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 27842 invoked from network); 14 Apr 2022 01:31:28 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Apr 2022 01:31:28 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649899888; b=jfpmDKfl0c9q1cjI/7HXTJDdOoHnjOm9Wt63+Js0eOERyEmLsF/D5jTiaVA+YyGIimk4q/HfoK Yc4g9yW2BqJTVBvOXQeOsnA7kSlZWRNM5U8tdLPfwNrsCwm2kdUL5Bub4X4ebxGvH6ppS/wR5/ NOAdxwMkP1bfHKWiIcf110ahty0RjmT7g4W8sPLZ4DIlFo/nQ1u7ynojvALmV0DWllwihrOfNW dD1zNWNx78yBogq8EN29stZtH0AJCk7Uonwq1UNcbPqce+aNdO6h7/uTXvPmDE9vZTW0okeNv8 BHeBbZ7RF+UfXsDbwQLPpwgvVXh9sTLCBCXN8BlxFhCSEw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; 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=1649899888; bh=p0ZfP1XGaj1Xu1029nuQEVQ8tSJnXfbZlMkSBH9ZOCM=; 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=q5D+W5nys7MXSaFhISix8OGcft8++kSqvxV/altY7svcLdAUTWUHsMsU5Bklfn7feM9xNGVSF3 BkywgN3Jn6qt2v1rf8+ivfQqm5eHWu4lzXZg8/WGXQOvnEE2VaRyKfKXOE4KeRLlb70feZBLgL Jj02/sH5wh18xJCUOMI1M0iLd5yg1BNQCNsTGvFvgabMb5ouBgqeOWGNEV47jCBYT3VBSy6P/H GAfO2cIbkd8nJ5vUXi6G6BoLuKxpHvQ+/0XpTxODsks10HDFcbRPRMW+LrGU6a1Yp0YcG0g9IB rbbPoUVXu1LgzZeR1D/ZVej58m+j24KDiSJA5uRMuJ2EQg==; 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=Bez4BwyNl/tBiyYfbd5uLuq0giu78+5e0eNTyhLuTMI=; b=RE+EdLRT/M4WHeSo7xlgZRIweq MCGdb6xmk1FNaBYOLexytrPHKP9tz5/vKY5hIOUk8nHZpOMW+bHrVwk6ejn8LoDg4XnFle3XWIneL V+/jZI0egbnVQqFujuiQVRQRk5kgMjYJuVmw7uAuJPVzNbVEVUEBXNm/yYYszT9haZc8b4V/UU8aA 6Zh5W7+kQa0ZnN2TH8C+BoVJzn3Gn7SsImh53anwpenpaknaE4WFboYOQ1iF1Hq+edkpDz3fwfwZp jWkYaVRNuPIBlwpRcxgxDf7R1O9RD5Rz9tR/vc7XPJbak1WxqXwgMJkHyBs5unJKtwenQf7ZbAd+Q xefAK3xA==; Received: from authenticated user by zero.zsh.org with local id 1neoKU-000C0i-J8; Thu, 14 Apr 2022 01:31:26 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; 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 out3-smtp.messagingengine.com ([66.111.4.27]:40511) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1neoJv-000Bhr-G7; Thu, 14 Apr 2022 01:30:53 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 128815C0153; Wed, 13 Apr 2022 18:03:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 13 Apr 2022 18:03:07 -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=1649887387; x=1649973787; bh=Bez4BwyNl/ tBiyYfbd5uLuq0giu78+5e0eNTyhLuTMI=; b=UIKX+xy+Y3X6GCJy+gtygToFV7 f51TmKiQGd4rpBwZlEoDcIFVF0NbtAHcb7fwoJZS+QvH6N7tdKWvrgijc4fOIWgk oUfV1UVruiE+TFxLq1KBCKcpmZHyVbuwoUF9CaGOvVPejBiWCNOTCQVx/sVGyIzt fxjOYeZWfr0ExVpv8C1+DAk16l8O41QHKROour5IDduG/CtY1OD1I/K4Gyg/c0sh mdjjMwV6qoX6yF6OlFaHMcCeS1Mw0xZV0FZBqF5zKfDh+KVZLoSKTdxzMxeb5z0X /mNfzcnUa9OrKymPZB2X0662Ucc6AoOlumZ5P+Z4qp0aAd8wio1bdNi5eFqQ== 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=1649887387; x=1649973787; bh=Bez4BwyNl/tBi yYfbd5uLuq0giu78+5e0eNTyhLuTMI=; b=r3QUFOpyGvbQipq73HbAEfwjMTpyL jWtwKY0f7QRWGNnsj7hupWqVR3Te1o8cFQC1M9MhEkMW19EHaeDrVJ6/gUitcr3v 4ZRGljakKY4Zr9FJjsj0LwhEX/5thoefa0TzU57o6jlx0oDiA/n5Yry7NxeRRRXM 6guZXgy8P6PH5Ici3zWgjYwW1m2ykleIE5L6/iGMkVvee+vD+FvmmszTiW5CcsQr CqQAw6bmRV3xazbT8eRUhrhDjzZXTWDkgtLzZ2k9yApiQ7tP7eGlGrxG+dc4XdnI 8pKJP3wfvqWXjMS6qM7ikEk9oL7YhM6D0+TiQy7UyjuC+P3g5RUf6DXkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelvddgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjggfsehtkedttddtreejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpefgkefgfeejgfdvvdfguddtleelkedvfeetiedtudfhveev veduhfdvveeffedvueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Apr 2022 18:03:06 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4KdxRX0GJyz1gl; Wed, 13 Apr 2022 22:03:03 +0000 (UTC) Date: Wed, 13 Apr 2022 22:03:03 +0000 From: Daniel Shahaf To: Sam Bostock Cc: zsh-workers@zsh.org Subject: Re: [PATCH] Abbreviate commit hash in prompt during git rebase Message-ID: <20220413220303.GL27526@tarpaulin.shahaf.local2> References: 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: 50057 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 Tue, Apr 12, 2022 at 22:41:46 -0600: > First time contributor here; Welcome! > hopefully I have appropriately formatted this! > Nope. Your MUA inserted hard line breaks, both in prose (e.g., after "uniqueness") and in the diff, breaking it. That may have affected only the text/plain version of the body. The standard workaround for diffs is to send them as attachments named *.txt. Configuring one's email client to not munge linebreaks or whitespace is also an option (and would help with the prose linebreaks too). You seem to use gmail; I don't know the "Be friendly to patches" incantation for that off the top of my head. > Please find the description of the change below. > > I don't have an environment setup to test this, There's Functions/VCS_Info/test-repo-git-rebase-merge, though admittedly it's not easy to discover. > 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 ⋮ > 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. > Specifically, it's included in the prompt via the %p expando of «patch-format», which currently gives, say, «d759c823c2019ab9d5d1d56ac0cd2f9fb0948b76 r7: Append a line» (using the test script), That's then interpolated into the prompt via the %m expando of «actionformats» (which isn't even used by the default settings; I'm glad to know it's nevertheless used ☺). Shortening the hash makes sense. With my setup I actually already get «d759c823c201 r7: Append a line» because I use a custom gen-applied-string hook that does truncation itself; similar to the one in Misc/vcs_info-examples:297, plus manually truncating ${patch_name_or_filename} to its first 12 characters (when under git or hg and not under quilt). The magic number 12 is hardcoded in my zshrc. Now, the test script's output (minimized by me): [in gen-applied-string] typeset -g -a argv=( 'd759c823c2019ab9d5d1d56ac0cd2f9fb0948b76 r7: Append a line' … ) typeset -g vcs_info_msg_0_='[5+2=7] [d759c823c2019ab9d5d1d56ac0cd2f9fb0948b76 r7: Append a line] [2]' typeset -g vcs_info_msg_1_='' The part inside the second set of square brackets is, as mentioned, the expansion of %p in patch-format. The hash and subject are two different attributes of the "patch" (= thing described by a single gen-applied-string argument). If we weren't already combining them into a single string, we'd never start doing that. For instance, my setup colors the hash and subject differently. How about if we added two new expandos, one that expanded only to d759c823c2019ab9d5d1d56ac0cd2f9fb0948b76 and one that expanded only to "r7: Append a line"? Then truncation could be achieved easily by using the %12.12x syntax to truncate to 12 characters (cf. "Truncate Long Hashes" in Misc/vcs_info-examples:137, and colouring the hash and subject differently wouldn't require writing a hook. At this point I suppose we could deprecate %p… which might be a good reason to rethink the way those arguments are passed to the applied-string hook, which in turn might help find a more elegant alternative to workers/49726. > 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. > Is this merely a _side effect_ of implementing hash truncation, or is it something that should be done anyway, even if hash truncation is implemented in a way that doesn't lend itself to also obtaining the subject for free? In the latter case, we might want to make the extra git run conditional on some style (perhaps «use-simple» which already exists; perhaps not). WDYT? Cheers, Daniel (the lists are down as I write this, so y'all will receive this with a delay, but we're working on bringing them back up) > --- > .../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"