{"thread":{"id":"7128","subject":"[PATCH 8/9] Use off_t in pack-objects/fast-import when we mean an offset","startedAt":"2007-03-07T01:44:34Z","lastAt":"2007-03-07T01:44:34Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"36518","messageId":"20070307014434.GI26482@spearce.org","threadId":"7128","inReplyTo":null,"subject":"[PATCH 8/9] Use off_t in pack-objects/fast-import when we mean an offset","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-07T01:44:34Z","receivedAt":"2007-03-07T01:44:34Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Always use an off_t value in pack-objects anytime we are dealing\nwith an offset to some data within a packfile.\n\nAlso fixed a minor uintmax_t that was incorrectly defined before.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-pack-objects.c |   52 ++++++++++++++++++++++++------------------------\n fast-import.c          |    4 +-\n 2 files changed, 28 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 8d5c3f1..f8ebad0 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -23,7 +23,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \\n\\\n struct object_entry {\n \tunsigned char sha1[20];\n \tunsigned long size;\t/* uncompressed size */\n-\tunsigned long offset;\t/* offset into the final pack file;\n+\toff_t offset;\t/* offset into the final pack file;\n \t\t\t\t * nonzero if already written.\n \t\t\t\t */\n \tunsigned int depth;\t/* delta depth */\n@@ -35,7 +35,7 @@ struct object_entry {\n #define in_pack_header_size delta_size\t/* only when reusing pack data */\n \tstruct object_entry *delta;\t/* delta base object */\n \tstruct packed_git *in_pack; \t/* already in pack */\n-\tunsigned int in_pack_offset;\n+\toff_t in_pack_offset;\n \tstruct object_entry *delta_child; /* deltified objects who bases me */\n \tstruct object_entry *delta_sibling; /* other deltified objects who\n \t\t\t\t\t     * uses the same base as me\n@@ -101,7 +101,7 @@ static int object_ix_hashsz;\n  * get the object sha1 from the main index.\n  */\n struct revindex_entry {\n-\tunsigned int offset;\n+\toff_t offset;\n \tunsigned int nr;\n };\n struct pack_revindex {\n@@ -183,7 +183,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)\n }\n \n static struct revindex_entry * find_packed_object(struct packed_git *p,\n-\t\t\t\t\t\t  unsigned int ofs)\n+\t\t\t\t\t\t  off_t ofs)\n {\n \tint num;\n \tint lo, hi;\n@@ -211,15 +211,14 @@ static struct revindex_entry * find_packed_object(struct packed_git *p,\n \tdie(\"internal error: pack revindex corrupt\");\n }\n \n-static unsigned long find_packed_object_size(struct packed_git *p,\n-\t\t\t\t\t     unsigned long ofs)\n+static off_t find_packed_object_size(struct packed_git *p, off_t ofs)\n {\n \tstruct revindex_entry *entry = find_packed_object(p, ofs);\n \treturn entry[1].offset - ofs;\n }\n \n static unsigned char *find_packed_object_name(struct packed_git *p,\n-\t\t\t\t\t      unsigned long ofs)\n+\t\t\t\t\t      off_t ofs)\n {\n \tstruct revindex_entry *entry = find_packed_object(p, ofs);\n \treturn (unsigned char *)(p->index_base + 256) + 24 * entry->nr + 4;\n@@ -276,8 +275,8 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha\n  */\n static int check_pack_inflate(struct packed_git *p,\n \t\tstruct pack_window **w_curs,\n-\t\tunsigned long offset,\n-\t\tunsigned long len,\n+\t\toff_t offset,\n+\t\toff_t len,\n \t\tunsigned long expect)\n {\n \tz_stream stream;\n@@ -303,8 +302,8 @@ static int check_pack_inflate(struct packed_git *p,\n static void copy_pack_data(struct sha1file *f,\n \t\tstruct packed_git *p,\n \t\tstruct pack_window **w_curs,\n-\t\tunsigned long offset,\n-\t\tunsigned long len)\n+\t\toff_t offset,\n+\t\toff_t len)\n {\n \tunsigned char *in;\n \tunsigned int avail;\n@@ -312,7 +311,7 @@ static void copy_pack_data(struct sha1file *f,\n \twhile (len) {\n \t\tin = use_pack(p, w_curs, offset, &avail);\n \t\tif (avail > len)\n-\t\t\tavail = len;\n+\t\t\tavail = (unsigned int)len;\n \t\tsha1write(f, in, avail);\n \t\toffset += avail;\n \t\tlen -= avail;\n@@ -369,14 +368,15 @@ static int revalidate_loose_object(struct object_entry *entry,\n \treturn check_loose_inflate(map, mapsize, size);\n }\n \n-static unsigned long write_object(struct sha1file *f,\n+static off_t write_object(struct sha1file *f,\n \t\t\t\t  struct object_entry *entry)\n {\n \tunsigned long size;\n \tenum object_type type;\n \tvoid *buf;\n \tunsigned char header[10];\n-\tunsigned hdrlen, datalen;\n+\tunsigned hdrlen;\n+\toff_t datalen;\n \tenum object_type obj_type;\n \tint to_reuse = 0;\n \n@@ -439,7 +439,7 @@ static unsigned long write_object(struct sha1file *f,\n \t\t\t * encoding of the relative offset for the delta\n \t\t\t * base from this object's position in the pack.\n \t\t\t */\n-\t\t\tunsigned long ofs = entry->offset - entry->delta->offset;\n+\t\t\toff_t ofs = entry->offset - entry->delta->offset;\n \t\t\tunsigned pos = sizeof(header) - 1;\n \t\t\theader[pos] = ofs & 127;\n \t\t\twhile (ofs >>= 7)\n@@ -460,7 +460,7 @@ static unsigned long write_object(struct sha1file *f,\n \telse {\n \t\tstruct packed_git *p = entry->in_pack;\n \t\tstruct pack_window *w_curs = NULL;\n-\t\tunsigned long offset;\n+\t\toff_t offset;\n \n \t\tif (entry->delta) {\n \t\t\tobj_type = (allow_ofs_delta && entry->delta->offset) ?\n@@ -470,7 +470,7 @@ static unsigned long write_object(struct sha1file *f,\n \t\thdrlen = encode_header(obj_type, entry->size, header);\n \t\tsha1write(f, header, hdrlen);\n \t\tif (obj_type == OBJ_OFS_DELTA) {\n-\t\t\tunsigned long ofs = entry->offset - entry->delta->offset;\n+\t\t\toff_t ofs = entry->offset - entry->delta->offset;\n \t\t\tunsigned pos = sizeof(header) - 1;\n \t\t\theader[pos] = ofs & 127;\n \t\t\twhile (ofs >>= 7)\n@@ -498,9 +498,9 @@ static unsigned long write_object(struct sha1file *f,\n \treturn hdrlen + datalen;\n }\n \n-static unsigned long write_one(struct sha1file *f,\n+static off_t write_one(struct sha1file *f,\n \t\t\t       struct object_entry *e,\n-\t\t\t       unsigned long offset)\n+\t\t\t       off_t offset)\n {\n \tif (e->offset || e->preferred_base)\n \t\t/* offset starts from header size and cannot be zero\n@@ -518,7 +518,7 @@ static void write_pack_file(void)\n {\n \tuint32_t i;\n \tstruct sha1file *f;\n-\tunsigned long offset;\n+\toff_t offset;\n \tstruct pack_header hdr;\n \tunsigned last_percent = 999;\n \tint do_progress = progress;\n@@ -671,13 +671,13 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud\n \tuint32_t idx = nr_objects;\n \tstruct object_entry *entry;\n \tstruct packed_git *p;\n-\tunsigned int found_offset = 0;\n+\toff_t found_offset = 0;\n \tstruct packed_git *found_pack = NULL;\n \tint ix, status = 0;\n \n \tif (!exclude) {\n \t\tfor (p = packed_git; p; p = p->next) {\n-\t\t\tunsigned long offset = find_pack_entry_one(sha1, p);\n+\t\t\toff_t offset = find_pack_entry_one(sha1, p);\n \t\t\tif (offset) {\n \t\t\t\tif (incremental)\n \t\t\t\t\treturn 0;\n@@ -978,17 +978,17 @@ static void check_object(struct object_entry *entry)\n \tif (entry->in_pack && !entry->preferred_base) {\n \t\tstruct packed_git *p = entry->in_pack;\n \t\tstruct pack_window *w_curs = NULL;\n-\t\tunsigned long left = p->pack_size - entry->in_pack_offset;\n \t\tunsigned long size, used;\n+\t\tunsigned int avail;\n \t\tunsigned char *buf;\n \t\tstruct object_entry *base_entry = NULL;\n \n-\t\tbuf = use_pack(p, &w_curs, entry->in_pack_offset, NULL);\n+\t\tbuf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);\n \n \t\t/* We want in_pack_type even if we do not reuse delta.\n \t\t * There is no point not reusing non-delta representations.\n \t\t */\n-\t\tused = unpack_object_header_gently(buf, left,\n+\t\tused = unpack_object_header_gently(buf, avail,\n \t\t\t\t\t\t   &entry->in_pack_type, &size);\n \n \t\t/* Check if it is delta, and the base is also an object\n@@ -997,7 +997,7 @@ static void check_object(struct object_entry *entry)\n \t\t */\n \t\tif (!no_reuse_delta) {\n \t\t\tunsigned char c, *base_name;\n-\t\t\tunsigned long ofs;\n+\t\t\toff_t ofs;\n \t\t\tunsigned long used_0;\n \t\t\t/* there is at least 20 bytes left in the pack */\n \t\t\tswitch (entry->in_pack_type) {\ndiff --git a/fast-import.c b/fast-import.c\nindex a418a17..fda5018 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -249,7 +249,7 @@ typedef enum {\n \n /* Configured limits on output */\n static unsigned long max_depth = 10;\n-static unsigned long max_packsize = (1LL << 32) - 1;\n+static off_t max_packsize = (1LL << 32) - 1;\n static int force_update;\n \n /* Stats and misc. counters */\n@@ -1527,7 +1527,7 @@ static void unload_one_branch(void)\n {\n \twhile (cur_active_branches\n \t\t&& cur_active_branches >= max_active_branches) {\n-\t\tunsigned long min_commit = ULONG_MAX;\n+\t\tuintmax_t min_commit = ULONG_MAX;\n \t\tstruct branch *e, *l = NULL, *p = NULL;\n \n \t\tfor (e = active_branches; e; e = e->active_next_branch) {\n-- \n1.5.0.3.863.gf0989\n"}]}