git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: git@vger.kernel.org, eevee.reply@veekun.com
Subject: Re: [PATCH v1 1/1] convert:  git cherry-pick -Xrenormalize did not work
Date: Tue, 29 Nov 2016 12:45:14 -0800	[thread overview]
Message-ID: <xmqqzikidnhh.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161129201600.GA14333@tb-raspi> ("Torsten Bögershausen"'s message of "Tue, 29 Nov 2016 20:16:00 +0000")

Torsten Bögershausen <tboegi@web.de> writes:

> Thanks for the review - how about this:
>
>
> convert: git cherry-pick -Xrenormalize did not work
>
> Working with a repo that used to be all CRLF. At some point it
> was changed to all LF, with `text=auto` in .gitattributes.
> Trying to cherry-pick a commit from before the switchover fails:
>
> $ git cherry-pick -Xrenormalize <commit>
>     fatal: CRLF would be replaced by LF in [path]
>
> Commit 65237284 "unify the "auto" handling of CRLF" introduced
> a regression:
>
> Whenever crlf_action is CRLF_TEXT_XXX and not CRLF_AUTO_XXX,
> SAFE_CRLF_RENORMALIZE was feed into check_safe_crlf().
> This is wrong because here everything else than SAFE_CRLF_WARN is
> treated as SAFE_CRLF_FAIL.

What is still left unsaid is that we shouldn't even bother seeing if
it is safe to do crlf conversion when renormalizing.  Perhaps that
is too obvious to state?

In any case, when you put the rationale that way, the impression I
get from it is that the root cause of the problem is that "here"
(aka "check_safe_crlf()") considers anything other than CRLF_WARN as
a failure, when a newer choice other than CRLF_WARN and CRLF_FAIL
(namely, CRLF_RENORMALIZE) exists.  Which hints me that a sensible
change may be to fix that function.

The patch you sent has the effect of not entering this whole block,
not just "don't call check_safe_crlf() because it misbehaves":

	if (checksafe && len) {
		struct text_stat new_stats;
		memcpy(&new_stats, &stats, sizeof(new_stats));
		/* simulate "git add" */
		if (convert_crlf_into_lf) {
			new_stats.lonelf += new_stats.crlf;
			new_stats.crlf = 0;
		}
		/* simulate "git checkout" */
		if (will_convert_lf_to_crlf(len, &new_stats, crlf_action)) {
			new_stats.crlf += new_stats.lonelf;
			new_stats.lonelf = 0;
		}
		check_safe_crlf(path, crlf_action, &stats, &new_stats, checksafe);
	}

And it is a sensible thing to do, because all the computation that
happens in the block before check_safe_crlf() is called is done ONLY
to prepare the parameter passed to check_safe_crlf(); if we are to
make the function no-op for CRLF_RENORMALIZE, preparing new_stats is
a wasted effort.

However, futzing with the value of checksafe in the function is
ugly.  It is not even unclear if it is safe to do so without reading
the remainder of the function (i.e. later parts of the function may
care--or start caring in the future--what the caller passed in the
variable).  Yes, the function already modifies the variable, but
that can also be fixed.

In other words, I would have expected that a fix that matches your
description to look more like below.  The condition for the "if"
statement may even want to become

	if ((checksafe == SAFE_CRLF_WARN ||
	    (checksafe == SAFE_CRLF_FAIL)) && len)

to clarify it further.

Thanks.

 convert.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/convert.c b/convert.c
index f9f7f5e436..d72e0bf0d7 100644
--- a/convert.c
+++ b/convert.c
@@ -282,12 +282,11 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 		 * If the file in the index has any CR in it, do not convert.
 		 * This is the new safer autocrlf handling.
 		 */
-		if (checksafe == SAFE_CRLF_RENORMALIZE)
-			checksafe = SAFE_CRLF_FALSE;
-		else if (has_cr_in_index(path))
+		if (checksafe != SAFE_CRLF_RENORMALIZE &&
+		    has_cr_in_index(path))
 			convert_crlf_into_lf = 0;
 	}
-	if (checksafe && len) {
+	if (checksafe && checksafe != SAFE_CRLF_RENORMALIZE && len) {
 		struct text_stat new_stats;
 		memcpy(&new_stats, &stats, sizeof(new_stats));
 		/* simulate "git add" */



  reply	other threads:[~2016-11-29 20:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6a7e155-f399-c9f8-c69e-8164e0735dfb@veekun.com>
2016-11-29 16:30 ` [PATCH v1 1/1] convert: git cherry-pick -Xrenormalize did not work tboegi
2016-11-29 18:42   ` Junio C Hamano
2016-11-29 20:16     ` Torsten Bögershausen
2016-11-29 20:45       ` Junio C Hamano [this message]
2016-11-30 17:02 ` [PATCH v2 " tboegi
2016-12-01 18:27   ` Junio C Hamano
2016-12-01 20:07   ` Jacob Keller
2016-12-01 20:24     ` Junio C Hamano
2016-12-02 12:20       ` Torsten Bögershausen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzikidnhh.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=eevee.reply@veekun.com \
    --cc=git@vger.kernel.org \
    --cc=tboegi@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).