* [PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse
@ 2019-01-27 19:27 Sven van Haastregt
2019-01-27 23:46 ` Eric Sunshine
0 siblings, 1 reply; 3+ messages in thread
From: Sven van Haastregt @ 2019-01-27 19:27 UTC (permalink / raw)
To: git; +Cc: Sven van Haastregt
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse
2019-01-27 19:27 [PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse Sven van Haastregt
@ 2019-01-27 23:46 ` Eric Sunshine
2019-01-28 2:33 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sunshine @ 2019-01-27 23:46 UTC (permalink / raw)
To: Sven van Haastregt; +Cc: Git List
On Sun, Jan 27, 2019 at 2:28 PM Sven van Haastregt <svenvh@gmail.com> wrote:
> 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>
> ---
> diff --git a/git-submodule.sh b/git-submodule.sh
> @@ -850,8 +850,16 @@ cmd_summary() {
> + # 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
This could be made a bit easier to follow by using indentation and ||
rather than &&. For instance, rewriting the entire block as:
# Shorten with hard-coded fallback if rev-parse fails
sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src ||
echo $sha1_src | cut -c1-7)
sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst ||
echo $sha1_dst | cut -c1-7)
In fact, the code is clear enough that the comment isn't even needed.
By the way, if git-rev-parse does fail, is it going to produce an
error message on stderr that needs to be suppressed?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse
2019-01-27 23:46 ` Eric Sunshine
@ 2019-01-28 2:33 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2019-01-28 2:33 UTC (permalink / raw)
To: Eric Sunshine; +Cc: Sven van Haastregt, Git List
Eric Sunshine <sunshine@sunshineco.com> writes:
> This could be made a bit easier to follow by using indentation and ||
> rather than &&. For instance, rewriting the entire block as:
>
> # Shorten with hard-coded fallback if rev-parse fails
> sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src ||
> echo $sha1_src | cut -c1-7)
> sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst ||
> echo $sha1_dst | cut -c1-7)
>
> In fact, the code is clear enough that the comment isn't even needed.
>
> By the way, if git-rev-parse does fail, is it going to produce an
> error message on stderr that needs to be suppressed?
All good points ;-).
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-28 2:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-27 19:27 [PATCH v2] git-submodule.sh: shorten submodule SHA-1s using rev-parse Sven van Haastregt
2019-01-27 23:46 ` Eric Sunshine
2019-01-28 2:33 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).