This is a minor change over pack index v2.  Since pack v4 already contains
the sorted SHA1 table, it is therefore ommitted from the index file.

Signed-off-by: Nicolas Pitre <n...@fluxnic.net>
---
 pack-write.c    |  6 +++++-
 packv4-create.c | 10 +++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/pack-write.c b/pack-write.c
index ca9e63b..631007e 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -87,6 +87,8 @@ const char *write_idx_file(const char *index_name, struct 
pack_idx_entry **objec
 
        /* if last object's offset is >= 2^31 we should use index V2 */
        index_version = need_large_offset(last_obj_offset, opts) ? 2 : 
opts->version;
+       if (index_version < opts->version)
+               index_version = opts->version;
 
        /* index versions 2 and above need a header */
        if (index_version >= 2) {
@@ -127,7 +129,9 @@ const char *write_idx_file(const char *index_name, struct 
pack_idx_entry **objec
                        uint32_t offset = htonl(obj->offset);
                        sha1write(f, &offset, 4);
                }
-               sha1write(f, obj->sha1, 20);
+               /* Pack v4 (using index v3) carries the SHA1 table already */
+               if (index_version < 3)
+                       sha1write(f, obj->sha1, 20);
                git_SHA1_Update(&ctx, obj->sha1, 20);
                if ((opts->flags & WRITE_IDX_STRICT) &&
                    (i && !hashcmp(list[-2]->sha1, obj->sha1)))
diff --git a/packv4-create.c b/packv4-create.c
index 63dc3d2..bb171c5 100644
--- a/packv4-create.c
+++ b/packv4-create.c
@@ -1007,8 +1007,10 @@ static void process_one_pack(char *src_pack, char 
*dst_pack)
        struct packed_git *p;
        struct sha1file *f;
        struct pack_idx_entry *objs, **p_objs;
+       struct pack_idx_option idx_opts;
        unsigned i, nr_objects;
        off_t written = 0;
+       unsigned char pack_sha1[20];
 
        p = open_pack(src_pack);
        if (!p)
@@ -1034,11 +1036,17 @@ static void process_one_pack(char *src_pack, char 
*dst_pack)
        for (i = 0; i < nr_objects; i++) {
                off_t obj_pos = written;
                struct pack_idx_entry *obj = p_objs[i];
+               crc32_begin(f);
                written += packv4_write_object(f, p, obj);
                obj->offset = obj_pos;
+               obj->crc32 = crc32_end(f);
        }
 
-       sha1close(f, NULL, CSUM_CLOSE | CSUM_FSYNC);
+       sha1close(f, pack_sha1, CSUM_CLOSE | CSUM_FSYNC);
+
+       reset_pack_idx_option(&idx_opts);
+       idx_opts.version = 3;
+       write_idx_file(dst_pack, p_objs, nr_objects, &idx_opts, pack_sha1);
 }
 
 static int git_pack_config(const char *k, const char *v, void *cb)
-- 
1.8.4.22.g54757b7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to