git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests
@ 2021-09-19  1:57 David Aguilar
  2021-09-19  1:57 ` [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments David Aguilar
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: David Aguilar @ 2021-09-19  1:57 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

The "dirlinks" and "growing" repositories should not outlive the
tests that use them.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 t/t7800-difftool.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a173f564bc..a923f193da 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -414,6 +414,7 @@ test_expect_success 'setup change in subdirectory' '
 test_expect_success 'difftool -d with growing paths' '
 	a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 	git init growing &&
+	test_when_finished rm -rf growing &&
 	(
 		cd growing &&
 		echo "test -f \"\$2/b\"" | write_script .git/test-for-b.sh &&
@@ -646,6 +647,7 @@ test_expect_success 'difftool properly honors gitlink and core.worktree' '
 test_expect_success SYMLINKS 'difftool --dir-diff symlinked directories' '
 	test_when_finished git reset --hard &&
 	git init dirlinks &&
+	test_when_finished rm -rf dirlinks &&
 	(
 		cd dirlinks &&
 		git config diff.tool checktrees &&
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments
  2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
@ 2021-09-19  1:57 ` David Aguilar
  2021-09-19  1:57 ` [PATCH 3/4] difftool: use a strbuf to create the tmpdir path David Aguilar
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: David Aguilar @ 2021-09-19  1:57 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 builtin/difftool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index bb9fe7245a..4d2e772031 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -548,7 +548,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	}
 
 	/*
-	 * Symbolic links require special treatment.The standard "git diff"
+	 * Symbolic links require special treatment. The standard "git diff"
 	 * shows only the link itself, not the contents of the link target.
 	 * This loop replicates that behavior.
 	 */
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
  2021-09-19  1:57 ` [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments David Aguilar
@ 2021-09-19  1:57 ` David Aguilar
  2021-09-19  2:17   ` Jeff King
  2021-09-19  9:00   ` [PATCH " Johannes Sixt
  2021-09-19  1:57 ` [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode David Aguilar
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: David Aguilar @ 2021-09-19  1:57 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

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.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 builtin/difftool.c  | 32 +++++++++++++++++++-------------
 t/t7800-difftool.sh |  7 +++++++
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4d2e772031..2014a2bb9e 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -252,11 +252,10 @@ static void changed_files(struct hashmap *result, const char *index_path,
 	strbuf_release(&buf);
 }
 
-static NORETURN void exit_cleanup(const char *tmpdir, int exit_code)
+static NORETURN void exit_cleanup(struct strbuf *buf, int exit_code)
 {
-	struct strbuf buf = STRBUF_INIT;
-	strbuf_addstr(&buf, tmpdir);
-	remove_dir_recursively(&buf, 0);
+	remove_dir_recursively(buf, 0);
+	strbuf_release(buf);
 	if (exit_code)
 		warning(_("failed: %d"), exit_code);
 	exit(exit_code);
@@ -333,11 +332,11 @@ static int checkout_path(unsigned mode, struct object_id *oid,
 static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 			struct child_process *child)
 {
-	char tmpdir[PATH_MAX];
 	struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT;
 	struct strbuf rpath = STRBUF_INIT, buf = STRBUF_INIT;
 	struct strbuf ldir = STRBUF_INIT, rdir = STRBUF_INIT;
 	struct strbuf wtdir = STRBUF_INIT;
+	struct strbuf tmpdir = STRBUF_INIT;
 	char *lbase_dir, *rbase_dir;
 	size_t ldir_len, rdir_len, wtdir_len;
 	const char *workdir, *tmp;
@@ -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] == '/') {
+		strbuf_setlen(&tmpdir, tmpdir.len - 1);
+	}
+	strbuf_addstr(&tmpdir, "/git-difftool.XXXXXX");
+
+	if (!mkdtemp(tmpdir.buf))
+		return error("could not create '%s'", tmpdir.buf);
+	strbuf_addf(&ldir, "%s/left/", tmpdir.buf);
+	strbuf_addf(&rdir, "%s/right/", tmpdir.buf);
 	strbuf_addstr(&wtdir, workdir);
 	if (!wtdir.len || !is_dir_sep(wtdir.buf[wtdir.len - 1]))
 		strbuf_addch(&wtdir, '/');
@@ -612,7 +617,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (!indices_loaded) {
 			struct lock_file lock = LOCK_INIT;
 			strbuf_reset(&buf);
-			strbuf_addf(&buf, "%s/wtindex", tmpdir);
+			strbuf_addf(&buf, "%s/wtindex", tmpdir.buf);
 			if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||
 			    write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
 				ret = error("could not write %s", buf.buf);
@@ -642,11 +647,11 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	}
 
 	if (err) {
-		warning(_("temporary files exist in '%s'."), tmpdir);
+		warning(_("temporary files exist in '%s'."), tmpdir.buf);
 		warning(_("you may want to cleanup or recover these."));
 		exit(1);
 	} else
-		exit_cleanup(tmpdir, rc);
+		exit_cleanup(&tmpdir, rc);
 
 finish:
 	if (fp)
@@ -658,6 +663,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	strbuf_release(&rdir);
 	strbuf_release(&wtdir);
 	strbuf_release(&buf);
+	strbuf_release(&tmpdir);
 
 	return ret;
 }
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a923f193da..3863afcaac 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -454,6 +454,13 @@ run_dir_diff_test 'difftool --dir-diff' '
 	grep "^file$" output
 '
 
+run_dir_diff_test 'difftool --dir-diff avoids double-slashes in TMPDIR' '
+	TMPDIR="${TMPDIR:-/tmp}////" \
+		git difftool --dir-diff $symlinks --extcmd echo branch >output &&
+	grep -v // output >actual &&
+	test_line_count = 1 actual
+'
+
 run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
 	git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
 	grep "^sub$" output &&
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode
  2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
  2021-09-19  1:57 ` [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments David Aguilar
  2021-09-19  1:57 ` [PATCH 3/4] difftool: use a strbuf to create the tmpdir path David Aguilar
@ 2021-09-19  1:57 ` David Aguilar
  2021-09-19  2:02   ` [PATCH v2 " David Aguilar
  2021-09-19 13:25 ` [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests Ævar Arnfjörð Bjarmason
  2021-09-20 18:28 ` Junio C Hamano
  4 siblings, 1 reply; 16+ messages in thread
From: David Aguilar @ 2021-09-19  1:57 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

The difftool dir-diff mode handles symlinks by replacing them with their
readlink(2) values. This allows diff tools to see changes to symlinks
as if they were regular text diffs with the old and new path values.
This is analogous to what "git diff" displays when symlinks change.

The temporary diff directories that are created initially contain
symlinks because they get checked-out using a temporary index that
retains the original symlinks as checked-in to the repository.

A bug was introduced when difftool was rewritten in C that made
difftool write the readlink(2) contents into the pointed-to file rather
than the symlink itself. The write was going through the symlink and
writing to its target rather than writing to the symlink path itself.

Replace symlinks with raw text files by unlinking the symlink path
before writing the readlink(2) content into them.

When 18ec800512eb0634a0bf5e86b36ed156fbee73f3 added handling for
modified symlinks this bug got recorded in the test suite. The tests
included the pointed-to symlink target paths. These paths were being
reported because difftool was erroneously writing to them, but they
should have never been reported nor written.

Correct the modified-symlinks test cases by removing the target files
from the expected output.

Add a test to ensure that symlinks are written with the readlink(2)
values and that the target files contain their original content.

Reported-by: Alan Blotz <work@blotz.org>
Helped-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
 builtin/difftool.c  |  2 ++
 t/t7800-difftool.sh | 70 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2014a2bb9e..4cf454eca4 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -562,11 +562,13 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (*entry->left) {
 			add_path(&ldir, ldir_len, entry->path);
 			ensure_leading_directories(ldir.buf);
+			unlink(ldir.buf);
 			write_file(ldir.buf, "%s", entry->left);
 		}
 		if (*entry->right) {
 			add_path(&rdir, rdir_len, entry->path);
 			ensure_leading_directories(rdir.buf);
+			unlink(rdir.buf);
 			write_file(rdir.buf, "%s", entry->right);
 		}
 	}
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 3863afcaac..97077f34a5 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -683,7 +683,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	rm c &&
 	ln -s d c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 		c
@@ -719,7 +718,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	# Deleted symlinks
 	rm -f c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 	EOF
@@ -732,6 +730,74 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	test_cmp expect actual
 '
 
+test_expect_success SYMLINKS 'difftool --dir-diff writes symlinks as raw text' '
+	# Start out on a branch called "init".
+	git init -b branch-init symlink-files &&
+	test_when_finished rm -rf symlink-files &&
+	(
+		cd ./symlink-files &&
+
+		# This test ensures that symlinks are written as raw text.
+		# The "cat" tool cats the file only if it is not a symlink.
+		git config difftool.cat-left-link.cmd "cat \$LOCAL/link" &&
+		git config difftool.cat-left-a.cmd "cat \$LOCAL/file-a" &&
+		git config difftool.cat-right-link.cmd "cat \$REMOTE/link" &&
+		git config difftool.cat-right-b.cmd "cat \$REMOTE/file-b" &&
+
+		# Record the empty start so that we can come back here later and
+		# not have to consider the any cases where difftool will create
+		# symlinks back into the worktree.
+		test_tick &&
+		git commit --allow-empty -m init &&
+
+		# Create a file called "file-a" with a symlink pointing to it.
+		git switch -c branch-a &&
+		echo a >file-a &&
+		ln -s file-a link &&
+		git add file-a link &&
+		test_tick &&
+		git commit -m link-to-file-a &&
+
+		# Create a file called "file-b" and point the symlink to it.
+		git switch -c branch-b &&
+		echo b >file-b &&
+		rm link &&
+		ln -s file-b link &&
+		git add file-b link &&
+		git rm file-a &&
+		test_tick &&
+		git commit -m link-to-file-b &&
+
+		# Checkout the initial branch so that the --symlinks behavior is
+		# not activated. The two directories should be completely
+		# independent with no syminks pointing back here.
+		git switch branch-init &&
+
+		# The left link must be "file-a" and "file-a" must contain "a".
+		printf "%s\n" file-a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-a \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		# The right link must be "file-b" and "file-b" must contain "b".
+		printf "%s\n" file-b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-b \
+			branch-a branch-b >actual &&
+		test_cmp expect actual
+	)
+'
+
+
 test_expect_success 'add -N and difftool -d' '
 	test_when_finished git reset --hard &&
 
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 4/4] difftool: fix symlink-file writing in dir-diff mode
  2021-09-19  1:57 ` [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode David Aguilar
@ 2021-09-19  2:02   ` David Aguilar
  2021-09-19  2:21     ` [PATCH v3 " David Aguilar
  0 siblings, 1 reply; 16+ messages in thread
From: David Aguilar @ 2021-09-19  2:02 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

The difftool dir-diff mode handles symlinks by replacing them with their
readlink(2) values. This allows diff tools to see changes to symlinks
as if they were regular text diffs with the old and new path values.
This is analogous to what "git diff" displays when symlinks change.

The temporary diff directories that are created initially contain
symlinks because they get checked-out using a temporary index that
retains the original symlinks as checked-in to the repository.

A bug was introduced when difftool was rewritten in C that made
difftool write the readlink(2) contents into the pointed-to file rather
than the symlink itself. The write was going through the symlink and
writing to its target rather than writing to the symlink path itself.

Replace symlinks with raw text files by unlinking the symlink path
before writing the readlink(2) content into them.

When 18ec800512eb0634a0bf5e86b36ed156fbee73f3 added handling for
modified symlinks this bug got recorded in the test suite. The tests
included the pointed-to symlink target paths. These paths were being
reported because difftool was erroneously writing to them, but they
should have never been reported nor written.

Correct the modified-symlinks test cases by removing the target files
from the expected output.

Add a test to ensure that symlinks are written with the readlink(2)
values and that the target files contain their original content.

Reported-by: Alan Blotz <work@blotz.org>
Helped-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---

Please drop the previous patch.
v2 removes a spurious extra newline that was added after the new test.
No changes otherwise.

 builtin/difftool.c  |  2 ++
 t/t7800-difftool.sh | 69 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2014a2bb9e..4cf454eca4 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -562,11 +562,13 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (*entry->left) {
 			add_path(&ldir, ldir_len, entry->path);
 			ensure_leading_directories(ldir.buf);
+			unlink(ldir.buf);
 			write_file(ldir.buf, "%s", entry->left);
 		}
 		if (*entry->right) {
 			add_path(&rdir, rdir_len, entry->path);
 			ensure_leading_directories(rdir.buf);
+			unlink(rdir.buf);
 			write_file(rdir.buf, "%s", entry->right);
 		}
 	}
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 3863afcaac..d9f6d15183 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -683,7 +683,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	rm c &&
 	ln -s d c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 		c
@@ -719,7 +718,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	# Deleted symlinks
 	rm -f c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 	EOF
@@ -732,6 +730,73 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	test_cmp expect actual
 '
 
+test_expect_success SYMLINKS 'difftool --dir-diff writes symlinks as raw text' '
+	# Start out on a branch called "init".
+	git init -b branch-init symlink-files &&
+	test_when_finished rm -rf symlink-files &&
+	(
+		cd ./symlink-files &&
+
+		# This test ensures that symlinks are written as raw text.
+		# The "cat" tool cats the file only if it is not a symlink.
+		git config difftool.cat-left-link.cmd "cat \$LOCAL/link" &&
+		git config difftool.cat-left-a.cmd "cat \$LOCAL/file-a" &&
+		git config difftool.cat-right-link.cmd "cat \$REMOTE/link" &&
+		git config difftool.cat-right-b.cmd "cat \$REMOTE/file-b" &&
+
+		# Record the empty start so that we can come back here later and
+		# not have to consider the any cases where difftool will create
+		# symlinks back into the worktree.
+		test_tick &&
+		git commit --allow-empty -m init &&
+
+		# Create a file called "file-a" with a symlink pointing to it.
+		git switch -c branch-a &&
+		echo a >file-a &&
+		ln -s file-a link &&
+		git add file-a link &&
+		test_tick &&
+		git commit -m link-to-file-a &&
+
+		# Create a file called "file-b" and point the symlink to it.
+		git switch -c branch-b &&
+		echo b >file-b &&
+		rm link &&
+		ln -s file-b link &&
+		git add file-b link &&
+		git rm file-a &&
+		test_tick &&
+		git commit -m link-to-file-b &&
+
+		# Checkout the initial branch so that the --symlinks behavior is
+		# not activated. The two directories should be completely
+		# independent with no syminks pointing back here.
+		git switch branch-init &&
+
+		# The left link must be "file-a" and "file-a" must contain "a".
+		printf "%s\n" file-a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-a \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		# The right link must be "file-b" and "file-b" must contain "b".
+		printf "%s\n" file-b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-b \
+			branch-a branch-b >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_expect_success 'add -N and difftool -d' '
 	test_when_finished git reset --hard &&
 
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  1:57 ` [PATCH 3/4] difftool: use a strbuf to create the tmpdir path David Aguilar
@ 2021-09-19  2:17   ` Jeff King
  2021-09-19  2:33     ` [PATCH v2 " David Aguilar
  2021-09-19  9:00   ` [PATCH " Johannes Sixt
  1 sibling, 1 reply; 16+ messages in thread
From: Jeff King @ 2021-09-19  2:17 UTC (permalink / raw)
  To: David Aguilar
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

On Sat, Sep 18, 2021 at 06:57:28PM -0700, David Aguilar wrote:

> +	/* Remove trailing slashes when $TMPDIR ends in '/'. */
> +	while (tmpdir.len > 0 && tmpdir.buf[tmpdir.len - 1] == '/') {
> +		strbuf_setlen(&tmpdir, tmpdir.len - 1);
> +	}
> +	strbuf_addstr(&tmpdir, "/git-difftool.XXXXXX");

It sounds like this should remove any directory separator (so on
Windows, it should also drop backslashes). You can use is_dir_sep() for
that, but better still, you can then do:

  strbuf_trim_trailing_dir_sep(&tmpdir);

-Peff

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 4/4] difftool: fix symlink-file writing in dir-diff mode
  2021-09-19  2:02   ` [PATCH v2 " David Aguilar
@ 2021-09-19  2:21     ` David Aguilar
  0 siblings, 0 replies; 16+ messages in thread
From: David Aguilar @ 2021-09-19  2:21 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

The difftool dir-diff mode handles symlinks by replacing them with their
readlink(2) values. This allows diff tools to see changes to symlinks
as if they were regular text diffs with the old and new path values.
This is analogous to what "git diff" displays when symlinks change.

The temporary diff directories that are created initially contain
symlinks because they get checked-out using a temporary index that
retains the original symlinks as checked-in to the repository.

A bug was introduced when difftool was rewritten in C that made
difftool write the readlink(2) contents into the pointed-to file rather
than the symlink itself. The write was going through the symlink and
writing to its target rather than writing to the symlink path itself.

Replace symlinks with raw text files by unlinking the symlink path
before writing the readlink(2) content into them.

When 18ec800512eb0634a0bf5e86b36ed156fbee73f3 added handling for
modified symlinks this bug got recorded in the test suite. The tests
included the pointed-to symlink target paths. These paths were being
reported because difftool was erroneously writing to them, but they
should have never been reported nor written.

Correct the modified-symlinks test cases by removing the target files
from the expected output.

Add a test to ensure that symlinks are written with the readlink(2)
values and that the target files contain their original content.

Reported-by: Alan Blotz <work@blotz.org>
Helped-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Sorry for the patch noise. This supersedes v2 as well.

Changes since v1:
- Removed a spurious newline after the new test.
- Updated test comments to fix a "branch-init" typo.
- Updated test comments to clarify the purpose of the "cat" tools.
- No functional changes.

 builtin/difftool.c  |  2 ++
 t/t7800-difftool.sh | 69 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 2014a2bb9e..4cf454eca4 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -562,11 +562,13 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (*entry->left) {
 			add_path(&ldir, ldir_len, entry->path);
 			ensure_leading_directories(ldir.buf);
+			unlink(ldir.buf);
 			write_file(ldir.buf, "%s", entry->left);
 		}
 		if (*entry->right) {
 			add_path(&rdir, rdir_len, entry->path);
 			ensure_leading_directories(rdir.buf);
+			unlink(rdir.buf);
 			write_file(rdir.buf, "%s", entry->right);
 		}
 	}
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 3863afcaac..f58114b900 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -683,7 +683,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	rm c &&
 	ln -s d c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 		c
@@ -719,7 +718,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	# Deleted symlinks
 	rm -f c &&
 	cat >expect <<-EOF &&
-		b
 		c
 
 	EOF
@@ -732,6 +730,73 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
 	test_cmp expect actual
 '
 
+test_expect_success SYMLINKS 'difftool --dir-diff writes symlinks as raw text' '
+	# Start out on a branch called "branch-init".
+	git init -b branch-init symlink-files &&
+	test_when_finished rm -rf symlink-files &&
+	(
+		cd ./symlink-files &&
+
+		# This test ensures that symlinks are written as raw text.
+		# The "cat" tools output link and file contents.
+		git config difftool.cat-left-link.cmd "cat \"\$LOCAL/link\"" &&
+		git config difftool.cat-left-a.cmd "cat \"\$LOCAL/file-a\"" &&
+		git config difftool.cat-right-link.cmd "cat \"\$REMOTE/link\"" &&
+		git config difftool.cat-right-b.cmd "cat \"\$REMOTE/file-b\"" &&
+
+		# Record the empty initial state so that we can come back here
+		# later and not have to consider the any cases where difftool
+		# will create symlinks back into the worktree.
+		test_tick &&
+		git commit --allow-empty -m init &&
+
+		# Create a file called "file-a" with a symlink pointing to it.
+		git switch -c branch-a &&
+		echo a >file-a &&
+		ln -s file-a link &&
+		git add file-a link &&
+		test_tick &&
+		git commit -m link-to-file-a &&
+
+		# Create a file called "file-b" and point the symlink to it.
+		git switch -c branch-b &&
+		echo b >file-b &&
+		rm link &&
+		ln -s file-b link &&
+		git add file-b link &&
+		git rm file-a &&
+		test_tick &&
+		git commit -m link-to-file-b &&
+
+		# Checkout the initial branch so that the --symlinks behavior is
+		# not activated. The two directories should be completely
+		# independent with no syminks pointing back here.
+		git switch branch-init &&
+
+		# The left link must be "file-a" and "file-a" must contain "a".
+		printf "%s\n" file-a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo a >expect &&
+		git difftool --symlinks --dir-diff --tool cat-left-a \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		# The right link must be "file-b" and "file-b" must contain "b".
+		printf "%s\n" file-b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-link \
+			branch-a branch-b >actual &&
+		test_cmp expect actual &&
+
+		echo b >expect &&
+		git difftool --symlinks --dir-diff --tool cat-right-b \
+			branch-a branch-b >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_expect_success 'add -N and difftool -d' '
 	test_when_finished git reset --hard &&
 
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  2:17   ` Jeff King
@ 2021-09-19  2:33     ` David Aguilar
  2021-09-20 18:35       ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: David Aguilar @ 2021-09-19  2:33 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh, Jeff King

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.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
Changes since v1:
- Updated to use strbuf_trim_trailing_dir_sep().

Thanks Peff!

 builtin/difftool.c  | 28 +++++++++++++++-------------
 t/t7800-difftool.sh |  7 +++++++
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/builtin/difftool.c b/builtin/difftool.c
index 4d2e772031..0554ae5fb5 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -252,11 +252,10 @@ static void changed_files(struct hashmap *result, const char *index_path,
 	strbuf_release(&buf);
 }
 
-static NORETURN void exit_cleanup(const char *tmpdir, int exit_code)
+static NORETURN void exit_cleanup(struct strbuf *buf, int exit_code)
 {
-	struct strbuf buf = STRBUF_INIT;
-	strbuf_addstr(&buf, tmpdir);
-	remove_dir_recursively(&buf, 0);
+	remove_dir_recursively(buf, 0);
+	strbuf_release(buf);
 	if (exit_code)
 		warning(_("failed: %d"), exit_code);
 	exit(exit_code);
@@ -333,11 +332,11 @@ static int checkout_path(unsigned mode, struct object_id *oid,
 static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 			struct child_process *child)
 {
-	char tmpdir[PATH_MAX];
 	struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT;
 	struct strbuf rpath = STRBUF_INIT, buf = STRBUF_INIT;
 	struct strbuf ldir = STRBUF_INIT, rdir = STRBUF_INIT;
 	struct strbuf wtdir = STRBUF_INIT;
+	struct strbuf tmpdir = STRBUF_INIT;
 	char *lbase_dir, *rbase_dir;
 	size_t ldir_len, rdir_len, wtdir_len;
 	const char *workdir, *tmp;
@@ -360,11 +359,13 @@ 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");
+	strbuf_trim_trailing_dir_sep(&tmpdir);
+	strbuf_addstr(&tmpdir, "/git-difftool.XXXXXX");
+	if (!mkdtemp(tmpdir.buf))
+		return error("could not create '%s'", tmpdir.buf);
+	strbuf_addf(&ldir, "%s/left/", tmpdir.buf);
+	strbuf_addf(&rdir, "%s/right/", tmpdir.buf);
 	strbuf_addstr(&wtdir, workdir);
 	if (!wtdir.len || !is_dir_sep(wtdir.buf[wtdir.len - 1]))
 		strbuf_addch(&wtdir, '/');
@@ -612,7 +613,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 		if (!indices_loaded) {
 			struct lock_file lock = LOCK_INIT;
 			strbuf_reset(&buf);
-			strbuf_addf(&buf, "%s/wtindex", tmpdir);
+			strbuf_addf(&buf, "%s/wtindex", tmpdir.buf);
 			if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||
 			    write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
 				ret = error("could not write %s", buf.buf);
@@ -642,11 +643,11 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	}
 
 	if (err) {
-		warning(_("temporary files exist in '%s'."), tmpdir);
+		warning(_("temporary files exist in '%s'."), tmpdir.buf);
 		warning(_("you may want to cleanup or recover these."));
 		exit(1);
 	} else
-		exit_cleanup(tmpdir, rc);
+		exit_cleanup(&tmpdir, rc);
 
 finish:
 	if (fp)
@@ -658,6 +659,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
 	strbuf_release(&rdir);
 	strbuf_release(&wtdir);
 	strbuf_release(&buf);
+	strbuf_release(&tmpdir);
 
 	return ret;
 }
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a923f193da..3863afcaac 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -454,6 +454,13 @@ run_dir_diff_test 'difftool --dir-diff' '
 	grep "^file$" output
 '
 
+run_dir_diff_test 'difftool --dir-diff avoids double-slashes in TMPDIR' '
+	TMPDIR="${TMPDIR:-/tmp}////" \
+		git difftool --dir-diff $symlinks --extcmd echo branch >output &&
+	grep -v // output >actual &&
+	test_line_count = 1 actual
+'
+
 run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
 	git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
 	grep "^sub$" output &&
-- 
2.33.0.721.ga252b5a140


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  1:57 ` [PATCH 3/4] difftool: use a strbuf to create the tmpdir path David Aguilar
  2021-09-19  2:17   ` Jeff King
@ 2021-09-19  9:00   ` Johannes Sixt
  2021-09-19 18:13     ` David Aguilar
  1 sibling, 1 reply; 16+ messages in thread
From: Johannes Sixt @ 2021-09-19  9:00 UTC (permalink / raw)
  To: David Aguilar, Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

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?

> @@ -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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests
  2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
                   ` (2 preceding siblings ...)
  2021-09-19  1:57 ` [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode David Aguilar
@ 2021-09-19 13:25 ` Ævar Arnfjörð Bjarmason
  2021-09-20 18:28 ` Junio C Hamano
  4 siblings, 0 replies; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-09-19 13:25 UTC (permalink / raw)
  To: David Aguilar
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh


On Sat, Sep 18 2021, David Aguilar wrote:

> The "dirlinks" and "growing" repositories should not outlive the
> tests that use them.

Why not? The pattern of not bothering to clean up the work scratch are
is fine as long as it doesn't leave crap around for other tests. See the
referenec to "repo" at[1].

I.e. is this needed for later tests that change in this series, or just
cleanup in case a future test ever cares that there's an untracked
"dirlinks" and "growing" directory at the top-level?

1. https://lore.kernel.org/git/87y27veeyj.fsf@evledraar.gmail.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  9:00   ` [PATCH " Johannes Sixt
@ 2021-09-19 18:13     ` David Aguilar
  2021-09-19 18:46       ` Johannes Sixt
  0 siblings, 1 reply; 16+ messages in thread
From: David Aguilar @ 2021-09-19 18:13 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh,
	Ævar Arnfjörð Bjarmason

On Sun, Sep 19, 2021 at 2:00 AM Johannes Sixt <j6t@kdbg.org> wrote:
>
> 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?

A better title might be:

    difftool: use a strbuf to generate a tmpdir path without double-slashes

The double-slashes are the point. This patch is a minor cleanup that I
found on the path towards fixing the data loss bug in patch 4.

Thanks for the heads-up about the confusion ~ I'll reword in the next
submission to make this point clearer.

Ævar (cc'd) also asked why we have a patch that deletes the temporary
repositories used by the tests. It sounds like it's best to leave
those in place so the next submission will also drop that patch and
will adjust patch 4/4 (now 3/3) so that it also does not remove the
temporary repo used by its new test.


> > @@ -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]).

Indeed. Peff also suggested strbuf_strip_trailing_dir_sep(&tmpdir)
which is what we have in patch v2. That uses is_dir_sep().

This commit will be reworded, patch 1/4 "t7800-difftool: cleanup
temporary repositories" will be dropped, and the final patch will be
adjusted to not cleanup its temporary test repository.

I'll resend all 3 patches later with these suggestions as "v4".

cheers,
-- 
David

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19 18:13     ` David Aguilar
@ 2021-09-19 18:46       ` Johannes Sixt
  2021-09-19 19:28         ` David Aguilar
  0 siblings, 1 reply; 16+ messages in thread
From: Johannes Sixt @ 2021-09-19 18:46 UTC (permalink / raw)
  To: David Aguilar
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh,
	Ævar Arnfjörð Bjarmason

Am 19.09.21 um 20:13 schrieb David Aguilar:
> A better title might be:
> 
>     difftool: use a strbuf to generate a tmpdir path without double-slashes
> 
> The double-slashes are the point. This patch is a minor cleanup that I
> found on the path towards fixing the data loss bug in patch 4.
> 
> Thanks for the heads-up about the confusion ~ I'll reword in the next
> submission to make this point clearer.

Thanks. My primary concern with the patch was actually that it looks
like mere code churn that introduces an error by not using is_dir_sep().
This is now settled.

But still, without a justification why the slashes should be cleaned up,
the patch looks like code churn. You can ignore me if it is obvious for
others why we need the patch.

-- Hannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19 18:46       ` Johannes Sixt
@ 2021-09-19 19:28         ` David Aguilar
  2021-09-19 19:50           ` Johannes Sixt
  0 siblings, 1 reply; 16+ messages in thread
From: David Aguilar @ 2021-09-19 19:28 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh,
	Ævar Arnfjörð Bjarmason

On Sun, Sep 19, 2021 at 11:46 AM Johannes Sixt <j6t@kdbg.org> wrote:
>
> Am 19.09.21 um 20:13 schrieb David Aguilar:
> > A better title might be:
> >
> >     difftool: use a strbuf to generate a tmpdir path without double-slashes
> >
> > The double-slashes are the point. This patch is a minor cleanup that I
> > found on the path towards fixing the data loss bug in patch 4.
> >
> > Thanks for the heads-up about the confusion ~ I'll reword in the next
> > submission to make this point clearer.
>
> Thanks. My primary concern with the patch was actually that it looks
> like mere code churn that introduces an error by not using is_dir_sep().
> This is now settled.
>
> But still, without a justification why the slashes should be cleaned up,
> the patch looks like code churn. You can ignore me if it is obvious for
> others why we need the patch.

Nah, that's a good point. Thanks for clarifying. I'll hold off on
resending until we've reached consensus on this patch.

The final bugfix patch is the most important one in the series so
perhaps I should reorder the series so that the bugfix comes first,
and these cosmetic improvements and typo fixes are the later ones in
the series? That'll make it so that the bugfix is easier to backport
and not entangled with these prep fixups.

I see double-slashes when using the dir-diff feature and they just
look wrong to me, but "striving for perfection" is a mere subjective
justification.

The double-slashes fixup is cosmetic from a technical perspective, but
since the paths are exposed to the diff tools it's a cosmetic blemish
that users will see front and center.

The test environment where I observed TMPDIR containing a trailing
slash is macOS, so it's a fairly common setup. One justification is
that we should not expose such blemishes to users -- that's what I've
written below but perhaps there's a better way to express it?

What do you and others think about the proposed message below and
whether or not this patch is worth applying?

"""
difftool: use a strbuf to create a tmpdir path without repeated slashes

The paths generated by difftool are passed to user-facing diff tools.
Using paths with repeated slashes in them is a cosmetic blemish that
is exposed to users and can be avoided.

Use a strbuf to create the buffer used for the dir-diff tmpdir.
Strip trailing slashes "/" from the value read from TMPDIR to avoid
repeated slashes in the generated paths.

Add a unit test to ensure that repeated slashes are not present.

"""
-- 
David

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19 19:28         ` David Aguilar
@ 2021-09-19 19:50           ` Johannes Sixt
  0 siblings, 0 replies; 16+ messages in thread
From: Johannes Sixt @ 2021-09-19 19:50 UTC (permalink / raw)
  To: David Aguilar
  Cc: Junio C Hamano, Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh,
	Ævar Arnfjörð Bjarmason

Am 19.09.21 um 21:28 schrieb David Aguilar:
> On Sun, Sep 19, 2021 at 11:46 AM Johannes Sixt <j6t@kdbg.org> wrote:
>>
>> Am 19.09.21 um 20:13 schrieb David Aguilar:
>>> A better title might be:
>>>
>>>     difftool: use a strbuf to generate a tmpdir path without double-slashes
>>>
>>> The double-slashes are the point. This patch is a minor cleanup that I
>>> found on the path towards fixing the data loss bug in patch 4.
>>>
>>> Thanks for the heads-up about the confusion ~ I'll reword in the next
>>> submission to make this point clearer.
>>
>> Thanks. My primary concern with the patch was actually that it looks
>> like mere code churn that introduces an error by not using is_dir_sep().
>> This is now settled.
>>
>> But still, without a justification why the slashes should be cleaned up,
>> the patch looks like code churn. You can ignore me if it is obvious for
>> others why we need the patch.
> 
> Nah, that's a good point. Thanks for clarifying. I'll hold off on
> resending until we've reached consensus on this patch.
> 
> The final bugfix patch is the most important one in the series so
> perhaps I should reorder the series so that the bugfix comes first,
> and these cosmetic improvements and typo fixes are the later ones in
> the series? That'll make it so that the bugfix is easier to backport
> and not entangled with these prep fixups.
> 
> I see double-slashes when using the dir-diff feature and they just
> look wrong to me, but "striving for perfection" is a mere subjective
> justification.
> 
> The double-slashes fixup is cosmetic from a technical perspective, but
> since the paths are exposed to the diff tools it's a cosmetic blemish
> that users will see front and center.
> 
> The test environment where I observed TMPDIR containing a trailing
> slash is macOS, so it's a fairly common setup. One justification is
> that we should not expose such blemishes to users -- that's what I've
> written below but perhaps there's a better way to express it?
> 
> What do you and others think about the proposed message below and
> whether or not this patch is worth applying?
> 
> """
> difftool: use a strbuf to create a tmpdir path without repeated slashes
> 
> The paths generated by difftool are passed to user-facing diff tools.
> Using paths with repeated slashes in them is a cosmetic blemish that
> is exposed to users and can be avoided.
> 
> Use a strbuf to create the buffer used for the dir-diff tmpdir.
> Strip trailing slashes "/" from the value read from TMPDIR to avoid
> repeated slashes in the generated paths.
> 
> Add a unit test to ensure that repeated slashes are not present.
> 
> """

With the justification that the path is user-visible you have my full
consent to this patch. It shows a careful eye for the detail.

-- Hannes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests
  2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
                   ` (3 preceding siblings ...)
  2021-09-19 13:25 ` [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests Ævar Arnfjörð Bjarmason
@ 2021-09-20 18:28 ` Junio C Hamano
  4 siblings, 0 replies; 16+ messages in thread
From: Junio C Hamano @ 2021-09-20 18:28 UTC (permalink / raw)
  To: David Aguilar
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh

David Aguilar <davvid@gmail.com> writes:

> The "dirlinks" and "growing" repositories should not outlive the
> tests that use them.
>
> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
>  t/t7800-difftool.sh | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
> index a173f564bc..a923f193da 100755
> --- a/t/t7800-difftool.sh
> +++ b/t/t7800-difftool.sh
> @@ -414,6 +414,7 @@ test_expect_success 'setup change in subdirectory' '
>  test_expect_success 'difftool -d with growing paths' '
>  	a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
>  	git init growing &&
> +	test_when_finished rm -rf growing &&

If "git init" fails after it created the directory, it will be left
behind because test_when_finished hasn't been called yet.  The same
problem exists in the other hunk.  Moving it above "git init" may
trigger "rm -rf X" where X does not exist yet, but that is what you
are giving the 'f'orce option there for.

Not a huge deal and no need to resend only to fix them alone,
though.

>  	(
>  		cd growing &&
>  		echo "test -f \"\$2/b\"" | write_script .git/test-for-b.sh &&
> @@ -646,6 +647,7 @@ test_expect_success 'difftool properly honors gitlink and core.worktree' '
>  test_expect_success SYMLINKS 'difftool --dir-diff symlinked directories' '
>  	test_when_finished git reset --hard &&
>  	git init dirlinks &&
> +	test_when_finished rm -rf dirlinks &&
>  	(
>  		cd dirlinks &&
>  		git config diff.tool checktrees &&

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/4] difftool: use a strbuf to create the tmpdir path
  2021-09-19  2:33     ` [PATCH v2 " David Aguilar
@ 2021-09-20 18:35       ` Junio C Hamano
  0 siblings, 0 replies; 16+ messages in thread
From: Junio C Hamano @ 2021-09-20 18:35 UTC (permalink / raw)
  To: David Aguilar
  Cc: Git Mailing List, Johannes Schindelin, Alan Blotz,
	Đoàn Trần Công Danh, Jeff King

David Aguilar <davvid@gmail.com> writes:

> 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.
>
> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
> Changes since v1:
> - Updated to use strbuf_trim_trailing_dir_sep().
>
> Thanks Peff!

> @@ -333,11 +332,11 @@ static int checkout_path(unsigned mode, struct object_id *oid,
>  static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
>  			struct child_process *child)

This is taken hostage by the topic 'ab/retire-option-argument',
which is not yet in 'master' and can never be merged to 'maint',
which is not something you may want to do if this topic is meant as
a bugfix.

I may queue this topic on top of a merge of 'ab/retire-option-argument'
into 'master' for now.

Thanks.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-09-20 18:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19  1:57 [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests David Aguilar
2021-09-19  1:57 ` [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments David Aguilar
2021-09-19  1:57 ` [PATCH 3/4] difftool: use a strbuf to create the tmpdir path David Aguilar
2021-09-19  2:17   ` Jeff King
2021-09-19  2:33     ` [PATCH v2 " David Aguilar
2021-09-20 18:35       ` Junio C Hamano
2021-09-19  9:00   ` [PATCH " Johannes Sixt
2021-09-19 18:13     ` David Aguilar
2021-09-19 18:46       ` Johannes Sixt
2021-09-19 19:28         ` David Aguilar
2021-09-19 19:50           ` Johannes Sixt
2021-09-19  1:57 ` [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode David Aguilar
2021-09-19  2:02   ` [PATCH v2 " David Aguilar
2021-09-19  2:21     ` [PATCH v3 " David Aguilar
2021-09-19 13:25 ` [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests Ævar Arnfjörð Bjarmason
2021-09-20 18:28 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).