From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 6b1740de for ; Sat, 1 Feb 2020 00:10:13 +0000 (UTC) Received: (qmail 18109 invoked by alias); 1 Feb 2020 00:10:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45366 Received: (qmail 21472 invoked by uid 1010); 1 Feb 2020 00:10:05 -0000 X-Qmail-Scanner-Diagnostics: from wout5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25703. spamassassin: 3.4.2. Clear:RC:0(64.147.123.21):SA:0(-2.6/5.0):. Processed in 6.266753 secs); 01 Feb 2020 00:10:05 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgedugddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfgjfhfogggtgfesthhqtd dtredtjeenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghnihgv lhdrshhhrghhrghfrdhnrghmvgeqnecukfhppeejledrudektddrheejrdduudelnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggr nhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Date: Sat, 1 Feb 2020 00:09:19 +0000 From: Daniel Shahaf To: WGH Cc: zsh-workers@zsh.org Subject: Re: [PATCH] _git: Fix __git_recent_branches for case when commit has empty message Message-ID: <20200201000919.32cba94b@tarpaulin.shahaf.local2> In-Reply-To: <5391aaa5-73e7-266c-adb2-8c7d96373b8e@torlan.ru> References: <5391aaa5-73e7-266c-adb2-8c7d96373b8e@torlan.ru> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable WGH wrote on Fri, 31 Jan 2020 19:57 +0300: > Pressing "Tab" after entering "git checkout " will cause the completion > script to crash with the following error: >=20 > =C2=A0=C2=A0=C2=A0 __git_recent_branches:21: bad set of key/value pairs f= or associative array Thanks, I can reproduce this. > This error happens when an associative array is assigned odd number of > elements. Unless the variable being split is inside double quotes, empty > elements are removed (which is what causes the problem). >=20 > This commit fixes it. Not on my machine. First, the unidiff was improperly serialized: the spaces at the start of each context line were converted to non-breaking spaces (U+00A0). I applied the patch manually, and completion did work, but stderr was spammed with two warnings: +__git_recent_branches:21> =C2=A0 local $'z=3D\C-@' __git_recent_branches:21: command not found: =C2=A0 +__git_recent_branches:22> _call_program all-descriptions 'git --no-pager f= or-each-ref --format=3D'\''%(refname)%00%(subject)'\' refs/heads/master -- = =20 __git_recent_branches:22: unknown file attribute: I'm not sure why that happened. I assume "unknown file attribute" means parentheses were taken for glob qualifiers, but I don't see why the patch would have that effect. I was testing in an empty repository, produced by =C2=ABcd "$(mktemp -d)" && git init && git commit --allow-empty{,-message} && git checkout -b foo=C2=BB. Does anyone see wha= t caused the warnings? As to the bug, I found a workaround: diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index ba1852699..7fccc11b0 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -6663,13 +6663,14 @@ __git_recent_branches() { # 4. Obtain log messages for all of them in one shot. # TODO: we'd really like --sort=3Dnone here... but git doesn't support = such a thing. # The \n removal is because for-each-ref prints a \n after each entry. + # The x is added in case %(subject)'s expansion is the empty string. - descriptions=3D( ${(0)"$(_call_program all-descriptions "git --no-pager = for-each-ref --format=3D'%(refname)%00%(subject)%00'" refs/heads/${(q)^bran= ches} "--")"//$'\n'} ) + descriptions=3D( ${(0)"$(_call_program all-descriptions "git --no-pager = for-each-ref --format=3D'%(refname)%00x%(subject)%00'" refs/heads/${(q)^bra= nches} "--")"//$'\n'} ) =20 # 5. Synthesize the data structure _describe wants. local -a branches_colon_descriptions local branch for branch in ${branches} ; do - branches_colon_descriptions+=3D"${branch//:/\:}:${descriptions[refs/he= ads/${(b)branch}]}" + branches_colon_descriptions+=3D"${branch//:/\:}:${descriptions[refs/he= ads/${(b)branch}]#x}" done =20 _describe -V -t recent-branches "recent branches" branches_colon_descrip= tions > Since --format=3D%(refname)%00%(subject)%00 appends null byte to every li= ne, > using this format would cause an extra empty element appear, breaking the > assigment again. In order to fix this, I removed the trailing null byte > from the format string, and replaced newlines separating entries with > null byte (they were previously removed). Since neither refname nor > subject appears to be capable of containing newlines, this change should > be safe. Agreed. Thanks for the bug report and the patch. I guess I'll commit my version, since it fixes the bug, but I do want to understand why your patch didn't work for me. Cheers, Daniel