All of lore.kernel.org
 help / color / mirror / Atom feed
* Bug with automated processing of git status results
@ 2017-06-30  6:00 Сергей Шестаков
  2017-06-30  7:12 ` Konstantin Khomoutov
  2017-06-30  9:09 ` Matthieu Moy
  0 siblings, 2 replies; 9+ messages in thread
From: Сергей Шестаков @ 2017-06-30  6:00 UTC (permalink / raw)
  To: git

Hi!

I am trying to make an automated processing of "git status" results.
I execute the command

git status -z -uno

I expect that it has stable output format. However, it still can print
warnings like

warning: CRLF will be replaced by LF in somefile.xml

I understand that we can turn off core.safecrlf, but it's
inconvinient. It would be better if "git status" command had an
optional parameter that disables any other output besides changed
files.

Thanks!
Sergey Shestakov
Playrix

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

* Re: Bug with automated processing of git status results
  2017-06-30  6:00 Bug with automated processing of git status results Сергей Шестаков
@ 2017-06-30  7:12 ` Konstantin Khomoutov
  2017-06-30  9:09 ` Matthieu Moy
  1 sibling, 0 replies; 9+ messages in thread
From: Konstantin Khomoutov @ 2017-06-30  7:12 UTC (permalink / raw)
  To: Сергей
	Шестаков
  Cc: git

On Fri, Jun 30, 2017 at 09:00:14AM +0300, Сергей Шестаков wrote:

> I am trying to make an automated processing of "git status" results.
> I execute the command
> 
> git status -z -uno
> 
> I expect that it has stable output format. However, it still can print
> warnings like
> 
> warning: CRLF will be replaced by LF in somefile.xml
> 
> I understand that we can turn off core.safecrlf, but it's
> inconvinient. It would be better if "git status" command had an
> optional parameter that disables any other output besides changed
> files.

The `git status` command supposedly writes their "regular" data to its
standard output while warnings go to its standard error stream.
Is this not the case?


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

* Re: Bug with automated processing of git status results
  2017-06-30  6:00 Bug with automated processing of git status results Сергей Шестаков
  2017-06-30  7:12 ` Konstantin Khomoutov
@ 2017-06-30  9:09 ` Matthieu Moy
  2017-06-30  9:22   ` Torsten Bögershausen
  1 sibling, 1 reply; 9+ messages in thread
From: Matthieu Moy @ 2017-06-30  9:09 UTC (permalink / raw)
  To: Сергей
	Шестаков
  Cc: git

Сергей Шестаков <s_shestakov@playrix.com> writes:

> I understand that we can turn off core.safecrlf, but it's
> inconvinient.

Note that you can do that without actually changing the config file:

  git -c core.safecrlf=false status ...

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: Bug with automated processing of git status results
  2017-06-30  9:09 ` Matthieu Moy
@ 2017-06-30  9:22   ` Torsten Bögershausen
  2017-06-30 16:28     ` [PATCH] status: suppress additional warning output in plumbing modes Stefan Beller
  0 siblings, 1 reply; 9+ messages in thread
From: Torsten Bögershausen @ 2017-06-30  9:22 UTC (permalink / raw)
  To: Matthieu Moy,
	Сергей
	Шестаков
  Cc: git



On 30/06/17 11:09, Matthieu Moy wrote:
> Сергей Шестаков <s_shestakov@playrix.com> writes:
> 
>> I understand that we can turn off core.safecrlf, but it's
>> inconvinient.
> 
> Note that you can do that without actually changing the config file:
> 
>    git -c core.safecrlf=false status ...
> 
Beside that, I would recommend to set up a .gitattributes file:

$ echo "*.xml text eol=lf" >>.gitattributes
$ git add .gitattributes
$ git commit -m "xml files are text with LF line endings"

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

