git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse
@ 2019-02-03 21:00 Sven van Haastregt
  2019-02-03 21:28 ` Eric Sunshine
  0 siblings, 1 reply; 4+ messages in thread
From: Sven van Haastregt @ 2019-02-03 21:00 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 always rely on 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 v2: Simplify code as suggested by Eric
Sunshine <sunshine@sunshineco.com> and suppress stderr.

 git-submodule.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 5e608f8bad..e26146e721 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -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")"
-- 
2.20.1.dirty


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse
  2019-02-03 21:00 [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse Sven van Haastregt
@ 2019-02-03 21:28 ` Eric Sunshine
  2019-02-04 18:47   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sunshine @ 2019-02-03 21:28 UTC (permalink / raw)
  To: Sven van Haastregt; +Cc: Git List

On Sun, Feb 3, 2019 at 4:01 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 always rely on successfully invoking `git rev-parse` in the
> submodule directory.  Keep the old method using `cut` as 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.

> Signed-off-by: Sven van Haastregt <svenvh@gmail.com>
> ---
> Differences since v2: Simplify code as suggested by Eric
> Sunshine <sunshine@sunshineco.com> and suppress stderr.

This version looks better. Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse
  2019-02-03 21:28 ` Eric Sunshine
@ 2019-02-04 18:47   ` Junio C Hamano
  2019-02-04 19:01     ` Eric Sunshine
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2019-02-04 18:47 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Sven van Haastregt, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Sun, Feb 3, 2019 at 4:01 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 always rely on successfully invoking `git rev-parse` in the
>> submodule directory.  Keep the old method using `cut` as 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.

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?


>
>> Signed-off-by: Sven van Haastregt <svenvh@gmail.com>
>> ---
>> Differences since v2: Simplify code as suggested by Eric
>> Sunshine <sunshine@sunshineco.com> and suppress stderr.
>
> This version looks better. Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse
  2019-02-04 18:47   ` Junio C Hamano
@ 2019-02-04 19:01     ` Eric Sunshine
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Sunshine @ 2019-02-04 19:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sven van Haastregt, Git List

On Mon, Feb 4, 2019 at 1:47 PM Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > On Sun, Feb 3, 2019 at 4:01 PM Sven van Haastregt <svenvh@gmail.com> wrote:
> >> We cannot always rely on successfully invoking `git rev-parse` in the
> >> submodule directory.  Keep the old method using `cut` as 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.
>
> 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?

That's better.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-04 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-03 21:00 [PATCH v3] git-submodule.sh: shorten submodule SHA-1s using rev-parse Sven van Haastregt
2019-02-03 21:28 ` Eric Sunshine
2019-02-04 18:47   ` Junio C Hamano
2019-02-04 19:01     ` Eric Sunshine

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).