From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30889 invoked from network); 13 Apr 2022 04:42:48 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Apr 2022 04:42:48 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649824968; b=ox7JSVPr0/4SnU3i5WXmYE2pkFbvJAwOS6P0vFIw9ihHGbN/jSHawFlo3tq+FU3PAlTllpfrnE OPNvt5VEul+lLGhajYgiJEcc2W+vnOzgMAw+YkJAandJTirfqTNWSWos442i1tZc42dvs7ekvm /ug2jWrHPTs6aVLKMHN8cY7+f/W1yh2YB2SiD926BR9TSIu0i+h77VnCsH+C62szVJM+IQllZa JaIpNL4f4eWM144k6YxyIxibSHPTxMnd4npc+l4O7RPD9ZapKvKZXAgQTS/sgkxaPjZZGpPjp/ SdKFpmGWAWT5je9at4/rvsEheXnWlcbPUl4windk/6u9NA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yw1-f171.google.com) smtp.remote-ip=209.85.128.171; dkim=pass header.d=shopify.com header.s=google header.a=rsa-sha256; dmarc=pass header.from=shopify.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1649824968; bh=A7BcvTyT0HUzLfdSlAyX1+ys+UGw4MLk14SuazCahTI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=F7YCU1QTfFWgzHzTPYVn4NghX8D+66Ct/AhN1i+toRkbEBwkOrDK8QKFVQcxuhw8yysQaV3HDD TWjXHr36GDD9MDLzsWhIszp7pZBXHEzn6ZvBkO1XWilkq2CL8+3STFBmdzlfdh6hhD1emSJoYE Q/C1MxmlLfJV/c6srgjQvFNuvEsAEMVllX2q8Xul8r+j6K04+uv6AV89dFU4+OGdQoUJYgYyU7 gCU1ksftJzs82hN+o3BnYdt+t3wYppFA9Ju9IUhw04mXVlagGAkBcJmSA/CMibqPeXxVlsFYH9 INrfJGYI7uvEu54lsXusCB4mU2MKeMEnjxdGIzLe/ltpow==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=b/Fi02lqBqQkaBqsCe4Z7z+skjBK3eIC6FoyLjRTnrQ=; b=asLBNWtDIoR6cRwvrjjZLRUAdG o7KuZ46M6eQLslQZNTWoJ+BpJ9Rt1QkC1Tno541QIviqwVNnLCopmpgL2ekhjJG7nAv0DaUZ0SVSN NCgZ/9NDAjBSddMjnAXltV4VVFD88SgzANG0Sf++FWLnZKdzaGtwcv+OxEctm94Hnx9WfykchEaKI ErrIShoIuKlgzbOKALxefiNmHieSQNB6ex/IrOqBbtoQb+py3adSeGnTZXNb17yOQzqQd4eR71nz+ XLIHtA9xmaM/MlF/9WKGyEm5n/RTJVew8QFUaBpwWzz6vXk2yxRuLVQNLEyFeyXyvY0yEjhgsBoDj QXqp8HbQ==; Received: from authenticated user by zero.zsh.org with local id 1neUq6-000FHP-9y; Wed, 13 Apr 2022 04:42:46 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yw1-f171.google.com) smtp.remote-ip=209.85.128.171; dkim=pass header.d=shopify.com header.s=google header.a=rsa-sha256; dmarc=pass header.from=shopify.com; arc=none Received: from mail-yw1-f171.google.com ([209.85.128.171]:45498) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1neUpS-000EwP-TD; Wed, 13 Apr 2022 04:42:07 +0000 Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-2ec04a2ebadso9357397b3.12 for ; Tue, 12 Apr 2022 21:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopify.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=b/Fi02lqBqQkaBqsCe4Z7z+skjBK3eIC6FoyLjRTnrQ=; b=g/mGGyqF9h4wq65uu/vPCKK/mZtrgRTXmnVlZ5Snze4qRk4h1sqAY4Bx2EIb3a6BMD OJuavK8kA4owshI7uWKzHYfabRIFR6w3S0ENEaGiu665vq2N/GWsWNNNh5wsUes+Y4Eo pXZYchA+bs13xIQUL41+ym4MCa3Ulny/7g80I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=b/Fi02lqBqQkaBqsCe4Z7z+skjBK3eIC6FoyLjRTnrQ=; b=OOpHJFY46lGv1AYcQ1+LRlLWGdEU7O94/fnAmzYtuWnVk1Act/rCbGnoAfnE8Mh9VY D3JyHoPEbGYcA2ggO8HBzGpER4LMFpXnle6k5b7Oc7voPDC/UntVJ2uaVOU+X666g9C1 7VTdCyNiIpnfFQSS2I3/1pUliE3232xh++9lrjFbLWfFKnbEuWk+apKjcZax8DHVBM9p EgkvYeddpW1ay36QDNEk/eCLMm+1n1CV0DCFydRfoVRdR1my/OXHFNv6sMGLi66A8Bzi yLsfjXgQpP7kGkFseoYQugb5/A+pOL+V5tpZkedosWXm8ON7o6O3pW+CkaQ/1gRTQPKS foOg== X-Gm-Message-State: AOAM531oD+KQdSfVu10BG71wtq3K1o4JgVR1qF2WxucVDYypMIlJiB9U pT5ROyEZqCJq0TK+rzuc+8uH9wykefT3cOh3+1QYMOBy3KpcqvcB X-Google-Smtp-Source: ABdhPJwM4EHt6nhk4brYhEZ+UgEGg5YbEzUUmbjdFTZPPVIGPb4PahXMQhKwLn4LZThPCagAduVd7vRl89SDx0caQlc= X-Received: by 2002:a05:690c:102:b0:2ef:48d8:24c3 with SMTP id bd2-20020a05690c010200b002ef48d824c3mr885098ywb.153.1649824925165; Tue, 12 Apr 2022 21:42:05 -0700 (PDT) MIME-Version: 1.0 From: Sam Bostock Date: Tue, 12 Apr 2022 22:41:46 -0600 Message-ID: Subject: [PATCH] Abbreviate commit hash in prompt during git rebase To: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="0000000000009b4afb05dc81ccb4" X-Seq: 50053 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --0000000000009b4afb05dc81ccb4 Content-Type: text/plain; charset="UTF-8" Hi! First time contributor here; hopefully I have appropriately formatted this! Please find the description of the change below. I don't have an environment setup to test this, but the following proof of concept works: # Typical case % msg="pick $(git rev-parse origin/master) wrong subject" % echo $msg pick 06e5ec914fdedac6446e02c9427a1706dda9c505 wrong subject % echo $(git log -1 --pretty=format:'%h %s' $msg[(w)2]) 06e5ec914 50013: skip %test if a chunk in %prep fails # Edge case mentioned in old comments for git 2.19.0 % msg="pick $(git rev-parse origin/master)" % echo $msg pick 06e5ec914fdedac6446e02c9427a1706dda9c505 % echo $(git log -1 --pretty=format:'%h %s' $msg[(w)2]) 06e5ec914 50013: skip %test if a chunk in %prep fails # Edge case mentioned in old comments for git 2.11.0 % msg="pick $(git rev-parse origin/master) $(git rev-parse --short origin/master)" % echo $msg pick 06e5ec914fdedac6446e02c9427a1706dda9c505 06e5ec914 % echo $(git log -1 --pretty=format:'%h %s' $msg[(w)2]) 06e5ec914 50013: skip %test if a chunk in %prep fails I copied the use of `${vcs_comm[cmd]}` from elsewhere in the file to invoke `git`. - Sam The full commit hash is quite long to be included in a prompt. Given it is unlikely that the hashes from the prompt need long term uniqueness, we can display the abbreviated hash instead. If, for some reason, the user wants the full hash, they can set the git's `core.abbrev` config. Ths change also allows us to reliably display the commit subject, even in the edge cases where it is not present in the `.git/rebase-merge/done` file. https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreabbrev --- .../VCS_Info/Backends/VCS_INFO_get_data_git | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index e45eebc8e..dd9c40ab4 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -209,27 +209,15 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then return 0 ;; (''(p|pick|e|edit|r|reword|f|fixup|s|squash)' '*) - # The line is of the form "pick $hash $subject". - # Just strip the verb and we're good to go. - p=${p#* } + # Typically, the line is of the form "pick $longhash $subject\n". # Special case: in an interactive rebase, if the user wrote "p $shorthash\n" # in the editor (without a description after the hash), then the .../done # file will contain "p $longhash $shorthash\n" (git 2.11.0) or "pick $longhash\n" # (git 2.19.0). - if [[ $p != *\ * ]]; then - # The line is of the form "pick $longhash\n" - # - # Mark the log message subject as unknown. - # TODO: Can we performantly obtain the subject? - p+=" ?" - elif (( ${#${p//[^ ]}} == 1 )) && [[ ${p%% *} == ${p#* }* ]]; then - # The line is of the form "p $longhash $shorthash\n" - # - # The shorthash is superfluous, so discard it, and mark - # the log message subject as unknown. - # TODO: Can we performantly obtain the subject? - p="${p%% *} ?" - fi + # Given we don't reliably have the subject, and the full hash is needlessly long + # for a prompt, we simply extract the hash (second word) and delegate to git to + # format it as "$shorthash $subject" according to git's hash abbreviation config. + p=$(${vcs_comm[cmd]} log -1 --pretty=format:'%h %s' $p[(w)2]) ;; (''(x|exec) *) # The line is of the form 'exec foo bar baz' where 'foo bar -- 2.35.1 --0000000000009b4afb05dc81ccb4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

