Merge branch 'mb/fast-import-delete-root' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Sep 2014 05:09:47 +0000 (22:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Sep 2014 05:09:48 +0000 (22:09 -0700)
An attempt to remove the entire tree in the "git fast-import" input
stream caused it to misbehave.

* mb/fast-import-delete-root:
fast-import: fix segfault in store_tree()
t9300: test filedelete command

1  2 
fast-import.c
diff --combined fast-import.c
index a1479e980da154f9179d71aeeda7746770686baa,e380804831f7c386e41dee85d7229448b9be30e0..a40b4ea2d0447e5369efafa9943e1e46a28cc477
@@@ -946,12 -946,10 +946,12 @@@ static void unkeep_all_packs(void
  
  static void end_packfile(void)
  {
 -      struct packed_git *old_p = pack_data, *new_p;
 +      if (!pack_data)
 +              return;
  
        clear_delta_base_cache();
        if (object_count) {
 +              struct packed_git *new_p;
                unsigned char cur_pack_sha1[20];
                char *idx_name;
                int i;
                pack_id++;
        }
        else {
 -              close(old_p->pack_fd);
 -              unlink_or_warn(old_p->pack_name);
 +              close(pack_data->pack_fd);
 +              unlink_or_warn(pack_data->pack_name);
        }
 -      free(old_p);
 +      free(pack_data);
 +      pack_data = NULL;
  
        /* We can't carry a delta across packfiles. */
        strbuf_release(&last_blob.data);
@@@ -1422,7 -1419,7 +1422,7 @@@ static void mktree(struct tree_content 
  
  static void store_tree(struct tree_entry *root)
  {
-       struct tree_content *t = root->tree;
+       struct tree_content *t;
        unsigned int i, j, del;
        struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
        struct object_entry *le = NULL;
        if (!is_null_sha1(root->versions[1].sha1))
                return;
  
+       if (!root->tree)
+               load_tree(root);
+       t = root->tree;
        for (i = 0; i < t->entry_count; i++) {
                if (t->entries[i]->tree)
                        store_tree(t->entries[i]);
@@@ -1734,16 -1735,14 +1738,16 @@@ static void dump_tags(void
        static const char *msg = "fast-import";
        struct tag *t;
        struct ref_lock *lock;
 -      char ref_name[PATH_MAX];
 +      struct strbuf ref_name = STRBUF_INIT;
  
        for (t = first_tag; t; t = t->next_tag) {
 -              sprintf(ref_name, "tags/%s", t->name);
 -              lock = lock_ref_sha1(ref_name, NULL);
 +              strbuf_reset(&ref_name);
 +              strbuf_addf(&ref_name, "tags/%s", t->name);
 +              lock = lock_ref_sha1(ref_name.buf, NULL);
                if (!lock || write_ref_sha1(lock, t->sha1, msg) < 0)
 -                      failure |= error("Unable to update %s", ref_name);
 +                      failure |= error("Unable to update %s", ref_name.buf);
        }
 +      strbuf_release(&ref_name);
  }
  
  static void dump_marks_helper(FILE *f,