On Sat, Apr 01, 2017 at 01:37:16AM -0400, Jeff King wrote:

> We use that strbuf for the prefix-comparison, too, but the way it is
> done is rather confusing. AFAICT, we could just be comparing against
> "packtmp + strlen(packdir) + 1". Though it would be simpler still to
> make "packtmp" just the basename, rather than the full path.

Something like the patch below, which would then free you up to replace
"buf" there with the diter->path.

diff --git a/builtin/repack.c b/builtin/repack.c
index 677bc7c81..06a14d687 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -48,7 +48,7 @@ static int repack_config(const char *var, const char *value, 
void *cb)
 static void remove_temporary_files(void)
 {
        struct strbuf buf = STRBUF_INIT;
-       size_t dirlen, prefixlen;
+       size_t dirlen;
        DIR *dir;
        struct dirent *e;
 
@@ -56,14 +56,11 @@ static void remove_temporary_files(void)
        if (!dir)
                return;
 
-       /* Point at the slash at the end of ".../objects/pack/" */
-       dirlen = strlen(packdir) + 1;
-       strbuf_addstr(&buf, packtmp);
-       /* Hold the length of  ".tmp-%d-pack-" */
-       prefixlen = buf.len - dirlen;
+       strbuf_addf(&buf, "%s/", packdir);
+       dirlen = buf.len;
 
        while ((e = readdir(dir))) {
-               if (strncmp(e->d_name, buf.buf + dirlen, prefixlen))
+               if (!starts_with(e->d_name, packtmp))
                        continue;
                strbuf_setlen(&buf, dirlen);
                strbuf_addstr(&buf, e->d_name);
@@ -216,7 +213,7 @@ int cmd_repack(int argc, const char **argv, const char 
*prefix)
                die(_(incremental_bitmap_conflict_error));
 
        packdir = mkpathdup("%s/pack", get_object_directory());
-       packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
+       packtmp = mkpathdup(".tmp-%d-pack", (int)getpid());
 
        sigchain_push_common(remove_pack_on_signal);
 
@@ -274,7 +271,7 @@ int cmd_repack(int argc, const char **argv, const char 
*prefix)
        if (delta_base_offset)
                argv_array_push(&cmd.args,  "--delta-base-offset");
 
-       argv_array_push(&cmd.args, packtmp);
+       argv_array_pushf(&cmd.args, "%s/%s", packdir, packtmp);
 
        cmd.git_cmd = 1;
        cmd.out = -1;
@@ -372,8 +369,8 @@ int cmd_repack(int argc, const char **argv, const char 
*prefix)
                        int exists = 0;
                        fname = mkpathdup("%s/pack-%s%s",
                                        packdir, item->string, exts[ext].name);
-                       fname_old = mkpathdup("%s-%s%s",
-                                       packtmp, item->string, exts[ext].name);
+                       fname_old = mkpathdup("%s/%s-%s%s",
+                                       packdir, packtmp, item->string, 
exts[ext].name);
                        if (!stat(fname_old, &statbuffer)) {
                                statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | 
S_IWOTH);
                                chmod(fname_old, statbuffer.st_mode);

Reply via email to