Code

Don't create a final empty packfile in fast-import.
authorShawn O. Pearce <spearce@spearce.org>
Mon, 15 Jan 2007 11:39:39 +0000 (06:39 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 15 Jan 2007 11:39:39 +0000 (06:39 -0500)
If the last packfile is going to be empty (has 0 objects) then it
shouldn't be kept after the import has terminated, as there is no
point to the packfile.  So rather than hashing it and making the
index file, just delete the packfile.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
fast-import.c

index 3f747be2878a1eb270b8a7b6958c64c76dee9b22..207acb3230f1c3a8b7843e82da282729ad4be37a 100644 (file)
@@ -713,17 +713,23 @@ static void end_packfile()
 {
        struct packed_git *old_p = pack_data, *new_p;
 
-       fixup_header_footer();
-       write_index(idx_name);
-
-       /* Register the packfile with core git's machinary. */
-       new_p = add_packed_git(idx_name, strlen(idx_name), 1);
-       if (!new_p)
-               die("core git rejected index %s", idx_name);
-       new_p->windows = old_p->windows;
-       new_p->pack_fd = old_p->pack_fd;
-       all_packs[pack_id++] = new_p;
-       install_packed_git(new_p);
+       if (object_count) {
+               fixup_header_footer();
+               write_index(idx_name);
+
+               /* Register the packfile with core git's machinary. */
+               new_p = add_packed_git(idx_name, strlen(idx_name), 1);
+               if (!new_p)
+                       die("core git rejected index %s", idx_name);
+               new_p->windows = old_p->windows;
+               new_p->pack_fd = old_p->pack_fd;
+               all_packs[pack_id++] = new_p;
+               install_packed_git(new_p);
+       }
+       else {
+               close(pack_fd);
+               unlink(old_p->pack_name);
+       }
        free(old_p);
        free(idx_name);