Skip to content

Commit 1934307

Browse files
peffgitster
authored andcommitted
repack: drop remove_temporary_files()
After we've successfully finished the repack, we call remove_temporary_files(), which looks for and removes any files matching ".tmp-$$-pack-*", where $$ is the pid of the current process. But this is pointless. If we make it this far in the process, we've already renamed these tempfiles into place, and there is nothing left to delete. Nor is there a point in trying to call it to clean up when we _aren't_ successful. It's not safe for using in a signal handler, and the previous commit already handed that job over to the tempfile API. It might seem like it would be useful to clean up stray .tmp files left by other invocations of git-repack. But it won't clean those files; it only matches ones with its pid, and leaves the rest. Fortunately, those are cleaned up naturally by successive calls to git-repack; we'll consider .tmp-*.pack the same as normal packfiles, so "repack -ad", etc, will roll up their contents and eventually delete them. The one case that could matter is if pack-objects generates an extension we don't know about, like ".tmp-pack-$$-$hash.some-new-ext". The current code will quietly delete such a file, while after this patch we'd leave it in place. In practice this doesn't happen, and would be indicative of a bug. Leaving the file as cruft is arguably a better behavior, as it means somebody is more likely to eventually notice and fix the bug. If we really wanted to be paranoid, we could scan for and warn about such files, but that seems like overkill. There's nothing to test with regard to the removal of this function. It was doing nothing, so the behavior should be the same. However, we can verify (and protect) our assumption that "repack -ad" will eventually remove stray files by adding a test for that. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9cf10d8 commit 1934307

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

builtin/repack.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,6 @@ static int repack_config(const char *var, const char *value, void *cb)
9191
return git_default_config(var, value, cb);
9292
}
9393

94-
/*
95-
* Remove temporary $GIT_OBJECT_DIRECTORY/pack/.tmp-$$-pack-* files.
96-
*/
97-
static void remove_temporary_files(void)
98-
{
99-
struct strbuf buf = STRBUF_INIT;
100-
size_t dirlen, prefixlen;
101-
DIR *dir;
102-
struct dirent *e;
103-
104-
dir = opendir(packdir);
105-
if (!dir)
106-
return;
107-
108-
/* Point at the slash at the end of ".../objects/pack/" */
109-
dirlen = strlen(packdir) + 1;
110-
strbuf_addstr(&buf, packtmp);
111-
/* Hold the length of ".tmp-%d-pack-" */
112-
prefixlen = buf.len - dirlen;
113-
114-
while ((e = readdir(dir))) {
115-
if (strncmp(e->d_name, buf.buf + dirlen, prefixlen))
116-
continue;
117-
strbuf_setlen(&buf, dirlen);
118-
strbuf_addstr(&buf, e->d_name);
119-
unlink(buf.buf);
120-
}
121-
closedir(dir);
122-
strbuf_release(&buf);
123-
}
124-
12594
/*
12695
* Adds all packs hex strings to either fname_nonkept_list or
12796
* fname_kept_list based on whether each pack has a corresponding
@@ -1106,7 +1075,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
11061075

11071076
if (run_update_server_info)
11081077
update_server_info(0);
1109-
remove_temporary_files();
11101078

11111079
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
11121080
unsigned flags = 0;

t/t7700-repack.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ test_expect_success 'clean up .tmp-* packs on error' '
440440
test_must_be_empty tmpfiles
441441
'
442442

443+
test_expect_success 'repack -ad cleans up old .tmp-* packs' '
444+
git rev-parse HEAD >input &&
445+
git pack-objects $objdir/pack/.tmp-1234 <input &&
446+
git repack -ad &&
447+
find $objdir/pack -name '.tmp-*' >tmpfiles &&
448+
test_must_be_empty tmpfiles
449+
'
450+
443451
test_expect_success 'setup for update-server-info' '
444452
git init update-server-info &&
445453
test_commit -C update-server-info message

0 commit comments

Comments
 (0)