Code

Merge branch 'jc/index-pack-reject-dups'
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2011 23:13:42 +0000 (15:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2011 23:13:42 +0000 (15:13 -0800)
* jc/index-pack-reject-dups:
  receive-pack, fetch-pack: reject bogus pack that records objects twice

builtin/index-pack.c
object.c
pack-write.c
pack.h

index 0945adbb3bb188b612341c31c8986fabb491928d..98025da7670aaa9f79bfc7faa3a26c4079682fbb 100644 (file)
@@ -1122,8 +1122,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                if (!index_name)
                        die("--verify with no packfile name given");
                read_idx_option(&opts, index_name);
-               opts.flags |= WRITE_IDX_VERIFY;
+               opts.flags |= WRITE_IDX_VERIFY | WRITE_IDX_STRICT;
        }
+       if (strict)
+               opts.flags |= WRITE_IDX_STRICT;
 
        curr_pack = open_pack_file(pack_name);
        parse_pack_header();
index 31976b5d70b6310552b04ce79c7ea0b07bc536d7..d8d09f92aacd114e23378af2cfbeb78a3dd785a0 100644 (file)
--- a/object.c
+++ b/object.c
@@ -149,6 +149,8 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
                struct tree *tree = lookup_tree(sha1);
                if (tree) {
                        obj = &tree->object;
+                       if (!tree->buffer)
+                               tree->object.parsed = 0;
                        if (!tree->object.parsed) {
                                if (parse_tree_buffer(tree, buffer, size))
                                        return NULL;
index 9cd3bfbb4b3859cbbdc1b9375ea95f511fffc94e..f84adde3eb3bb6f6d3f4a871167d6a07ef73ebd8 100644 (file)
@@ -129,6 +129,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
                }
                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)))
+                       die("The same object %s appears twice in the pack",
+                           sha1_to_hex(obj->sha1));
        }
 
        if (index_version >= 2) {
diff --git a/pack.h b/pack.h
index 324a1d73c041053cf84e81681d11e52a5be6c62b..a8d9b9f2fcc41bf56007cd48dcfcb94a7e00d3ca 100644 (file)
--- a/pack.h
+++ b/pack.h
@@ -37,7 +37,8 @@ struct pack_header {
 struct pack_idx_option {
        unsigned flags;
        /* flag bits */
-#define WRITE_IDX_VERIFY 01
+#define WRITE_IDX_VERIFY 01 /* verify only, do not write the idx file */
+#define WRITE_IDX_STRICT 02
 
        uint32_t version;
        uint32_t off32_limit;