@matheusbsbs / matheus-bagliano / commits / 3e005baf85
Fork 0

Don't create a final empty packfile in fast-import.

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>

Shawn O. Pearce committed Jan 15, 2007 at 06:39 UTC 3e005baf8542a3116e51c4b0a27b72c7e14d949b
1 file changed +17 -11
fast-import.c
+17 -11
@@ -713,17 +713,23 @@ static void end_packfile()
713 {
714 struct packed_git *old_p = pack_data, *new_p;
715
716 - fixup_header_footer();
717 - write_index(idx_name);
718 -
719 - /* Register the packfile with core git's machinary. */
720 - new_p = add_packed_git(idx_name, strlen(idx_name), 1);
721 - if (!new_p)
722 - die("core git rejected index %s", idx_name);
723 - new_p->windows = old_p->windows;
724 - new_p->pack_fd = old_p->pack_fd;
725 - all_packs[pack_id++] = new_p;
726 - install_packed_git(new_p);
716 + if (object_count) {
717 + fixup_header_footer();
718 + write_index(idx_name);
719 +
720 + /* Register the packfile with core git's machinary. */
721 + new_p = add_packed_git(idx_name, strlen(idx_name), 1);
722 + if (!new_p)
723 + die("core git rejected index %s", idx_name);
724 + new_p->windows = old_p->windows;
725 + new_p->pack_fd = old_p->pack_fd;
726 + all_packs[pack_id++] = new_p;
727 + install_packed_git(new_p);
728 + }
729 + else {
730 + close(pack_fd);
731 + unlink(old_p->pack_name);
732 + }
733 free(old_p);
734 free(idx_name);
735