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

[PATCH 2/4] Fix cg-{diff,mkpatch} with HEAD^

From
PGPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Date
Sep 2, 2005, 10:31 UTC
Message-ID
<20050902103128.24918.77004.stgit@zion.home.lan>
In-Reply-To
<20050902103125.24918.905.stgit@zion.home.lan>
Supplying "HEAD^" to commit-id gives a failure; I saw this with the failure of:
$ cg-mkpatch -r HEAD^:HEAD

I wonder whether we should remove commit-id and switch to git-rev-parse entirely, but in the meanwhile, fix it.

The problems are two ones: *) there's an extra space at the end of the return string of cg-Xnormid.

Verify by running the command: echo "\"$normid\""

*) the space remotion in commit-id can remove only one space, and forgets that when calling git-cat-file -t.

Fixing either one is sufficient, but I've decided to fix both.

Also, when doing cg-diff -r HEAD^:HEAD, I've noticed that tree-id has the same problems, and fixed it too. I checked parent-id, and it's safe.

FIXME: I didn't add a testcase in the t/ directory.
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---
 cg-Xnormid |    4 +++-
 commit-id  |   13 +++++++++++--
 tree-id    |   13 +++++++++++--
 3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/cg-Xnormid b/cg-Xnormid
--- a/cg-Xnormid
+++ b/cg-Xnormid
@@ -11,6 +11,8 @@
 # 	short SHA1 (4 or more hex digits)
 #
 # Takes the ID to normalize and returns the normalized ID.
+# Output format:
+# 40 hex digits ID, followed by _one_ space, followed by the optional ID type.
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
@@ -19,7 +21,7 @@ id="$1"
 if [ "${id:(-1):1}" = "^" ]; then
 	# parent-id
 	id=$(commit-id "${id%^}") || exit 1
-	git-cat-file commit "$id" | awk '/^parent/{print $2," "};/^$/{exit}' || exit 1
+	git-cat-file commit "$id" | awk '/^parent/{print $2 " "};/^$/{exit}' || exit 1
 	exit
 fi
 
diff --git a/commit-id b/commit-id
--- a/commit-id
+++ b/commit-id
@@ -9,8 +9,17 @@
 
 id="$1"
 normid=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1
-type=${normid#* }; [ "$type" ] || type=$(git-cat-file -t "$normid")
-normid=${normid% *}
+# Trim beginning space; leave end one because it means we must get the type
+# ourselves.
+normid=${normid# }
+type=${normid#* }
+#Trim type.
+type=${type# }
+type=${type% }
+# Trim end space (and everything after the space) when passing to
+# git-cat-file
+normid=${normid%% *}
+[ "$type" ] || type=$(git-cat-file -t "$normid")
 
 if [ "$type" != "commit" ]; then
 	echo "Invalid commit id: $normid" >&2
diff --git a/tree-id b/tree-id
--- a/tree-id
+++ b/tree-id
@@ -7,8 +7,17 @@
 
 id="$1"
 normid=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1
-type=${normid#* }; [ "$type" ] || type=$(git-cat-file -t "$normid")
-normid=${normid% *}
+# Trim beginning space; leave end one because it means we must get the type
+# ourselves.
+normid=${normid# }
+type=${normid#* }
+#Trim type.
+type=${type# }
+type=${type% }
+# Trim end space (and everything after the space) when passing to
+# git-cat-file
+normid=${normid%% *}
+[ "$type" ] || type=$(git-cat-file -t "$normid")
 
 if [ "$type" = "commit" ]; then
 	normid=$(git-cat-file commit "$normid" | sed -e 's/tree //;q')
Previous: Paolo 'Blaisorblade' GiarrussoNext: Paolo 'Blaisorblade' Giarrusso
Message 2 of 6 in “Fix txt installation”
  1. 1/4 Fix txt installationPaolo 'Blaisorblade' Giarrusso, Sep 2, 2005
  2. 2/4 Fix cg-{diff,mkpatch} with HEAD^Paolo 'Blaisorblade' Giarrusso, Sep 2, 2005
  3. 3/4 commit-id micro cleanupPaolo 'Blaisorblade' Giarrusso, Sep 2, 2005
  4. 4/4 cg-{diff,mkpatch}: rename/copy optional detectionPaolo 'Blaisorblade' Giarrusso, Sep 2, 2005
  5. Petr BaudisSep 12, 2005
  6. BlaisorbladeSep 13, 2005

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.