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=-2.3 required=5.0 tests=DATE_IN_PAST_03_06, 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 29308 invoked from network); 14 Apr 2022 01:43:16 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Apr 2022 01:43:16 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649900596; b=ofx/fQno9bBf2ABMCGG0SeAMOwjdC4vsYCnNN3KKZ9lSnzg8A6ZnNRZRJG+PrAcrXDQKX+3unG zEeTceVxScTpimFADoMiv3NxbFZPBQKmEped52Gus9fMeKbOeUKSv6yqlkuG2i+a2/Horhn+7N FTOYVvGUk4R0a/uGejb6vkLLB5OI/s9CAR/FXoAO5VGkXxwHeYiVnsbeyF737S8utgIKXa/MpO bOB5Pw9CebRccZjBlzEsomE0I+jz8g5PuSLlbpW1hc2ijFwpQs3Je/EUFDFVJRcwhgqznqMOWX gR8tPs+Qlbp4K5zu6ehqFTPzqlpN3IxQL27VsWjIrIcM7Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f46.google.com) smtp.remote-ip=209.85.210.46; 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=1649900596; bh=WyJLFWm8bzdTTixI9oXoIjIba5/gwRR37KyFp1Pp+lA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=rGJ8W7l+X+kKJgCCrnR/A0hHOi8FBHXVw34nAEoS2SmJonRwHfmt1ylITootRQayLEPigkPF6y CUQqrmekwJI5jpHJ+rjkdM09eukxjI3yos/6mXR5oOW5VFMiFdKpac0gZ0e0u7rhQVUsB99Yec eojSZrGw9j+FdgSpECktnS58/MKVAO2o43ZpVacddPq9VnVQkFYS1MdWvyRNv7t8OQddGD7no/ 8hTrEkog5iQI5gWc3lyk12cl2mfHkprmkIm508vtbhD880noQjOzYhAg5UH02aTjg6T2mNq4Iw yUE4cIaN9iu+Xs5UoWqGZiSxlPlbjpilYduazQ01LJlSDA==; 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:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=xhai6YIAuiQTZCFVpexyyhHlKnrzmzpYWUiotn+CBf0=; b=BEUnnIkXaBip9SjNCJyg670Mna fuin9/K7ssAZ7wewyVm2JfRJyS2inEzdo6WstznUDL3jQN47QWSLV41sE6hGnSDnOtlGnoTWxwUvQ q8BsJSCPiBCpp16nNRyBb3sqLtsEBBvihEDKdSGItmd3/MvvXUtHj1pfj3W4Y1Rh3rve8jOpS86BV uPjVEFQKbm0DlgLW08dyaWWx6iOzLRYAZrbkPCmC9ZqEDOf513k/rE4m/wsomHmQw2VtHUiyh647s /zAOPpTSlxveFLQ7nvSIaFOintL/VC2rYHBZBqIPEr+buklXFWJF+FMef97df9T3CybagNm2JrCd+ qQlRGGlw==; Received: from authenticated user by zero.zsh.org with local id 1neoVw-000Cvh-8X; Thu, 14 Apr 2022 01:43:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f46.google.com) smtp.remote-ip=209.85.210.46; dkim=pass header.d=shopify.com header.s=google header.a=rsa-sha256; dmarc=pass header.from=shopify.com; arc=none Received: from mail-ot1-f46.google.com ([209.85.210.46]:44595) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1neoVR-000Cal-SQ; Thu, 14 Apr 2022 01:42:47 +0000 Received: by mail-ot1-f46.google.com with SMTP id m16-20020a9d73d0000000b005f8edc0599eso698757otk.11 for ; Wed, 13 Apr 2022 18:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopify.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xhai6YIAuiQTZCFVpexyyhHlKnrzmzpYWUiotn+CBf0=; b=hjAWJOTkvDrbkg1eswFljnpGr7qiNgqODKIzLmm7GVVBvCNXF/qVr3UYe8PMP83Fvj z4n0XNekzgm3eebMvZfmhO1Y9g3yI4ADG1CiVCfbBcqTA5Z783N//kZ0Y0cBYsYjtyop et0pF0zGbBieH/MGWq0+Ak7ShJCevFfARyAIo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xhai6YIAuiQTZCFVpexyyhHlKnrzmzpYWUiotn+CBf0=; b=rSb1xqSY79VxhP7RvgykBYMCVLIqoNymmQsEfBq5MtPht4PgKz4qz/VGHssc1wLfb4 gCrG3cAG8b2zxcYi2eneAHTITfmi/5KUlpWTJ9Rt/ANz9isJ/Q+Nq0SNsYcmJ1nHbJ8W 9pWi4jLuI7AHxa7KZu0z7IQoMqMxzSTT9lcFs7+GSVU986QFHQ0trhWDtikyvUIJyYfp hXz/7Hv6cmkA0aSbMzOxHGvmH41y9FSPFuEIlGuFtDj0bOJyKiHZj3fR1f1FN/E+H4vU KT/Lmpmzk8EEmrWPDSXINWF/5Q2ayedBbGwLAS8hoNvXhRrqX90Zq+x8ZimGTINdYrlm Mt0g== X-Gm-Message-State: AOAM530xLM9WcfP7VMd+c7+y1L1AOy7t16ZbQhn5Tyy+tFzv/fzT7KsF XmtobiA1qEIQ+Bz+YPMOwE3Lefu9EFQkVB4PpKPfk7TNbA6iTg== X-Google-Smtp-Source: ABdhPJxwzJq52OG/tZbefJZxPabdQJ13yqlmCivycErtQlyhRvIw5zTRdirKXM58Nl4BOFQ06PDsz4TTZf5JhGpdyl8= X-Received: by 2002:a81:9c48:0:b0:2ed:7f5b:84fa with SMTP id n8-20020a819c48000000b002ed7f5b84famr435610ywa.511.1649879632510; Wed, 13 Apr 2022 12:53:52 -0700 (PDT) MIME-Version: 1.0 References: <58222599-b634-401b-b70f-3e5fd5633839@www.fastmail.com> In-Reply-To: <58222599-b634-401b-b70f-3e5fd5633839@www.fastmail.com> From: Sam Bostock Date: Wed, 13 Apr 2022 13:53:40 -0600 Message-ID: Subject: Re: [PATCH] Abbreviate commit hash in prompt during git rebase To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="0000000000006b221405dc8e89b4" X-Seq: 50058 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: --0000000000006b221405dc8e89b4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Lawrence, Thanks for the reply! Git's abbreviation mechanism ensures uniqueness, rather than strictly truncating. If I'm not mistaken, the core.abbrev setting is effectively just a minimum for how many characters to include, with git including as many additional characters as required to avoid colliding with another object in the repository. I believe the default is determined using a heuristic based on the number objects in the repository. So we could make it a setting and do truncation ourselves, but then we'd be displaying a value without uniqueness guarantees. Given we're already in somewhat of an edge case (rebase in progress), is the penalty still a problem? Also, while I'm not familiar with the inner workings of vcs_info, I'm wondering if we recompute this every time the prompt is rendered, or if we lazily compute the values only when the rebase progresses? Sam On Tue., Apr. 12, 2022, 11:38 p.m. Lawrence Vel=C3=A1zquez, wrote: > Hi Sam, > > On Wed, Apr 13, 2022, at 12:41 AM, Sam Bostock wrote: > > First time contributor here > > Welcome! > > > 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=3D${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 !=3D *\ * ]]; 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+=3D" ?" > > - elif (( ${#${p//[^ ]}} =3D=3D 1 )) && [[ ${p%% *} =3D= =3D ${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=3D"${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=3D$(${vcs_comm[cmd]} log -1 --pretty=3Dformat:'%h %s= ' > > $p[(w)2]) > > ;; > > (''(x|exec) *) > > # The line is of the form 'exec foo bar baz' where > > 'foo bar > > It strikes me as a regression to run git if we already have the > subject; vcs_info is slow enough as it is. Could this be reserved > for the edge cases where we don't have the subject? > > (This would preclude what is arguably your primary goal, which is > using core.abbrev to choose between short and long hashes. But > that amounts to using git as a glorified string slicer. Perhaps > the choice could be determined by a style instead, and we could do > the truncation ourselves?) > > -- > vq > --0000000000006b221405dc8e89b4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Lawrence,

