zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/2] __git_recent_branches: Fix an 'assertion' failure when two branches (refs) point to the same commit.
@ 2016-11-12  1:01 Daniel Shahaf
  2016-11-12  1:01 ` [PATCH 2/2] __git_recent_branches: Remove erroneous parsing of partial ref names as tags Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2016-11-12  1:01 UTC (permalink / raw)
  To: zsh-workers; +Cc: Daniel Hahler

---
Found by Daniel Hahler.

__git_recent_branches() is not called by _git (for the time being).

Cheers,

Daniel

 Completion/Unix/Command/_git | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 17a7b1e..94457fc 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6076,7 +6076,8 @@ __git_recent_branches__names()
 
 (( $+functions[__git_recent_branches] )) ||
 __git_recent_branches() {
-  local -a branches descriptions
+  local -a branches
+  local -A descriptions
   local -a reply
   local -aU valid_ref_names_munged=( ${"${(f)"$(_call_program valid-ref-names 'git for-each-ref --format="%(refname)" refs/heads/ refs/tags/')"}"#refs/(heads|tags)/} )
 
@@ -6093,19 +6094,15 @@ __git_recent_branches() {
   fi
 
   # 4. Obtain log messages for all of them in one shot.
-  descriptions=( ${(f)"$(_call_program all-descriptions git --no-pager log --no-walk=unsorted --pretty=%s ${(q)branches} --)"} )
-
-  if (( $#branches != $#descriptions )); then
-    # ### Trouble...
-    zle -M "__git_recent_branches: \$#branches != \$#descriptions"
-    return 1
-  fi
+  # TODO: we'd really like --sort=none here...  but git doesn't support such a thing.
+  # The \n removal is because for-each-ref prints a \n after each entry.
+  descriptions=( ${(0)"$(_call_program all-descriptions "git --no-pager for-each-ref --format='%(refname)%00%(subject)%00'" refs/heads/${(q)^branches} refs/tags/${(q)^branches} "--")"//$'\n'} )
 
   # 5. Synthesize the data structure _describe wants.
   local -a branches_colon_descriptions
-  local branch description
-  for branch description in ${branches:^descriptions} ; do
-    branches_colon_descriptions+="${branch//:/\:}:${description}"
+  local branch
+  for branch in ${branches} ; do
+    branches_colon_descriptions+="${branch//:/\:}:${(v)descriptions[(I)(refs/heads/|refs/tags/)${(b)branch}]}"
   done
 
   _describe -V -t recent-branches "recent branches" branches_colon_descriptions


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] __git_recent_branches: Remove erroneous parsing of partial ref names as tags.
  2016-11-12  1:01 [PATCH 1/2] __git_recent_branches: Fix an 'assertion' failure when two branches (refs) point to the same commit Daniel Shahaf
@ 2016-11-12  1:01 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2016-11-12  1:01 UTC (permalink / raw)
  To: zsh-workers; +Cc: Daniel Hahler

In the reflog, partial ref names in the "from" field always represent names of
heads.  (That is not true for the "to" field.)  The parsing of tag names was
added in commit 39102 (317c96b64f43688a6be08a8b1c93b6ab4eed662c) for equivalence
with the then-previous implementation which used `git log $partial_ref_name`.
The equivalence was correct, however, the then-previous implementation was not,
since it would consider $partial_ref_name as a refs/tags/ name if a refs/heads/
name did not exist.
---
 Completion/Unix/Command/_git | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 94457fc..4dba93b 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6079,7 +6079,7 @@ __git_recent_branches() {
   local -a branches
   local -A descriptions
   local -a reply
-  local -aU valid_ref_names_munged=( ${"${(f)"$(_call_program valid-ref-names 'git for-each-ref --format="%(refname)" refs/heads/ refs/tags/')"}"#refs/(heads|tags)/} )
+  local -aU valid_ref_names_munged=( ${"${(f)"$(_call_program valid-ref-names 'git for-each-ref --format="%(refname)" refs/heads/')"}"#refs/heads/} )
 
   # 1. Obtain names of recently-checked-out branches from the reflog.
   # 2. Remove ref names that that no longer exist from the list.
@@ -6096,13 +6096,13 @@ __git_recent_branches() {
   # 4. Obtain log messages for all of them in one shot.
   # TODO: we'd really like --sort=none here...  but git doesn't support such a thing.
   # The \n removal is because for-each-ref prints a \n after each entry.
-  descriptions=( ${(0)"$(_call_program all-descriptions "git --no-pager for-each-ref --format='%(refname)%00%(subject)%00'" refs/heads/${(q)^branches} refs/tags/${(q)^branches} "--")"//$'\n'} )
+  descriptions=( ${(0)"$(_call_program all-descriptions "git --no-pager for-each-ref --format='%(refname)%00%(subject)%00'" refs/heads/${(q)^branches} "--")"//$'\n'} )
 
   # 5. Synthesize the data structure _describe wants.
   local -a branches_colon_descriptions
   local branch
   for branch in ${branches} ; do
-    branches_colon_descriptions+="${branch//:/\:}:${(v)descriptions[(I)(refs/heads/|refs/tags/)${(b)branch}]}"
+    branches_colon_descriptions+="${branch//:/\:}:${descriptions[refs/heads/${(b)branch}]}"
   done
 
   _describe -V -t recent-branches "recent branches" branches_colon_descriptions


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-12  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-12  1:01 [PATCH 1/2] __git_recent_branches: Fix an 'assertion' failure when two branches (refs) point to the same commit Daniel Shahaf
2016-11-12  1:01 ` [PATCH 2/2] __git_recent_branches: Remove erroneous parsing of partial ref names as tags Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).