* [PATCH] status: suppress additional warning output in plumbing modes
  2017-06-30  9:22   ` Torsten Bögershausen
@ 2017-06-30 16:28     ` Stefan Beller
  2017-07-01 12:49       ` Torsten Bögershausen
                         ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stefan Beller @ 2017-06-30 16:28 UTC (permalink / raw)
  To: s_shestakov, kostix+git, Matthieu.Moy, tboegi; +Cc: git, Stefan Beller

When status is called with '--porcelain' (as implied by '-z'), we promise
to output only messages as described in the man page.

Suppress CRLF warnings.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

Maybe something like this?

 builtin/commit.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/builtin/commit.c b/builtin/commit.c
index 00a01f07c3..3705d5ec6f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1126,6 +1126,11 @@ static void finalize_deferred_config(struct wt_status *s)
 			die(_("--long and -z are incompatible"));
 	}
 
+	/* suppress all additional output in porcelain mode */
+	if (status_format == STATUS_FORMAT_PORCELAIN ||
+	    status_format == STATUS_FORMAT_PORCELAIN_V2)
+		safe_crlf = SAFE_CRLF_FALSE;
+
 	if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED)
 		status_format = status_deferred_config.status_format;
 	if (status_format == STATUS_FORMAT_UNSPECIFIED)
-- 
2.13.0.31.g9b732c453e


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

* Re: [PATCH] status: suppress additional warning output in plumbing modes
  2017-06-30 16:28     ` [PATCH] status: suppress additional warning output in plumbing modes Stefan Beller
@ 2017-07-01 12:49       ` Torsten Bögershausen
  2017-07-01 13:52       ` Ævar Arnfjörð Bjarmason
  2017-07-01 17:35       ` Junio C Hamano
  2 siblings, 0 replies; 9+ messages in thread
From: Torsten Bögershausen @ 2017-07-01 12:49 UTC (permalink / raw)
  To: Stefan Beller, s_shestakov, kostix+git, Matthieu.Moy; +Cc: git



 >On 30/06/17 18:28, Stefan Beller wrote:

The patch makes a lot of sense - thanks for the fast reply.
A question: does the header correspond to the patch ?

< [PATCH] status: suppress additional warning output in plumbing modes
 > [PATCH] status: suppress CRLF warnings in porcelain modes

(And may be the comment in the code:)

< / * suppress all additional output in porcelain mode */
 > / * suppress CRLF conversion warnings in porcelain mode */

> When status is called with '--porcelain' (as implied by '-z'), we promise
> to output only messages as described in the man page.
> 
> Suppress CRLF warnings.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> 
> Maybe something like this?
> 
>   builtin/commit.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 00a01f07c3..3705d5ec6f 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1126,6 +1126,11 @@ static void finalize_deferred_config(struct wt_status *s)
>   			die(_("--long and -z are incompatible"));
>   	}
>   
> +	/* suppress all additional output in porcelain mode */
> +	if (status_format == STATUS_FORMAT_PORCELAIN ||
> +	    status_format == STATUS_FORMAT_PORCELAIN_V2)
> +		safe_crlf = SAFE_CRLF_FALSE;
> +
>   	if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED)
>   		status_format = status_deferred_config.status_format;
>   	if (status_format == STATUS_FORMAT_UNSPECIFIED)
> 

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

* Re: [PATCH] status: suppress additional warning output in plumbing modes
  2017-06-30 16:28     ` [PATCH] status: suppress additional warning output in plumbing modes Stefan Beller
  2017-07-01 12:49       ` Torsten Bögershausen
@ 2017-07-01 13:52       ` Ævar Arnfjörð Bjarmason
  2017-07-01 17:35       ` Junio C Hamano
  2 siblings, 0 replies; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-07-01 13:52 UTC (permalink / raw)
  To: Stefan Beller; +Cc: s_shestakov, kostix+git, Matthieu.Moy, tboegi, git


On Fri, Jun 30 2017, Stefan Beller jotted:

> When status is called with '--porcelain' (as implied by '-z'), we promise
> to output only messages as described in the man page.
>
> Suppress CRLF warnings.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Maybe something like this?

It looks sensibly implemented, but as for the approach I think we should
just document that you might get errors on stderr, but stable output on
stdout.

Many consumers of --porcelain, such as magit, will run arbitrary git
output and expect that if they get something on stderr they should be
showing it in some special buffer to the user as associated error
information.

I think it makes sense to do this & document it in the man page, if you
don't care about possible error messages 2>/dev/null is trivial, but
it's not trivial to discover in some non-expensive way (parsing the
non-porcelain output) that there *are* errors.

>  builtin/commit.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 00a01f07c3..3705d5ec6f 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1126,6 +1126,11 @@ static void finalize_deferred_config(struct wt_status *s)
>  			die(_("--long and -z are incompatible"));
>  	}
>
> +	/* suppress all additional output in porcelain mode */
> +	if (status_format == STATUS_FORMAT_PORCELAIN ||
> +	    status_format == STATUS_FORMAT_PORCELAIN_V2)
> +		safe_crlf = SAFE_CRLF_FALSE;
> +
>  	if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED)
>  		status_format = status_deferred_config.status_format;
>  	if (status_format == STATUS_FORMAT_UNSPECIFIED)

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

* Re: [PATCH] status: suppress additional warning output in plumbing modes
  2017-06-30 16:28     ` [PATCH] status: suppress additional warning output in plumbing modes Stefan Beller
  2017-07-01 12:49       ` Torsten Bögershausen
  2017-07-01 13:52       ` Ævar Arnfjörð Bjarmason
