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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 17420 invoked from network); 17 Apr 2022 17:53:06 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 17 Apr 2022 17:53:06 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1650217986; b=oeOom8oQmq8+BtQMMXssNwyvkArxIbZrE61isb3uGsDdtsO5KM3SWuxvitLujMKQ7razE8+5+z pD8ctG5eXMkiQc5uKimpLCsKxGGl2h7+7FtiJlkZIpUEV39phCr8Yb0WsEnG9LOcBWjgQOMGY5 gn/rlMhGm2CqyrgLFSjGfwL8zqECGal/6dtBwlYEYZ5KHHVvi/LA1jCGIUoyFT06eEzECc6997 rkmwidbpra5JcMA/DULlrJqZf4YRycNHt/eYyrDV+5lfrIjazk7qaMee1presQOVfhuJKQo5UF nx2DOxQj9DGPabG0dm0HoELXNYGKvYZxsctUO/4w+7h1LA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1650217986; bh=yfypo5vduILZiv1LXTAmTkzeFAqWKwlxbMWDQyPuKsk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=oZ1lvxpTpgVH2H/78HAudT+W7tseQgCeIZhk2jpCBLOuOjmthUdeNwGj+LNlUVRamQJqm5BMtS ZqzI0GVok1pHIeNhzpc4xcHlSsAGH/0zJRgpG1Q5nfSHhLJwozjA6Eps5/ZOEShlxsvUkYVr59 xZYY9Cb0X1/XWpoZbKaJKWoR4PRl7BJCqhzUGjTI8Phd4xhEqhVx+kTERE39aHeVzObhRKnVMu PTu3kHfLbojkei2IQJ11q/ltG7Qx2qyM4viabKKKtngGMQnl46jR2GnR4XRq36cs1ysikRtDnQ ROfmp1hslhp9Rmigj1wDrqk1+dlvSPhV6y1TZwM1jTuswQ==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=hGKNIiywbbcs9WwuNj92bOcYysaWC69Vxl/y34EktKI=; b=NT7r5q3jQu/k2Bi28WFSO+ztp3 6B5/QkVxs8UFH8pYGpMIoF0Lr1bxBAx/kEUZocyE/C3f+yPubNJ4SzKXUWOEFEcMd7AsJvLXGw5Ac VydqgHLZhOAZFgQ1Bm7y/FmgWUk9VFVmAvcuDHZK9AiLugGKpZbtE7jJLa1PPPqWf+KqCmKNel4HZ SH30LrDD35h58DkgXEPk4voY9pFpwDbPvc8FH7PDA32Kqufv8/Pv72o9IKJh1SAfBQzUSPV+avhTG 7R2ZS5rRTYSi0z0p/eJkFoCYqGEm6N8ZdY0uJUIwiOKhcnrH5YSjNfP1/3vG22iO0O8oIHhf2imNA 5SYLmtrg==; Received: from authenticated user by zero.zsh.org with local id 1ng957-000EEB-M5; Sun, 17 Apr 2022 17:53:05 +0000 Authentication-Results: zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out5-smtp.messagingengine.com ([66.111.4.29]:45365) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ng94a-000DvS-Ei; Sun, 17 Apr 2022 17:52:33 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 221305C011A; Sun, 17 Apr 2022 13:52:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 17 Apr 2022 13:52:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1650217951; x=1650304351; bh=hGKNIiywbb cs9WwuNj92bOcYysaWC69Vxl/y34EktKI=; b=X79RDF/GxryzN/KTOS/EzsLy54 lfdlZcSfr8aBkw/SAGJay9bRBd8cGRybWyUT+rCYtvDdSVLLP/n1xLLln1gOQXLx v9gDuKWW0+ClkAbIrtopZAw6KoXiZxe4WU7B01EQYOpvhwMx8EKmSCB74+heTdm0 PyLSpr0i4he/yD03FdEiJ/7ChoO4QroMLPgpn8VoySLISFtlFqWTDf7xLg+2q8qh ztpkCVyIkEUk1+/GgfPhbFPbUhblb6R4wCcFuHwWyl2FOltSmPrJV8gbJklTdW6U Y2NyeSPSOG/UKOQXEvALsHgbYIJ7tjuduD45BPgddihJJzf01S5vDz+/wpjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1650217951; x=1650304351; bh=hGKNIiywbbcs9 WwuNj92bOcYysaWC69Vxl/y34EktKI=; b=KcJt6GFarG56YOE9GJTD+voTRZunU Oc9Ljse2sRHTs7ffWQIHxZQNYAttExIxIb5FZj6zM7Q0W99w+s6EhAT1Nw+W9uXq NE1IbdfhS4g/+AeCXgId9IKdcJ6A96XFY3V1iBphQjvdKNBRQH4pU5vWTH6BVNE9 TE4vp9LvAewEa8QmODV1ZVHQb1/D8qILcwSvf51XGGd19LWK+FKnJ2MTy07QAxy8 W+S3yPa6a3RKK/i8elVwbcGn/lvZVBodQyDSFzLWvQ375ro5bb4Q8Mj4yMQUkO8v VHBBl2TBDxf0TxI9oYnpt0MfdGEeYFyNyypIQaD8j5tUWJugfxBYuPLjA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelledguddvvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggugfgjfgesthektddttderjeenucfhrhhomhepffgr nhhivghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg eqnecuggftrfgrthhtvghrnhepueejuefgudeileejgfehleefvdevheehleduffefudet udehgeefvdfhieeihfevnecuffhomhgrihhnpeiishhhrdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhs hhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Apr 2022 13:52:30 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4KhHhX1yqFzpv; Sun, 17 Apr 2022 17:52:28 +0000 (UTC) Date: Sun, 17 Apr 2022 17:52:28 +0000 From: Daniel Shahaf To: Sam Bostock Cc: Lawrence =?iso-8859-1?Q?Vel=E1zquez?= , zsh-workers@zsh.org Subject: Re: [PATCH] Abbreviate commit hash in prompt during git rebase Message-ID: <20220417175228.GP27526@tarpaulin.shahaf.local2> References: <58222599-b634-401b-b70f-3e5fd5633839@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 50073 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: Sam Bostock wrote on Wed, Apr 13, 2022 at 13:53:40 -0600: > Hi Lawrence, > > Thanks for the reply! > Have you seen my previous reply to you, ? (For obvious reasons I'll re-send this question to you in a minute from another address of mine. Apologies in advance for the duplicate.) > 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. > The operative word here is "guarantee". If we truncate to, say, 12 hex digits, that's 48 bits (= 12 nibbles), so a repository would need to have 2**24 commits (≈ 16M) in order to have a ≈50% chance of having two commits with the same first 12 nibbles. (That's _commits_, not _objects_, since IIRC «d41d8cd^{commit}» v. «d41d8cd^{blob}» is a valid way to disambiguate.) Only the largest/oldest projects would have history DAGs this large.¹ And if we truncate "too soon" and the resulting hash is ambiguous, then what? Would that be a problem? - It wouldn't break the use-case of looking at the prompt after «git commit» or «git rebase --continue» to confirm the command worked. - It wouldn't break the use-case of reviewing the scrollback and knowing what the state was before each command. - It _would_ break the use-case of copying the hash into the command line, because then git would error out about the ambiguous prefix. The workaround would be to extract the full hash from the reflogs or from rebase's todo list. This use-case is so common for me that I had my zshrc store the commit hash in a global variable so I can easily use it in interactive commands. (I do «typeset -g y=…» in zshrc and then «git show $y» interactively.) So, do we actually need to *guarantee* uniqueness? ¹ For instance, FreeBSD's ports repository, which started in 1994, has 0.6M commit objects (per «git rev-list --all --count») and autogenerates 12-nibble short hashes. (I didn't choose this repository because of this property; it's just a repository I happened to have handy.) > Given we're already in somewhat of an edge case (rebase in progress), is > the penalty still a problem? > I don't consider rebases an edge case, so, "Yes.". > 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? > Every time. Cheers, Daniel > Sam > > > On Tue., Apr. 12, 2022, 11:38 p.m. Lawrence Velázquez, > 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=${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 > > > > 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 > >