First time contributor here; hopefully I have a= ppropriately formatted this!

Please find the description of the chan= ge below.

I don't have an environment setup to test this, but th= e following proof of concept works:

# Typical case
% msg=3D"= pick $(git rev-parse origin/master) wrong subject"
% echo $msg =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0
pick 06e5ec914fdedac6446e02c9427a1706dda9c505 wrong subject% echo $(git log -1 --pretty=3Dformat:'%h %s' $msg[(w)2]) =C2=A0<= br>06e5ec914 50013: skip %test if a chunk in %prep fails

# Edge case= mentioned in old comments for git 2.19.0
% msg=3D"pick $(git rev-p= arse origin/master)" =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<= br>% echo $msg =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0
pick 06e5ec914fdedac6446e02c9427a1706dda9c50= 5
% echo $(git log -1 --pretty=3Dformat:'%h %s' $msg[(w)2])
0= 6e5ec914 50013: skip %test if a chunk in %prep fails

# Edge case men= tioned in old comments for git 2.11.0
% msg=3D"pick $(git rev-parse= origin/master) $(git rev-parse --short origin/master)"
% echo $msg= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0
pick 06e5ec914fdedac6446e02c9427a1706dda9c505 0= 6e5ec914
% echo $(git log -1 --pretty=3Dformat:'%h %s' $msg[(w)2= ]) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
06e5ec914 50013: skip %test if= a chunk in %prep fails

