All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Robert Stanca <robert.stanca7@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators
Date: Sat, 1 Apr 2017 01:41:59 -0400	[thread overview]
Message-ID: <20170401054158.77ftxkba6kj2mdvp@sigill.intra.peff.net> (raw)
In-Reply-To: <20170401053716.yzxqxokuz3awqki4@sigill.intra.peff.net>

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	other threads:[~2017-04-01  5:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-01  0:24 [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators Robert Stanca
2017-04-01  5:37 ` Jeff King
2017-04-01  5:41   ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170401054158.77ftxkba6kj2mdvp@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=robert.stanca7@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.