threads / patch / 38785

patchgit-completion: add stashes for gitk

Subject: [PATCH] git-completion: add stashes for gitk

## tl;dr

5 messages between Mar 12, 2015 and Mar 14, 2015. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Sveinung Kvilhaugsvik· Mar 12, 2015, 00:42 UTC · lore

Auto complete stashed modifications for gitk. This makes them easier to discover and faster to view.

Signed-off-by: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net>
---
 contrib/completion/git-completion.bash | 2 ++
 1 file changed, 2 insertions(+)
Show changes to contrib/completion/git-completion.bash +2 −0
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c21190d..3a23abb 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2644,6 +2644,8 @@ __gitk_main ()
 		;;
 	esac
 	__git_complete_revlist
+	__gitcomp_nl_append "$(git --git-dir="$(__gitdir)" stash list \
+			| sed -n -e 's/:.*//p')"
 }
 
 if [[ -n ${ZSH_VERSION-} ]]; then
-- 
2.1.4
Junio C Hamano· Mar 12, 2015, 18:11 UTC · re: Sveinung Kvilhaugsvik · lore

Re: [PATCH] git-completion: add stashes for gitk

Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net> writes:
Show 18 quoted lines
> Auto complete stashed modifications for gitk. This makes them easier to
> discover and faster to view.
>
> Signed-off-by: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net>
> ---
>  contrib/completion/git-completion.bash | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index c21190d..3a23abb 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2644,6 +2644,8 @@ __gitk_main ()
>  		;;
>  	esac
>  	__git_complete_revlist
> +	__gitcomp_nl_append "$(git --git-dir="$(__gitdir)" stash list \
> +			| sed -n -e 's/:.*//p')"

I do not find it particularly useful to expand "gitk st<TAB>" to "gitk st" and offer "sting stash@{0} stash@{1} stash@{2} stash@{3}" ('sting' happens to be just one of the names of my branches) as possible choices.

Because I happen to have only four stash entries right now, it may still be manageable, but the stash entries can be dozens for some people.

Once you have dozens of branches and tags, you learn to avoid "gitk <TAB>" (or "git log <TAB>") to prevent the completion code from dumping all these refnames at you. Instead, you would give a few characters before hitting the <TAB> to limit the completion. But this change makes it harder if what you want happens to start with es-tee something, as you would get many stash@{...} entries along with it. Also, when you have no ref that is named es-tee something, "gitk st<TAB>" completes to "gitk stash@{", as if the problem the change tries to cure is "it is unnecessarily hard to type at-mark open-brace".

I do not have to be the target audience, though. Maybe this is useful for some people.

A bigger question is why this change is made to gitk completion. If this completion were useful for "gitk", wouoldn't it be equally useful for "git log"?

Thanks.
Junio C Hamano· Mar 12, 2015, 18:40 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-completion: add stashes for gitk

Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> ...  Also, when you have no ref that is named es-tee something,
> "gitk st<TAB>" completes to "gitk stash@{", as if the problem the
> change tries to cure is "it is unnecessarily hard to type at-mark
> open-brace".
>
> I do not have to be the target audience, though.  Maybe this is
> useful for some people.

There is another thing your patch made me notice, which is not a problem that is introduced by your desire to include stash entries to the completion.

The way in which the users can name a stash entry is not very descriptive. I often cannot offhand remember what stash@{2} contains, for example, in my tree. So it is not very useful to be offered a choice among stash@{0} stash@{1} stash@{2} and stash@{3} by a TAB completion.

If there were a way for users to say "The one I made to stash away that change" from the command line (I do not mean "git stash list | grep 'that change'"), it would be good. A new syntax to name a stash entry by pattern matching with the message given to "stash save" could be something like (just thinking aloud, not suggesting that this has to be our final design of that syntax):

    $ git log stash@{/$pattern}
and then it mould make a lot of sense for a completion request
    $ git log stash@{<TAB>
to result in something like this:
    "stash@{/avoid unnecessary negation}"
    "stash@{/style fix t4122}"
    ...
Sveinung Kvilhaugsvik· Mar 13, 2015, 17:25 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-completion: add stashes for gitk

Thank you for the review.

I now understand that the commit message should have provided way more context about my use case.

I used Bazaar almost exclusively until about a year ago. Git's ability to put stuff in the index without committing and the power of "git rebase" covers many of the use cases I would have used shelves ("stashes") for in Bazaar. But a stash is still, as far as I know Git, the best solution in some cases.

A Bazaar shelve ("stash") has a stable number. (Applying a shelve from the middle of the list won't cause a renumbering) A git stash will change its number when a new stash is added. (On the positive side this allows stash@{2.hours.ago}) The renumbering makes it more difficult to keep track of what is there. I therefore have more need of a quick way to get an overview of the stashes in git than in bazaar. You idea of using a stash's message to refer to it would solve this.

In Bazaar I can quickly get an overview of the shelves ("stashes") by typing "bzr qshelve" and clicking on the "View shelved changes" tab. Its has a list of my shelves including their number and message at the top. Under it the diff of the currently selected shelve is displayed. This makes it fast to get an overview of the shelves.

The objective the patch tries to achieve is to speed up getting an overview of stashed changes in gitk. A big stash in "git stash list -p" can force a user to read it slowly or risk skipping the next stash. By typing "gitk stash@{<TAB>" all stashes are listed. The user can then know if there are more stashes that haven't been viewed yet and stop reading a stash when he knows what the current stash is. (If I understand things right "gitk stash@{.}" would have the problem of burying old stashed under the commits above it)

> A bigger question is why this change is made to gitk completion.  If
> this completion were useful for "gitk", wouoldn't it be equally
> useful for "git log"?

I must admit that I didn't know that "git log" could display the content of a stashed change. After trying "git log -p -m stash@{0}" I would say that adding stashes for "git log" would be slightly less useful. "gitk stash@{0}" allows me to look at the stashed change and find out what it contains. "git log -p" (note: no "-m" since the user don't know that a stash is a merge commit) won't let me do that. Another reason is that "git stash show -p stash@{0}" already is autocompleted for those that wish to view their stash diff on the command line)

> If there were a way for users to say "The one I made to stash away
> that change" from the command line (I do not mean "git stash list |
> grep 'that change'"), it would be good.
Great idea.
-- 
Helsing
Sveinung

"The Lord requires of his saints confession of sins during their whole
lives, and that without ceasing, and promises pardon. How presumptuous,
then, to exempt them from sin, or when they have stumbled, to exclude them
altogether from grace?" (sitat John Calvin)
Junio C Hamano· Mar 14, 2015, 05:18 UTC · re: Sveinung Kvilhaugsvik · lore

Re: [PATCH] git-completion: add stashes for gitk

Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net> writes:
Show 7 quoted lines
>> A bigger question is why this change is made to gitk completion.  If
>> this completion were useful for "gitk", wouoldn't it be equally
>> useful for "git log"?
> I must admit that I didn't know that "git log" could display the
> content of a stashed change. After trying "git log -p -m stash@{0}" I
> would say that adding stashes for "git log" would be slightly less
> useful.

Yeah, it would not be so useful to dig with "log" beyond the commit that each stash entry is based on. But imagine "git show stash@{....}" or "git log -g stash@{0}"?

← back to recent threads