summaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-01-15 11:39:39 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-01-15 11:39:39 (GMT)
commit3e005baf8542a3116e51c4b0a27b72c7e14d949b (patch)
tree3c2d7e72a1fb2d0b4c09ac00c4a5fdaecd3dbf76 /fast-import.c
parent7bfe6e261378a30980886994dabc0e7e4c9ce3d8 (diff)
downloadgit-3e005baf8542a3116e51c4b0a27b72c7e14d949b.zip
git-3e005baf8542a3116e51c4b0a27b72c7e14d949b.tar.gz
git-3e005baf8542a3116e51c4b0a27b72c7e14d949b.tar.bz2
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>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/fast-import.c b/fast-import.c
index 3f747be..207acb3 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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);