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

[PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse

From
Sven van Haastregt <svenvh@gmail.com>
Date
Jan 27, 2019, 19:27 UTC
Message-ID
<20190127192740.8678-1-svenvh@gmail.com>

Until now, `git submodule summary` was always emitting 7-character SHA-1s that have a higher chance of being ambiguous for larger repositories. Use `git rev-parse --short` instead, which will determine suitable short SHA-1 lengths.

We cannot rely on always successfully invoking `git rev-parse` in the submodule directory. Keep the old method using `cut` as a fallback.

Signed-off-by: Sven van Haastregt <svenvh@gmail.com>
---
Differences since v1: Keep the old method using `cut` as a fallback.
 git-submodule.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/git-submodule.sh b/git-submodule.sh
index 5e608f8bad..5bd724e63b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -850,8 +850,16 @@ cmd_summary() {
 			;;
 		esac
 
+		# Ensure we have crudely abbreviated SHA-1s as fallback in case
+		# rev-parse fails to shorten the SHA-1s.
 		sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
 		sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
+
+		sha1_abbrev=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src) &&
+		sha1_abbr_src=$sha1_abbrev
+		sha1_abbrev=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst) &&
+		sha1_abbr_dst=$sha1_abbrev
+
 		if test $status = T
 		then
 			blob="$(gettext "blob")"
-- 
2.20.1.dirty
Next: Eric Sunshine
Message 1 of 3 in “git-submodule.sh: shorten submodule SHA-1s using rev-parse”
  1. git-submodule.sh: shorten submodule SHA-1s using rev-parseSven van Haastregt, Jan 27, 2019
  2. Eric SunshineJan 27, 2019
  3. Junio C HamanoJan 28, 2019

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.