Thread (14 messages) flat view 14 messages, 4 authors, 2021-09-19

Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path

From: Johannes Sixt <hidden>
Date: 2021-09-19 09:00:14

Am 19.09.21 um 03:57 schrieb David Aguilar:
Use a strbuf to create the buffer used for the dir-diff tmpdir.
Strip trailing slashes "/" from the value read from TMPDIR to avoid
double-slashes in the calculated paths.

Add a unit test to ensure that double-slashes are not present.
I wonder why it is necessary to strip trailing slashes? You even go so
far as to add a test case, but then bury the change in a commit with a
title that is about a completely different topic.

So, which one of the two changes is the "while at it, do that, too" change?
quoted hunk ↗ jump to hunk
@@ -360,11 +359,17 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 
 	/* Setup temp directories */
 	tmp = getenv("TMPDIR");
-	xsnprintf(tmpdir, sizeof(tmpdir), "%s/git-difftool.XXXXXX", tmp ? tmp : "/tmp");
-	if (!mkdtemp(tmpdir))
-		return error("could not create '%s'", tmpdir);
-	strbuf_addf(&ldir, "%s/left/", tmpdir);
-	strbuf_addf(&rdir, "%s/right/", tmpdir);
+	strbuf_add_absolute_path(&tmpdir, tmp ? tmp : "/tmp");
+	/* Remove trailing slashes when $TMPDIR ends in '/'. */
+	while (tmpdir.len > 0 && tmpdir.buf[tmpdir.len - 1] == '/') {
This should most likely be is_dir_sep(tmpdir.buf[tmpdir.len - 1]).

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help