git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] Show an error if too-long paths are seen by git clean -dfx
@ 2019-07-16 14:04 Johannes Schindelin via GitGitGadget
  2019-07-16 14:04 ` [PATCH 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
  2019-07-18  9:30 ` [PATCH v2 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
  0 siblings, 2 replies; 12+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-16 14:04 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

This is particularly important on Windows, where PATH_MAX is very small
compared to Unix/Linux.

Johannes Schindelin (1):
  clean: show an error message when the path is too long

 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)


base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-219%2Fdscho%2Fclean-long-paths-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-219/dscho/clean-long-paths-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/219
-- 
gitgitgadget

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

* [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-16 14:04 [PATCH 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
@ 2019-07-16 14:04 ` Johannes Schindelin via GitGitGadget
  2019-07-16 15:01   ` René Scharfe
  2019-07-16 16:13   ` SZEDER Gábor
  2019-07-18  9:30 ` [PATCH v2 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
  1 sibling, 2 replies; 12+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-16 14:04 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

Without an error message when stat() failed, e.g. `git clean` would
abort without an error message, leaving the user quite puzzled.

In particular on Windows, where the default maximum path length is quite
small (yet there are ways to circumvent that limit in many cases), it is
very important that users be given an indication why their command
failed because of too long paths when it did.

This test case makes sure that a warning is issued that would have
helped the user who reported this issue:

	https://github.com/git-for-windows/git/issues/521

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/builtin/clean.c b/builtin/clean.c
index aaba4af3c2..7be689f480 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -194,7 +194,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
 		strbuf_setlen(path, len);
 		strbuf_addstr(path, e->d_name);
 		if (lstat(path->buf, &st))
-			; /* fall thru */
+			warning("Could not stat path '%s': %s",
+				path->buf, strerror(errno));
 		else if (S_ISDIR(st.st_mode)) {
 			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
 				ret = 1;
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 7b36954d63..aa08443f6a 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -669,4 +669,15 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
 	test_path_is_missing foo/b/bb
 '
 
+test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
+	git config core.longpaths false &&
+	test_when_finished git config --unset core.longpaths &&
+	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
+	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
+	touch $a50$a50/test.txt &&
+	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
+	test_must_fail git clean -xdf 2>.git/err &&
+	grep "too long" .git/err
+'
+
 test_done
-- 
gitgitgadget

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

* Re: [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-16 14:04 ` [PATCH 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
@ 2019-07-16 15:01   ` René Scharfe
  2019-07-16 19:56     ` Junio C Hamano
  2019-07-16 16:13   ` SZEDER Gábor
  1 sibling, 1 reply; 12+ messages in thread
From: René Scharfe @ 2019-07-16 15:01 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget, git
  Cc: Junio C Hamano, Johannes Schindelin

Am 16.07.19 um 16:04 schrieb Johannes Schindelin via GitGitGadget:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> Without an error message when stat() failed, e.g. `git clean` would
> abort without an error message, leaving the user quite puzzled.
>
> In particular on Windows, where the default maximum path length is quite
> small (yet there are ways to circumvent that limit in many cases), it is
> very important that users be given an indication why their command
> failed because of too long paths when it did.
>
> This test case makes sure that a warning is issued that would have
> helped the user who reported this issue:
>
> 	https://github.com/git-for-windows/git/issues/521
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  builtin/clean.c  |  3 ++-
>  t/t7300-clean.sh | 11 +++++++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index aaba4af3c2..7be689f480 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -194,7 +194,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
>  		strbuf_setlen(path, len);
>  		strbuf_addstr(path, e->d_name);
>  		if (lstat(path->buf, &st))
> -			; /* fall thru */

I don't understand the "fall thru" comment here.  It only makes sense in
switch statements, doesn't it?  And the code after this if/else-if/else
block is only executed if we pass through here, so why was it placed way
down in the first place?  Perhaps for historical reasons.

dir.c::remove_dir_recurse() has such a comment as well, by the way.

Anyway, I'd keep that strange comment, as I don't see a connection to
your changes.  (Or explain in the commit message why we no longer "fall
thru", whatever that may mean.  Or perhaps I'm just thick.)

> +			warning("Could not stat path '%s': %s",
> +				path->buf, strerror(errno));

The other warnings in that function are issued using warning_errno()
(shorter code, consistency is enforced) and messages are marked for
translation.  That would be nice to have here as well, no?

>  		else if (S_ISDIR(st.st_mode)) {
>  			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
>  				ret = 1;
> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
> index 7b36954d63..aa08443f6a 100755
> --- a/t/t7300-clean.sh
> +++ b/t/t7300-clean.sh
> @@ -669,4 +669,15 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
>  	test_path_is_missing foo/b/bb
>  '
>
> +test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
> +	git config core.longpaths false &&
> +	test_when_finished git config --unset core.longpaths &&
> +	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
> +	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
> +	touch $a50$a50/test.txt &&
> +	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
> +	test_must_fail git clean -xdf 2>.git/err &&
> +	grep "too long" .git/err

The pattern "too long" is expected to be supplied by strerror(3), right?
Depending on the locale it might return an message in a different
language, so test_i18ngrep should be used here even if the warning above
is not translated, right?

> +'
> +
>  test_done
>


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

* Re: [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-16 14:04 ` [PATCH 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
  2019-07-16 15:01   ` René Scharfe
@ 2019-07-16 16:13   ` SZEDER Gábor
  1 sibling, 0 replies; 12+ messages in thread
From: SZEDER Gábor @ 2019-07-16 16:13 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget
  Cc: git, Junio C Hamano, Johannes Schindelin

On Tue, Jul 16, 2019 at 07:04:23AM -0700, Johannes Schindelin via GitGitGadget wrote:
> +test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
> +	git config core.longpaths false &&
> +	test_when_finished git config --unset core.longpaths &&

'test_config core.longpaths false' could replace the above two lines
with a single one.

> +	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
> +	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
> +	touch $a50$a50/test.txt &&
> +	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&

Is there a reason for using 'touch' to create these files here,
instead of the usual '>"$file"' shell redirections?  Something
Windows/MinGW/long path specific, perhaps?

> +	test_must_fail git clean -xdf 2>.git/err &&

I was puzzled when I saw that '2>.git/err' first, because why put that
file in the .git directory?!  but of course 'git clean' would delete
that file if it were in the worktree.  OK.

> +	grep "too long" .git/err
> +'
> +
>  test_done
> -- 
> gitgitgadget

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

* Re: [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-16 15:01   ` René Scharfe
@ 2019-07-16 19:56     ` Junio C Hamano
  2019-07-17 18:50       ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2019-07-16 19:56 UTC (permalink / raw)
  To: René Scharfe
  Cc: Johannes Schindelin via GitGitGadget, git, Johannes Schindelin

René Scharfe <l.s.r@web.de> writes:

>> diff --git a/builtin/clean.c b/builtin/clean.c
>> index aaba4af3c2..7be689f480 100644
>> --- a/builtin/clean.c
>> +++ b/builtin/clean.c
>> @@ -194,7 +194,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
>>  		strbuf_setlen(path, len);
>>  		strbuf_addstr(path, e->d_name);
>>  		if (lstat(path->buf, &st))
>> -			; /* fall thru */
>
> I don't understand the "fall thru" comment here.  It only makes sense in
> switch statements, doesn't it?  And the code after this if/else-if/else
> block is only executed if we pass through here, so why was it placed way
> down in the first place?  Perhaps for historical reasons.

f538a91e ("git-clean: Display more accurate delete messages",
2013-01-11) introduced that line when it first introduced the
function and it is not inherited from anything else.  As the if/else
cascade has a catch-all else that always continues at the end, failing
lstat is the only way for the entire loop to break out early, so as
you hinted above, having the "fail, break and return" right there would
probably be a better organization of this loop.

> Anyway, I'd keep that strange comment, as I don't see a connection to
> your changes.  (Or explain in the commit message why we no longer "fall
> thru", whatever that may mean.  Or perhaps I'm just thick.)
>
>> +			warning("Could not stat path '%s': %s",
>> +				path->buf, strerror(errno));
>
> The other warnings in that function are issued using warning_errno()
> (shorter code, consistency is enforced) and messages are marked for
> translation.  That would be nice to have here as well, no?

Absolutely.  Also, downcase "Could" and perhaps use _() around.

As to the "fall thru" comment, I tend to agree that it does not fall
through to the next "case" in the usual sense and is confusing.
Mentioning that we removed a confusing and pointless comment in the
log message would be nice, but I'd vote for removing it if I was
asked.

Thanks.






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

* Re: [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-16 19:56     ` Junio C Hamano
@ 2019-07-17 18:50       ` Junio C Hamano
  2019-07-18  8:49         ` Johannes Schindelin
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2019-07-17 18:50 UTC (permalink / raw)
  To: git
  Cc: Johannes Schindelin via GitGitGadget, René Scharfe,
	Johannes Schindelin

Junio C Hamano <gitster@pobox.com> writes:

>> The other warnings in that function are issued using warning_errno()
>> (shorter code, consistency is enforced) and messages are marked for
>> translation.  That would be nice to have here as well, no?
>
> Absolutely.  Also, downcase "Could" and perhaps use _() around.


This one is easy enough (not just in the technical sense, but in the
sense that it has little room wasting our time bikeshedding), so
let's tie the loose ends and move on.

I was tempted to fix the proposed log message to excise exaggeration
(I prefer not to see "very", "important", etc.---other things that
is said in the message should be enough to convince readers about
the importance), but didn't.  

What I did do was to not just rephrasing the warning message, but to
give it its own constant and to feed it to warning_errno(), to match
the other warning message.

I also saved one (or perhaps two) fork(s) from the test script ;-)
and added a portability note there.

1:  d93f701a2e ! 1:  b1e100aa6a clean: show an error message when the path is too long
    @@ Metadata
      ## Commit message ##
         clean: show an error message when the path is too long
     
    -    Without an error message when stat() failed, e.g. `git clean` would
    +    Without an error message when lstat() failed, `git clean` would
         abort without an error message, leaving the user quite puzzled.
     
         In particular on Windows, where the default maximum path length is quite
    @@ Commit message
                 https://github.com/git-for-windows/git/issues/521
     
         Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
    +    [jc: matched the warning message style to existing ones, fixed test]
         Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
      ## builtin/clean.c ##
    +@@ builtin/clean.c: static const char *msg_would_remove = N_("Would remove %s\n");
    + static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
    + static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
    + static const char *msg_warn_remove_failed = N_("failed to remove %s");
    ++static const char *msg_warn_lstat_failed = N_("could not lstat %s\n");
    + 
    + enum color_clean {
    + 	CLEAN_COLOR_RESET = 0,
     @@ builtin/clean.c: static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
      		strbuf_setlen(path, len);
      		strbuf_addstr(path, e->d_name);
      		if (lstat(path->buf, &st))
     -			; /* fall thru */
    -+			warning("Could not stat path '%s': %s",
    -+				path->buf, strerror(errno));
    ++			warning_errno(_(msg_warn_lstat_failed), path->buf);
      		else if (S_ISDIR(st.st_mode)) {
      			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
      				ret = 1;
    @@ t/t7300-clean.sh: test_expect_success 'git clean -d skips untracked dirs contain
     +	test_when_finished git config --unset core.longpaths &&
     +	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
     +	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
    -+	touch $a50$a50/test.txt &&
    -+	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
    ++	: >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" &&
    ++	# create a temporary outside the working tree to hide from "git clean"
     +	test_must_fail git clean -xdf 2>.git/err &&
    -+	grep "too long" .git/err
    ++	# grepping for a strerror string is unportable but it is OK here with
    ++	# MINGW prereq
    ++	test_i18ngrep "too long" .git/err
     +'
     +
      test_done



-- >8 --
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH] clean: show an error message when the path is too long

Without an error message when lstat() failed, `git clean` would
abort without an error message, leaving the user quite puzzled.

In particular on Windows, where the default maximum path length is quite
small (yet there are ways to circumvent that limit in many cases), it is
very important that users be given an indication why their command
failed because of too long paths when it did.

This test case makes sure that a warning is issued that would have
helped the user who reported this issue:

	https://github.com/git-for-windows/git/issues/521

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
[jc: matched the warning message style to existing ones, fixed test]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/builtin/clean.c b/builtin/clean.c
index aaba4af3c2..d5579da716 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -34,6 +34,7 @@ static const char *msg_would_remove = N_("Would remove %s\n");
 static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
 static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
 static const char *msg_warn_remove_failed = N_("failed to remove %s");
+static const char *msg_warn_lstat_failed = N_("could not lstat %s\n");
 
 enum color_clean {
 	CLEAN_COLOR_RESET = 0,
@@ -194,7 +195,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
 		strbuf_setlen(path, len);
 		strbuf_addstr(path, e->d_name);
 		if (lstat(path->buf, &st))
-			; /* fall thru */
+			warning_errno(_(msg_warn_lstat_failed), path->buf);
 		else if (S_ISDIR(st.st_mode)) {
 			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
 				ret = 1;
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 7b36954d63..bde55b358c 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -669,4 +669,17 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
 	test_path_is_missing foo/b/bb
 '
 
+test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
+	git config core.longpaths false &&
+	test_when_finished git config --unset core.longpaths &&
+	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
+	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
+	: >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" &&
+	# create a temporary outside the working tree to hide from "git clean"
+	test_must_fail git clean -xdf 2>.git/err &&
+	# grepping for a strerror string is unportable but it is OK here with
+	# MINGW prereq
+	test_i18ngrep "too long" .git/err
+'
+
 test_done
-- 
2.22.0-653-g37fc7794bc







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

* Re: [PATCH 1/1] clean: show an error message when the path is too long
  2019-07-17 18:50       ` Junio C Hamano
@ 2019-07-18  8:49         ` Johannes Schindelin
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Schindelin @ 2019-07-18  8:49 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Johannes Schindelin via GitGitGadget, René Scharfe,
	SZEDER Gábor

[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]

Hi,

On Wed, 17 Jul 2019, Junio C Hamano wrote:

> Junio C Hamano <gitster@pobox.com> writes:
>
> >> The other warnings in that function are issued using
> >> warning_errno() (shorter code, consistency is enforced) and
> >> messages are marked for translation.  That would be nice to have
> >> here as well, no?
> >
> > Absolutely.  Also, downcase "Could" and perhaps use _() around.
>
>
> This one is easy enough (not just in the technical sense, but in the
> sense that it has little room wasting our time bikeshedding), so let's
> tie the loose ends and move on.
>
> I was tempted to fix the proposed log message to excise exaggeration
> (I prefer not to see "very", "important", etc.---other things that is
> said in the message should be enough to convince readers about the
> importance), but didn't.
>
> What I did do was to not just rephrasing the warning message, but to
> give it its own constant and to feed it to warning_errno(), to match
> the other warning message.
>
> I also saved one (or perhaps two) fork(s) from the test script ;-) and
> added a portability note there.

Thanks!

On top, I integrated Gabór's suggestion to use `test_config` and threw
in a paragraph in the commit message to explain why the `core.longpaths`
variable is touched at all.

v2 incoming,
Dscho

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

* [PATCH v2 0/1] Show an error if too-long paths are seen by git clean -dfx
  2019-07-16 14:04 [PATCH 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
  2019-07-16 14:04 ` [PATCH 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
@ 2019-07-18  9:30 ` Johannes Schindelin via GitGitGadget
  2019-07-18  9:30   ` [PATCH v2 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
  1 sibling, 1 reply; 12+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-18  9:30 UTC (permalink / raw)
  To: git
  Cc: René Scharfe <l.s.r@web.de>, SZEDER Gábor,
	Junio C Hamano

This is particularly important on Windows, where PATH_MAX is very small
compared to Unix/Linux.

Changes since v1:

 * Matched the warning message style to existing ones,
 * Fixed test in multiple ways: * Avoiding touch in favor of : >.
    * Using test_config.
    * Using test_i18ngrep instead of grep to avoid localization problems.
    * Add helpful comments.
   
   
 * The commit message now talks about lstat() instead of stat().
 * The commit message also explains where that core.longpaths comes from.

Johannes Schindelin (1):
  clean: show an error message when the path is too long

 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)


base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-219%2Fdscho%2Fclean-long-paths-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-219/dscho/clean-long-paths-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/219

Range-diff vs v1:

 1:  36677556a2 ! 1:  c7b11fe410 clean: show an error message when the path is too long
     @@ -2,7 +2,7 @@
      
          clean: show an error message when the path is too long
      
     -    Without an error message when stat() failed, e.g. `git clean` would
     +    Without an error message when `lstat()` failed, `git clean` would
          abort without an error message, leaving the user quite puzzled.
      
          In particular on Windows, where the default maximum path length is quite
     @@ -15,18 +15,32 @@
      
                  https://github.com/git-for-windows/git/issues/521
      
     +    Note that we temporarily set `core.longpaths = false` in the regression
     +    test; This ensures forward-compatibility with the `core.longpaths`
     +    feature that has not yet been upstreamed from Git for Windows.
     +
     +    Helped-by: René Scharfe <l.s.r@web.de>
     +    Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
     +    Helped-by: Junio C Hamano <gitster@pobox.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       diff --git a/builtin/clean.c b/builtin/clean.c
       --- a/builtin/clean.c
       +++ b/builtin/clean.c
     +@@
     + static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
     + static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
     + static const char *msg_warn_remove_failed = N_("failed to remove %s");
     ++static const char *msg_warn_lstat_failed = N_("could not lstat %s\n");
     + 
     + enum color_clean {
     + 	CLEAN_COLOR_RESET = 0,
      @@
       		strbuf_setlen(path, len);
       		strbuf_addstr(path, e->d_name);
       		if (lstat(path->buf, &st))
      -			; /* fall thru */
     -+			warning("Could not stat path '%s': %s",
     -+				path->buf, strerror(errno));
     ++			warning_errno(_(msg_warn_lstat_failed), path->buf);
       		else if (S_ISDIR(st.st_mode)) {
       			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
       				ret = 1;
     @@ -39,14 +53,15 @@
       '
       
      +test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
     -+	git config core.longpaths false &&
     -+	test_when_finished git config --unset core.longpaths &&
     ++	test_config core.longpaths false &&
      +	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
      +	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
     -+	touch $a50$a50/test.txt &&
     -+	touch $a50$a50/$a50$a50/$a50$a50/test.txt &&
     ++	: >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" &&
     ++	# create a temporary outside the working tree to hide from "git clean"
      +	test_must_fail git clean -xdf 2>.git/err &&
     -+	grep "too long" .git/err
     ++	# grepping for a strerror string is unportable but it is OK here with
     ++	# MINGW prereq
     ++	test_i18ngrep "too long" .git/err
      +'
      +
       test_done

-- 
gitgitgadget

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

* [PATCH v2 1/1] clean: show an error message when the path is too long
  2019-07-18  9:30 ` [PATCH v2 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
@ 2019-07-18  9:30   ` Johannes Schindelin via GitGitGadget
  2019-07-18 16:03     ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-18  9:30 UTC (permalink / raw)
  To: git
  Cc: René Scharfe <l.s.r@web.de>, SZEDER Gábor,
	Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

Without an error message when `lstat()` failed, `git clean` would
abort without an error message, leaving the user quite puzzled.

In particular on Windows, where the default maximum path length is quite
small (yet there are ways to circumvent that limit in many cases), it is
very important that users be given an indication why their command
failed because of too long paths when it did.

This test case makes sure that a warning is issued that would have
helped the user who reported this issue:

	https://github.com/git-for-windows/git/issues/521

Note that we temporarily set `core.longpaths = false` in the regression
test; This ensures forward-compatibility with the `core.longpaths`
feature that has not yet been upstreamed from Git for Windows.

Helped-by: René Scharfe <l.s.r@web.de>
Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/clean.c  |  3 ++-
 t/t7300-clean.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/builtin/clean.c b/builtin/clean.c
index aaba4af3c2..d5579da716 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -34,6 +34,7 @@ static const char *msg_would_remove = N_("Would remove %s\n");
 static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
 static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
 static const char *msg_warn_remove_failed = N_("failed to remove %s");
+static const char *msg_warn_lstat_failed = N_("could not lstat %s\n");
 
 enum color_clean {
 	CLEAN_COLOR_RESET = 0,
@@ -194,7 +195,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
 		strbuf_setlen(path, len);
 		strbuf_addstr(path, e->d_name);
 		if (lstat(path->buf, &st))
-			; /* fall thru */
+			warning_errno(_(msg_warn_lstat_failed), path->buf);
 		else if (S_ISDIR(st.st_mode)) {
 			if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
 				ret = 1;
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 7b36954d63..a2c45d1902 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -669,4 +669,16 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
 	test_path_is_missing foo/b/bb
 '
 
+test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
+	test_config core.longpaths false &&
+	a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
+	mkdir -p $a50$a50/$a50$a50/$a50$a50 &&
+	: >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" &&
+	# create a temporary outside the working tree to hide from "git clean"
+	test_must_fail git clean -xdf 2>.git/err &&
+	# grepping for a strerror string is unportable but it is OK here with
+	# MINGW prereq
+	test_i18ngrep "too long" .git/err
+'
+
 test_done
-- 
gitgitgadget

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

* Re: [PATCH v2 1/1] clean: show an error message when the path is too long
  2019-07-18  9:30   ` [PATCH v2 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
@ 2019-07-18 16:03     ` Junio C Hamano
  2019-07-19 12:53       ` Johannes Schindelin
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2019-07-18 16:03 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget
  Cc: git, René Scharfe <l.s.r@web.de>, SZEDER Gábor,
	Johannes Schindelin

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> Without an error message when `lstat()` failed, `git clean` would
> abort without an error message, leaving the user quite puzzled.

Let's drop the first three words ;-)  Sorry for not catching it
earlier and parrotting the same mistake in my variant yesterday.

> In particular on Windows, where the default maximum path length is quite
> small (yet there are ways to circumvent that limit in many cases), it is
> very important that users be given an indication why their command
> failed because of too long paths when it did.

s/it is very important that users be given/it helps to give users/


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

* Re: [PATCH v2 1/1] clean: show an error message when the path is too long
  2019-07-18 16:03     ` Junio C Hamano
@ 2019-07-19 12:53       ` Johannes Schindelin
  2019-07-19 15:10         ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Johannes Schindelin @ 2019-07-19 12:53 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Schindelin via GitGitGadget, git,
	René Scharfe <l.s.r@web.de>, SZEDER Gábor

Hi Junio,

On Thu, 18 Jul 2019, Junio C Hamano wrote:

> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > Without an error message when `lstat()` failed, `git clean` would
> > abort without an error message, leaving the user quite puzzled.
>
> Let's drop the first three words ;-)  Sorry for not catching it
> earlier and parrotting the same mistake in my variant yesterday.

You mean the first four words.

> > In particular on Windows, where the default maximum path length is quite
> > small (yet there are ways to circumvent that limit in many cases), it is
> > very important that users be given an indication why their command
> > failed because of too long paths when it did.
>
> s/it is very important that users be given/it helps to give users/

If you really feel it important to invalidate my personal style of
expression, sure.

Ciao,
Dscho

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

* Re: [PATCH v2 1/1] clean: show an error message when the path is too long
  2019-07-19 12:53       ` Johannes Schindelin
@ 2019-07-19 15:10         ` Junio C Hamano
  0 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2019-07-19 15:10 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Johannes Schindelin via GitGitGadget, git,
	René Scharfe <l.s.r@web.de>, SZEDER Gábor

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Thu, 18 Jul 2019, Junio C Hamano wrote:
>
>> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
>> writes:
>>
>> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
>> >
>> > Without an error message when `lstat()` failed, `git clean` would
>> > abort without an error message, leaving the user quite puzzled.
>>
>> Let's drop the first three words ;-)  Sorry for not catching it
>> earlier and parrotting the same mistake in my variant yesterday.
>
> You mean the first four words.

Eek, yes, I cannot count ;-)

>> > In particular on Windows, where the default maximum path length is quite
>> > small (yet there are ways to circumvent that limit in many cases), it is
>> > very important that users be given an indication why their command
>> > failed because of too long paths when it did.
>>
>> s/it is very important that users be given/it helps to give users/
>
> If you really feel it important to invalidate my personal style of
> expression, sure.

I meant it as a pure improvement---I think the importance of this
change to the affected population is so obvious that it does not
need self promoting exaggeration to convince readers by stating
plainly how it helps.

But if it is very important for you, I'll undo the change before
merging it to 'next'.

Thanks.
t

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

end of thread, other threads:[~2019-07-19 15:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 14:04 [PATCH 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
2019-07-16 14:04 ` [PATCH 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
2019-07-16 15:01   ` René Scharfe
2019-07-16 19:56     ` Junio C Hamano
2019-07-17 18:50       ` Junio C Hamano
2019-07-18  8:49         ` Johannes Schindelin
2019-07-16 16:13   ` SZEDER Gábor
2019-07-18  9:30 ` [PATCH v2 0/1] Show an error if too-long paths are seen by git clean -dfx Johannes Schindelin via GitGitGadget
2019-07-18  9:30   ` [PATCH v2 1/1] clean: show an error message when the path is too long Johannes Schindelin via GitGitGadget
2019-07-18 16:03     ` Junio C Hamano
2019-07-19 12:53       ` Johannes Schindelin
2019-07-19 15:10         ` 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).