t7800-difftool: cleanup temporary repositories used by tests
PATCH 1/4 t7800-difftool: cleanup temporary repositories used by tests
The "dirlinks" and "growing" repositories should not outlive the tests that use them.
--- t/t7800-difftool.sh | 2 ++ 1 file changed, 2 insertions(+)
t/t7800-difftool.sh +2 -0
@@ -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 &&
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH 2/4 difftool: add a missing space to the run_dir_diff() comments
--- builtin/difftool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/difftool.c +1 -1
@@ -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. */
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH 3/4 difftool: use a strbuf to create the tmpdir path
In reply to David AguilarUse 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.
--- builtin/difftool.c | 32 +++++++++++++++++++------------- t/t7800-difftool.sh | 7 +++++++ 2 files changed, 26 insertions(+), 13 deletions(-)
builtin/difftool.c +19 -13
@@ -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; }
t/t7800-difftool.sh +7 -0
@@ -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 &&
Signature · 1 line
2.30.1 (Apple Git-130)
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
builtin/difftool.c static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, · line 367
Quoted 5 lines · David Aguilar
builtin/difftool.c +5
-0+/* 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
PATCH v2 3/4 difftool: use a strbuf to create the tmpdir path
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.
---
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(-)
builtin/difftool.c +15 -13
@@ -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; }
t/t7800-difftool.sh +7 -0
@@ -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 &&
Signature · 1 line
2.33.0.721.ga252b5a140
Re: [PATCH v2 3/4] difftool: use a strbuf to create the tmpdir path
Quoted 14 lines · 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.
Signed-off-by David Aguilar <[email protected]>---
Changes since v1:
- Updated to usestrbuf_trim_trailing_dir_sep().Thanks Peff!
builtin/difftool.c static int checkout_path(unsigned mode, struct object_id *oid, · line 333
Quoted 2 lines
builtin/difftool.c +0
-0@@ -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.
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
In reply to David AguilarAm 19.09.21 um 03:57 schrieb David Aguilar:
Quoted 5 lines
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?
builtin/difftool.c static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, · line 364
Quoted 12 lines
builtin/difftool.c +3
-5@@ -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
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
Quoted 6 lines · Johannes Sixt
Am 19.09.21 um 03:57 schrieb David Aguilar:
Quoted 4 lines
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.
Quoted 7 lines
Quoted 1 line
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.
Quoted 14 lines
builtin/difftool.c static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, · line 364
Quoted 12 lines
builtin/difftool.c +3
-5@@ -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,
Signature · 1 line
David
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
Am 19.09.21 um 20:13 schrieb David Aguilar:
Quoted 9 lines
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
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
Quoted 12 lines · Johannes Sixt
Am 19.09.21 um 20:13 schrieb David Aguilar:
Quoted 9 lines
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.
Quoted 7 lines
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.
"""
Signature · 1 line
David
Re: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path
Am 19.09.21 um 21:28 schrieb David Aguilar:
Quoted 53 lines · Johannes Sixt
Quoted 12 lines
Am 19.09.21 um 20:13 schrieb David Aguilar:
Quoted 9 lines
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.
Quoted 7 lines
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 slashesThe 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.
Quoted 7 lines
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
PATCH 4/4 difftool: fix symlink-file writing in dir-diff mode
In reply to David AguilarThe 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.
--- builtin/difftool.c | 2 ++ t/t7800-difftool.sh | 70 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-)
builtin/difftool.c +2 -0
@@ -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); } }
t/t7800-difftool.sh +68 -2
88 lines not on this page · raw message
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH v2 4/4 difftool: fix symlink-file writing in dir-diff mode
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.
---
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(-)
builtin/difftool.c +2 -0
@@ -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); } }
t/t7800-difftool.sh +67 -2
87 lines not on this page · raw message
Signature · 1 line
2.30.1 (Apple Git-130)
PATCH v3 4/4 difftool: fix symlink-file writing in dir-diff mode
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.
---
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(-)
builtin/difftool.c +2 -0
@@ -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); } }
t/t7800-difftool.sh +67 -2
87 lines not on this page · raw message
Signature · 1 line
2.30.1 (Apple Git-130)
Quoted 2 lines · David Aguilar
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?
Quoted 13 lines · David Aguilar
The "dirlinks" and "growing" repositories should not outlive the tests that use them.
Signed-off-by David Aguilar <[email protected]>--- t/t7800-difftool.sh | 2 ++ 1 file changed, 2 insertions(+)t/t7800-difftool.sh +0
-0
t/t7800-difftool.sh test_expect_success 'setup change in subdirectory' ' · line 417
Quoted 4 lines
t/t7800-difftool.sh +1
-0@@ -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.
Quoted 11 lines
t/t7800-difftool.sh +1
-0( 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 &&