git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Christopher Warrington via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org,
	Christopher Warrington <chwarr@microsoft.com>
Subject: Re: [PATCH] bisect: fix replay of CRLF logs
Date: Fri, 08 May 2020 09:28:56 -0700	[thread overview]
Message-ID: <xmqq8si2z8zb.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <xmqqh7wq1n52.fsf@gitster.c.googlers.com> (Junio C. Hamano's message of "Fri, 08 May 2020 08:07:05 -0700")

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

> I wonder if we can add a CR to IFS so that the parsing logic of each
> line would not even see it?

So I got curious and tried this; it seems to pass Christopher's test
(corrected with Eric's suggestion).

As the implementation changed, I ended up rewriting some parts of
the log message originally proposed and here is what I tentatively
queued.

-- >8 --
From: Christopher Warrington <chwarr@microsoft.com>
Subject: [PATCH] bisect: allow CRLF line endings in "git bisect replay" input

We advertise that the bisect log can be corrected in your editor
before being fed to "git bisect replay", but some editors may
turn the line endings to CRLF.

Update the parser of the input lines so that the CR at the end of
the line gets ignored.

Were anyone to intentionally be using terms/revs with embedded CRs,
replaying such bisects will no longer work with this change. I suspect
that this is incredibly rare.

Signed-off-by: Christopher Warrington <chwarr@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-bisect.sh               | 2 ++
 t/t6030-bisect-porcelain.sh | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/git-bisect.sh b/git-bisect.sh
index efee12b8b1..56548d4be7 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -209,6 +209,7 @@ bisect_replay () {
 	test "$#" -eq 1 || die "$(gettext "No logfile given")"
 	test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")"
 	git bisect--helper --bisect-reset || exit
+	oIFS="$IFS" IFS="$IFS:$(printf '\015')"
 	while read git bisect command rev
 	do
 		test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue
@@ -232,6 +233,7 @@ bisect_replay () {
 			die "$(gettext "?? what are you talking about?")" ;;
 		esac
 	done <"$file"
+	IFS="$oIFS"
 	bisect_auto_next
 }
 
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 821a0c88cf..bb84c8a411 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -792,6 +792,13 @@ test_expect_success 'bisect replay with old and new' '
 	git bisect reset
 '
 
+test_expect_success 'bisect replay with CRLF log' '
+	append_cr <log_to_replay.txt >log_to_replay_crlf.txt &&
+	git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
+	grep "$HASH2 is the first new commit" bisect_result_crlf &&
+	git bisect reset
+'
+
 test_expect_success 'bisect cannot mix old/new and good/bad' '
 	git bisect start &&
 	git bisect bad $HASH4 &&
-- 
2.26.2-561-g07d8ea56f2


  reply	other threads:[~2020-05-08 16:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 21:29 [PATCH] bisect: fix replay of CRLF logs Christopher Warrington via GitGitGadget
2020-05-07 22:13 ` Eric Sunshine
2020-05-07 22:25 ` Jeff King
2020-05-07 23:07   ` Junio C Hamano
2020-05-08 13:08     ` Jeff King
2020-05-08 15:07       ` Junio C Hamano
2020-05-08 16:28         ` Junio C Hamano [this message]
2020-05-08 17:12           ` Jeff King
2020-05-08 17:53             ` Junio C Hamano
2020-05-09 22:17             ` brian m. carlson
2020-05-10 10:54               ` Achim Gratz
2020-05-08 22:59           ` [EXTERNAL] " Christopher Warrington (CHRISTOPHER)
2020-05-09 16:28             ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=xmqq8si2z8zb.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=chwarr@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).