git-submodule.sh: shorten submodule SHA-1s using rev-parse
PATCH 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.
--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -850,8 +850,8 @@ 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) + sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst) if test $status = T then blob="$(gettext "blob")"
Signature · 1 line
2.20.1.dirty
Hi Sven,
Quoted 4 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.
Good point. Just one suggestion:
git-submodule.sh cmd_summary() { · line 853
Quoted 11 lines
git-submodule.sh +1
-2@@ -850,8 +850,8 @@ 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)
How about git -C "$name" rev-parse --short? That would less likely run over 80 columns/line, either.
Ciao,
Johannes
Quoted 8 lines
git-submodule.sh +1
-0+ sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst) if test $status = T then blob="$(gettext "blob")"Signature · 1 line
2.20.1.dirty
Quoted 4 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.
In general I think it is a good idea to scale as the repository grows by asking "rev-parse --short" to do the job.
One thing it is not clear to me is that this codepath is prepared to handle sha1_src and sha1_dst referring to an object that does not exist (i.e. $missing_(src|dst)=t); the original code will still give us 7 hexdigit to show on the headline, but does the updated code that uses "rev-parse --short" give us a reasonable output?
Quoted 21 lines
Signed-off-by Sven van Haastregt <[email protected]>--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)git-submodule.sh +2
-2@@ -850,8 +850,8 @@ 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) + sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst) if test $status = T then blob="$(gettext "blob")"
Quoted 4 lines · Johannes Schindelin
git-submodule.sh cmd_summary() { · line 853
Quoted 1 line
git-submodule.sh +1
-0+ sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src)How about
git -C "$name" rev-parse --short? That would less likely run over 80 columns/line, either.
That would be a separate patch, either as a preliminary or a follow-up. The existing code has too many of the same construct.
Quoted 5 lines · Junio C Hamano
One thing it is not clear to me is that this codepath is prepared to handle
sha1_srcandsha1_dstreferring to an object that does not exist (i.e. $missing_(src|dst)=t); the original code will still give us 7 hexdigit to show on the headline, but does the updated code that uses "rev-parse --short" give us a reasonable output?
Good point, I expect it will output an error message in that case. I suppose we can fallback to the old echo and cut if the object does not exist; I'll update the patch.
Quoted 16 lines
Quoted 15 lines
git-submodule.sh +2
-2@@ -850,8 +850,8 @@ 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) + sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst) if test $status = T then blob="$(gettext "blob")"
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
git-submodule.sh cmd_summary() { · line 853
Quoted 1 line
git-submodule.sh +1
-0+ sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src)How about
git -C "$name" rev-parse --short? That would less likely run over 80 columns/line, either.That would be a separate patch, either as a preliminary or a follow-up. The existing code has too many of the same construct.
It's also not the same; if $GIT_DIR is already set in the environment, that will override auto-discovery done after the chdir() triggered by "-C". It would need to be "git --git-dir".
Sincerely,
Somebody who has been bit by the distinction many times
Hi Peff,
Quoted 12 lines · Jeff King
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
git-submodule.sh cmd_summary() { · line 853
Quoted 1 line
git-submodule.sh +1
-0+ sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src)How about
git -C "$name" rev-parse --short? That would less likely run over 80 columns/line, either.That would be a separate patch, either as a preliminary or a follow-up. The existing code has too many of the same construct.
Quoted 6 lines
It's also not the same; if $GIT_DIR is already set in the environment, that will override auto-discovery done after the
chdir()triggered by "-C". It would need to be "git --git-dir".Sincerely,
Somebody who has been bit by the distinction many times
Ouch. Good point.
Thanks,
Dscho