Thanks for the reply!

Git's abbreviation mechanism ensures uniqueness, rather than = strictly truncating. If I'm not mistaken, the core.abbrev setting is ef= fectively just a minimum for how many characters to include, with git inclu= ding as many additional characters as required to avoid colliding with anot= her object in the repository. I believe the default is determined using a h= euristic based on the number objects in the repository.

So we could make it a setting and do trunca= tion ourselves, but then we'd be displaying a value without uniqueness = guarantees.

Given we'= ;re already in somewhat of an edge case (rebase in progress), is the penalt= y still a problem?

Also,= while I'm not familiar with the inner workings of vcs_info, I'm wo= ndering if we recompute this every time the prompt is rendered, or if we la= zily compute the values only when the rebase progresses?

Sam


On Tue., Apr. 12, 2022, 11:38 p.m. Lawrence Vel=C3=A1zq= uez, <larryv@zsh.org> wrote:
= Hi Sam,

On Wed, Apr 13, 2022, at 12:41 AM, Sam Bostock wrote:
> First time contributor here

Welcome!

> 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
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 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|pick|e|e= dit|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=A0 p=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 # Specia= l 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 after the
> hash), then the .../done
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # file w= ill contain "p $longhash $shorthash\n" (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=A0 if [[ $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=A0 p+=3D" ?"
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 elif (( ${#${= p//[^ ]}} =3D=3D 1 )) && [[ ${p%% *} =3D=3D ${p#*
> }* ]]; 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 "p $longhash
> $shorthash\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 # The shorthash is superfluous, so discard 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=A0 p=3D"${p%% *} ?"
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fi
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Given we do= n't reliably have the subject, and the
> full hash is needlessly long
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # for a promp= t, 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 a= s "$shorthash $subject" according to
> git's hash abbreviation config.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 p=3D$(${vcs_c= omm[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 li= ne is of the form 'exec foo bar baz' where
> 'foo bar

It strikes me as a regression to run git if we already have the
subject; vcs_info is slow enough as it is.=C2=A0 Could this be reserved
for the edge cases where we don't have the subject?

(This would preclude what is arguably your primary goal, which is
using core.abbrev to choose between short and long hashes.=C2=A0 But
that amounts to using git as a glorified string slicer.=C2=A0 Perhaps
the choice could be determined by a style instead, and we could do
the truncation ourselves?)

--
vq
--0000000000006b221405dc8e89b4--