zsh_completion: use revsets to exclude this rev from suggestions to hg merge
ClosedPublic

Authored by av6 on Aug 31 2018, 1:42 AM.

Details

Summary

One of the most important aspects of a completion system is its speed, so 1
call to hg is definitely better than 4.

Sorting by rev (descending) is to preserve the same order as in hg heads
output.

While at it, declare branches as an array too.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
av6 created this revision.Aug 31 2018, 1:42 AM

Would it make sense to combine this into one hg invocation? I think it wouldn't be that hard (hmm, not as trivial as I thought, but.. not the worst thing ever? :))

allheads=(${(f)"$(_hg_cmd log -r 'sort(head(), -rev)' --template '{ifcontains(rev, revset(\".\"), \"T\", \"F\")}:{rev}:{branch}\n')"})

# Extract current revision from allheads, remove "[TF]:" prefix from each item
selfentry=(${${allheads:#F*}/#T:/})
heads=(${${allheads:#T*}/#F:/})

# Remove "{rev}:" prefix from each item in heads to get just branch names
branches=(${(S)heads/#*:/})

# Remove branches that match the one we're currently on
selfbranch=(${(S)selfentry/#*:/})
branches=(${branches:#$selfbranch})
av6 added a comment.EditedAug 31 2018, 9:31 PM

It probably would make sense, but you don't need to exclude current branch, because hg merge my-current-branch works when you have more than one branch head (except when you stand on the newest head, unfortunately: "abort: merging with a working directory ancestor has no effect").

av6 updated this revision to Diff 10716.Sep 3 2018, 6:52 AM
av6 edited the summary of this revision. (Show Details)
av6 added a comment.EditedSep 3 2018, 7:08 AM

Now it's only one call to hg. All possible branches included, even if hg merge that-branch would complain (see my comment above), because in completions it's better to give extra suggestions than to miss some.

But this "revision numbers + branch names" got me thinking, maybe it should also suggest hashes, since some people prefer them? Specifically, {node|shortest}, so that they don't take too much space.

spectral accepted this revision.Sep 4 2018, 4:33 PM
pulkit accepted this revision.Sep 5 2018, 6:40 AM
This revision was automatically updated to reflect the committed changes.