@ 2017-07-01 17:35       ` Junio C Hamano
  2017-07-05 18:53         ` Stefan Beller
  2 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2017-07-01 17:35 UTC (permalink / raw)
  To: Stefan Beller; +Cc: s_shestakov, kostix+git, Matthieu.Moy, tboegi, git

Stefan Beller <sbeller@google.com> writes:

> When status is called with '--porcelain' (as implied by '-z'), we promise
> to output only messages as described in the man page.
>
> Suppress CRLF warnings.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Maybe something like this?

This looks to me like a stimulus having enough time to go to the
spinal cord to induce a knee-jerk reaction, without giving a chance
to the brain to think things through.

Surely the reported symptom may have only been about CRLF, but who
says that would be the only kind of warning that would be seen
during "status --porcelain" codepath?

I tend to agree with Ævar's "output for the script can be read from
our standard output" should probably be our first response.

The patch _is_ a good start to document that we may want to do
something differently under _PORCELAIN output modes and one location
in the code that may be a good place to make that decision, but if
we are to squelch the warnings, we should make sure we do not give
any warning, not limited to squelching the safe-crlf warning, to the
standard error, but still diagnose errors and show error messages,
or something like that, I would think.

>
>  builtin/commit.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 00a01f07c3..3705d5ec6f 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1126,6 +1126,11 @@ static void finalize_deferred_config(struct wt_status *s)
>  			die(_("--long and -z are incompatible"));
>  	}
>  
> +	/* suppress all additional output in porcelain mode */
> +	if (status_format == STATUS_FORMAT_PORCELAIN ||
> +	    status_format == STATUS_FORMAT_PORCELAIN_V2)
> +		safe_crlf = SAFE_CRLF_FALSE;
> +
>  	if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED)
>  		status_format = status_deferred_config.status_format;
>  	if (status_format == STATUS_FORMAT_UNSPECIFIED)

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

* Re: [PATCH] status: suppress additional warning output in plumbing modes
  2017-07-01 17:35       ` Junio C Hamano
@ 2017-07-05 18:53         ` Stefan Beller
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Beller @ 2017-07-05 18:53 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Сергей
	Шестаков,
	Konstantin Khomoutov, Matthieu Moy, Torsten Bögershausen,
	git

On Sat, Jul 1, 2017 at 10:35 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> When status is called with '--porcelain' (as implied by '-z'), we promise
>> to output only messages as described in the man page.
>>
>> Suppress CRLF warnings.
>>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>
>> Maybe something like this?
>
> This looks to me like a stimulus having enough time to go to the
> spinal cord to induce a knee-jerk reaction, without giving a chance
> to the brain to think things through.
>

sort of.

> Surely the reported symptom may have only been about CRLF, but who
> says that would be the only kind of warning that would be seen
> during "status --porcelain" codepath?

I was slightly worried about this, too.

>
> I tend to agree with Ævar's "output for the script can be read from
> our standard output" should probably be our first response.
>
> The patch _is_ a good start to document that we may want to do
> something differently under _PORCELAIN output modes and one location
> in the code that may be a good place to make that decision, but if
> we are to squelch the warnings, we should make sure we do not give
> any warning, not limited to squelching the safe-crlf warning, to the
> standard error, but still diagnose errors and show error messages,
> or something like that, I would think.

So for now we'd rather want to go with a documentation patch first
and then the refinement of the porcelain mode of potentially
suppressing more warnings?

Note that this patch was a one-off by me, so I no longer pursue
fixing the problem here, someone else is kindly asked to step up.

Thanks,
Stefan

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

end of thread, other threads:[~2017-07-05 18:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30  6:00 Bug with automated processing of git status results Сергей Шестаков
2017-06-30  7:12 ` Konstantin Khomoutov
2017-06-30  9:09 ` Matthieu Moy
2017-06-30  9:22   ` Torsten Bögershausen
2017-06-30 16:28     ` [PATCH] status: suppress additional warning output in plumbing modes Stefan Beller
2017-07-01 12:49       ` Torsten Bögershausen
2017-07-01 13:52       ` Ævar Arnfjörð Bjarmason
2017-07-01 17:35       ` Junio C Hamano
2017-07-05 18:53         ` Stefan Beller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.