git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] git-rebase--interactive.sh: replace cut with ${v%% *}

From
Chris Johnsen <chris_johnsen@pobox.com>
Date
Sep 17, 2010, 21:42 UTC
Message-ID
<0eafa42f1da5f66465a1eb9da170416363cf72e0.1284759770.git.chris_johnsen@pobox.com>
In-Reply-To
<7vsk182p2q.fsf@alter.siamese.dyndns.org>

Some versions of cut do not cope well with lines that do not end in an LF. In this case, we can completely avoid cut by using the ${var%% *} parameter expansion (suggested by Brandon Casey).

I found this problem when t3404's "avoid unnecessary reset" failed due to the "rebase -i" not avoiding updating the tested timestamp.

On a Mac OS X 10.4.11 system:
    % printf '%s' 'foo bar' | /usr/bin/cut -d ' ' -f 1
    cut: stdin: Illegal byte sequence
Signed-off-by: Chris Johnsen <chris_johnsen@pobox.com>
---
Brandon Casey wrote:
Show 5 quoted lines
> Or we could write it like:
>
>    sha1=${rest%% *}
>
> Does the above work on your FreeBSD system?

Yes, as Junio points out, ${var%% *} is portable enough for Git. After this change t3404 passes here without GNU cut available.

Junio C Hamano wrote:
> Agreed; the less use of 'cut' we see, the better ;-)
It seems like the other uses of cut in git-rebase--interactive.sh
would be more awkward if they were replaced with equivalent
processing done in-shell with parameter expansions. Eliminating them
should probably wait until after 1.7.3, if at all.
---
 git-rebase--interactive.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index eb2dff5..a27952d 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -626,7 +626,7 @@ skip_unnecessary_picks () {
 		case "$fd,$command" in
 		3,pick|3,p)
 			# pick a commit whose parent is current $ONTO -> skip
-			sha1=$(printf '%s' "$rest" | cut -d ' ' -f 1)
+			sha1=${rest%% *}
 			case "$(git rev-parse --verify --quiet "$sha1"^)" in
 			"$ONTO"*)
 				ONTO=$sha1
-- 
1.7.3.rc2
Previous: Brandon CaseyNext: Junio C Hamano
Message 5 of 7 in “git-rebase--interactive.sh: LF terminate line sent to cut”
  1. git-rebase--interactive.sh: LF terminate line sent to cutChris Johnsen, Sep 17, 2010
  2. Brandon CaseySep 17, 2010
  3. Junio C HamanoSep 17, 2010
  4. Brandon CaseySep 17, 2010
  5. git-rebase--interactive.sh: replace cut with ${v%% *}Chris Johnsen, Sep 17, 2010
  6. Junio C HamanoSep 17, 2010
  7. Chris JohnsenSep 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.