I copied the use of `${vcs_comm[cmd]}` from = elsewhere in the file to invoke `git`.

- Sam



The full= commit hash is quite long to be included in a prompt.
Given it is unlik= ely that the hashes from the prompt need long term uniqueness,
we can di= splay the abbreviated hash instead.

If, for some reason, the user wa= nts the full hash, they can set the git's
`core.abbrev` config.
<= br>Ths change also allows us to reliably display the commit subject, even i= n the
edge cases where it is not present in the `.git/rebase-merge/done`= file.

https://git-scm.com/docs/git-config#Documentatio= n/git-config.txt-coreabbrev
---
=C2=A0.../VCS_Info/Backends/VCS_I= NFO_get_data_git =C2=A0 | 22 +++++--------------
=C2=A01 file changed, 5= insertions(+), 17 deletions(-)

diff --git a/Functions/VCS_Info/Back= ends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_= git
index e45eebc8e..dd9c40ab4 100644
--- a/Functions/VCS_Info/Backen= ds/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_= data_git
@@ -209,27 +209,15 @@ elif [[ -d "${gitdir}/rebase-merge&q= uot; ]]; then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0return 0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0;;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(''(p|p= ick|e|edit|r|reword|f|fixup|s|squash)' '*)
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# The line is of the form "pick = $hash $subject".
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0# Just strip the verb and we're good to go.
- =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p=3D${p#* }
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Typically, the line is of the form = "pick $longhash $subject\n".
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Special case: in an interactive rebase, if= the user wrote "p $shorthash\n"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# in the editor (without a description af= ter the hash), then the .../done
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0# file will contain "p $longhash $shorthash\n&= quot; (git 2.11.0) or "pick $longhash\n"
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# (git 2.19.0).
- =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if [[ $p !=3D *\ * ]]; then
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0# The line is of the form "pick $longhash\n"
- =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0#
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0# Mark the log message subject as unknown.
- =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0# TODO: Can we performantly obtain the subject?
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p+=3D&quo= t; ?"
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0elif= (( ${#${p//[^ ]}} =3D=3D 1 )) && [[ ${p%% *} =3D=3D ${p#* }* ]]; t= hen
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0# The line is of the form "p $longhash $shorthash\n&q= uot;
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0#
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# The shorthash is superfluous, so disca= rd it, and mark
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# the log message subject as unknown.
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0# TODO: Can we performantly obtain the subject?
- =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p= =3D"${p%% *} ?"
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0fi
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0# Given we don't reliably have the subject, and the full hash is nee= dlessly long
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# = for a prompt, we simply extract the hash (second word) and delegate to git = to
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# format it = as "$shorthash $subject" according to git's hash abbreviation= config.
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p=3D$(= ${vcs_comm[cmd]} log -1 --pretty=3Dformat:'%h %s' $p[(w)2])
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;;
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(''(x|exec) *)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# The line is of the fo= rm 'exec foo bar baz' where 'foo bar
--
2.35.1
--0000000000009b4afb05dc81ccb4--