git-submodule.sh: shorten submodule SHA-1s using rev-parse
PATCH v3 1/1 git-submodule.sh: shorten submodule SHA-1s using rev-parse
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 always rely on successfully invoking git rev-parse in the submodule directory. Keep the old method using cut as a fallback.
---
Differences since v2: Simplify code as suggested by Eric Sunshine <[email protected]> and suppress stderr.
git-submodule.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
git-submodule.sh +5 -2
@@ -850,8 +850,11 @@ cmd_summary() { ;; esac - sha1_abbr_src=$(echo $sha1_src | cut -c1-7) - sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7) + sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src 2>/dev/null || + echo $sha1_src | cut -c1-7) + sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst 2>/dev/null || + echo $sha1_dst | cut -c1-7) + if test $status = T then blob="$(gettext "blob")"
Signature · 1 line
2.20.1.dirty
Quoted 7 lines · Sven van Haastregt
Until now,
git submodule summarywas always emitting 7-character SHA-1s that have a higher chance of being ambiguous for larger repositories. Usegit rev-parse --shortinstead, which will determine suitable short SHA-1 lengths.We cannot always rely on successfully invoking
git rev-parsein the submodule directory. Keep the old method usingcutas a fallback.
Reviewers and future readers of this patch are left in the dark regarding the circumstances in which git-rev-parse may fail in the submodule directory. It would be helpful for the commit message to explain this potential failure in enough detail for someone working in this area in the future to understand any implications of changes to this code.
Quoted 4 lines
Signed-off-by Sven van Haastregt <[email protected]>---
Differences since v2: Simplify code as suggested by Eric Sunshine <[email protected]> and suppress stderr.
This version looks better. Thanks.
Quoted 9 lines · Eric Sunshine
Quoted 7 lines · Sven van Haastregt
Until now,
git submodule summarywas always emitting 7-character SHA-1s that have a higher chance of being ambiguous for larger repositories. Usegit rev-parse --shortinstead, which will determine suitable short SHA-1 lengths.We cannot always rely on successfully invoking
git rev-parsein the submodule directory. Keep the old method usingcutas a fallback.
Quoted 6 lines
Reviewers and future readers of this patch are left in the dark regarding the circumstances in which git-rev-parse may fail in the submodule directory. It would be helpful for the commit message to explain this potential failure in enough detail for someone working in this area in the future to understand any implications of changes to this code.
Replace that problematic sentence with something like
As a submodule may not be initialized with "submodule init" or not cloned, git rev-parse may not work in it yet; as a fallback, use the original method of cutting at 7 hexdigits.
perhaps?
Quoted 7 lines
Quoted 5 lines
Signed-off-by Sven van Haastregt <[email protected]>---
Differences since v2: Simplify code as suggested by Eric Sunshine <[email protected]> and suppress stderr.This version looks better. Thanks.
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Eric Sunshine
Quoted 2 lines · Sven van Haastregt
We cannot always rely on successfully invoking
git rev-parsein the submodule directory. Keep the old method usingcutas a fallback.Reviewers and future readers of this patch are left in the dark regarding the circumstances in which git-rev-parse may fail in the submodule directory. It would be helpful for the commit message to explain this potential failure in enough detail for someone working in this area in the future to understand any implications of changes to this code.
Quoted 7 lines
Replace that problematic sentence with something like
As a submodule may not be initialized with "submodule init" or not cloned,
git rev-parsemay not work in it yet; as a fallback, use the original method of cutting at 7 hexdigits.perhaps?
That's better.