From: "Jens Lideström" <jens@lidestrom.se>
To: Johannes Sixt <j6t@kdbg.org>
Cc: "Paul Mackerras [ ]" <paulus@ozlabs.org>,
git@vger.kernel.org,
Jens Lidestrom via GitGitGadget <gitgitgadget@gmail.com>
Subject: Re: [PATCH v2 05/10] gitk: add keyboard bind for checkout command
Date: Sat, 8 Jul 2023 14:09:30 +0200 [thread overview]
Message-ID: <a56a2c80-e28c-1445-c863-039d3ad82da8@lidestrom.se> (raw)
In-Reply-To: <dc76bbf3-cf35-4e7b-bed5-2de9c13eee37@kdbg.org>
> There is already a branch selection dialog (hit F2 to bring it up).
> Could you please have a look whether it can be reused here? Because...
Ah, I didn't consider that! I'll investigate using something similar.
> At a minimum, there should be a confirmation when a
> transition from a branch to a detached head happens
That sounds like a good idea to me too, will fix.
> I find it irritating that it is possible to check out a detached head
> with Ctrl-O, but not via the context menu.
>
> ...
>
> I propose that you do not include the ability to check out a detached
> head in this commit, but make it a new feature once this series has settled.
I agree that the asymmetry between the keyboard bind and the context menu is somewhat unfortunate. But I also think that there is a pretty good justification it, and because of this I'd like to keep the feature in this PR.
The row context menu has a bit too many entries already, to the point where it is a bit hard to use. We really only what to put the most important or commonly used commands here. This is an inherit limitation for GUI menus: the screen real estate is limited. So there is a valid reason not to include the Checkout command.
For keyboard binds however these is no such screen real-estate issue. On the contrary: For keyboard binds it is an artificial asymmetry without any technical justification to NOT be able to checkout the commit of a selected row.
Apart from this it will unfortunately be hard for me to take the time to create a separate PR.
Do you accept this motivation for having the "checkout detached head" feature stay in this PR?
> I find it irritating that it is possible to check out a detached head
> with Ctrl-O, but not via the context menu.
>
> Playing around a bit with this feature, it may be a bit too easy to
> check out a different commit with a simple key press and without
> confirmation. At a minimum, there should be a confirmation when a
> transition from a branch to a detached head happens, because otherwise
> inexperienced users end up in inconvenient territories.
>
> I propose that you do not include the ability to check out a detached
> head in this commit, but make it a new feature once this series has settled.
On 2023-07-05 19:29, Johannes Sixt wrote:
> Am 03.07.23 um 20:45 schrieb Jens Lidestrom via GitGitGadget:
>> From: Jens Lidestrom <jens@lidestrom.se>
>>
>> This also introduces the ability to check out detatched heads. This
>> shouldn't result any problems, because gitk already works with
>> detatched heads if they are checked out using the terminal.
>
> I find it irritating that it is possible to check out a detached head
> with Ctrl-O, but not via the context menu.
>
> Playing around a bit with this feature, it may be a bit too easy to
> check out a different commit with a simple key press and without
> confirmation. At a minimum, there should be a confirmation when a
> transition from a branch to a detached head happens, because otherwise
> inexperienced users end up in inconvenient territories.
>
> I propose that you do not include the ability to check out a detached
> head in this commit, but make it a new feature once this series has settled.
>
>>
>> Signed-off-by: Jens Lidestrom <jens@lidestrom.se>
>> ---
>> gitk-git/gitk | 125 +++++++++++++++++++++++++++++++++++++++-----------
>> 1 file changed, 98 insertions(+), 27 deletions(-)
>>
>> diff --git a/gitk-git/gitk b/gitk-git/gitk
>> index 642cd7f652a..8364033ad58 100755
>> --- a/gitk-git/gitk
>> +++ b/gitk-git/gitk
>> @@ -2691,6 +2691,7 @@ proc makewindow {} {
>> bind $ctext <Button-1> {focus %W}
>> bind $ctext <<Selection>> rehighlight_search_results
>> bind . <$M1B-t> {resethead [selected_line_id]}
>> + bind . <$M1B-o> {checkout [selected_line_heads] [selected_line_id]}
>> for {set i 1} {$i < 10} {incr i} {
>> bind . <$M1B-Key-$i> [list go_to_parent $i]
>> }
>> @@ -2732,7 +2733,7 @@ proc makewindow {} {
>>
>> set headctxmenu .headctxmenu
>> makemenu $headctxmenu {
>> - {mc "Check out this branch" command cobranch}
>> + {mc "Check out this branch" command {checkout [list $headmenuhead] $headmenuid}}
>> {mc "Rename this branch" command mvbranch}
>> {mc "Remove this branch" command rmbranch}
>> {mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
>> @@ -3183,6 +3184,7 @@ proc keys {} {
>> [mc "<%s-minus> Decrease font size" $M1T]
>> [mc "<F5> Update"]
>> [mc "<%s-T> Reset current branch to selected commit" $M1T]
>> +[mc "<%s-O> Check out selected commit" $M1T]
>> " \
>> -justify left -bg $bgcolor -border 2 -relief groove
>> pack $w.m -side top -fill both -padx 2 -pady 2
>> @@ -9978,25 +9980,93 @@ proc headmenu {x y id head} {
>> tk_popup $headctxmenu $x $y
>> }
>>
>> -proc cobranch {} {
>> - global headmenuid headmenuhead headids
>> +proc checkout {heads_on_commit id_to_checkout} {
>> + global headids mainhead
>> global showlocalchanges
>> + global sel_ix confirm_ok NS
>>
>> # check the tree is clean first??
>> - set newhead $headmenuhead
>> +
>> + # Filter out remote branches if local branch is also present
>> + foreach remote_ix [lsearch -all $heads_on_commit "remotes/*"] {
>> + set remote_head [lindex $heads_on_commit $remote_ix]
>> + set local_head [string range $remote_head [expr [string last / $remote_head] + 1] end]
>> + if {$local_head in $heads_on_commit} {
>> + set heads_on_commit [lreplace $heads_on_commit $remote_ix $remote_ix]
>> + }
>> + }
>> +
>> + if {[llength $heads_on_commit] == 1 && [lindex $heads_on_commit 0] eq $mainhead} {
>> + # Only the currently active branch
>> + return
>> + }
>> +
>> + # Filter out mainhead
>> + set mainhead_ix [lsearch $heads_on_commit $mainhead]
>> + if {$mainhead_ix != -1} {
>> + set heads_on_commit [lreplace $heads_on_commit $mainhead_ix $mainhead_ix]
>> + }
>> + set nr_heads_on_commit [llength $heads_on_commit]
>> +
>> + # The number of heads on the commit determines how to select what to checkout
>> + if {$nr_heads_on_commit == 0} {
>> + set head_to_checkout ""
>> + set ref_to_checkout $id_to_checkout
>> + } elseif {$nr_heads_on_commit == 1} {
>> + set head_to_checkout [lindex $heads_on_commit 0]
>> + set ref_to_checkout $head_to_checkout
>> + } else {
>> + # Branch selection dialog
>> +
>> + set confirm_ok 0
>> +
>> + set w ".selectbranch"
>> + ttk_toplevel $w
>> + make_transient $w .
>> + wm title $w [mc "Check out branch"]
>
> There is already a branch selection dialog (hit F2 to bring it up).
> Could you please have a look whether it can be reused here? Because...
>
>> + ${NS}::label $w.m -text [mc "Check out which branch?"]
>> + pack $w.m -side top -fill x -padx 20 -pady 20
>> + ${NS}::frame $w.f
>> +
>> + set sel_ix 0
>> + for {set i 0} {$i < $nr_heads_on_commit} {incr i} {
>> + ${NS}::radiobutton $w.f.id_$i -value $i -variable sel_ix \
>> + -text [lindex $heads_on_commit $i]
>
> ... presenting a list of items in the form of radio buttons is a very
> non-standard user-interface, IMO. I would have expected a list widget in
> which an entry is highlighted. Also, if the list is long, a list would
> have a scroll bar, but a radio button group is limited to the available
> screen height.
>
>> + bind $w.f.id_$i <Key-Up> "set sel_ix [expr ($i - 1) % $nr_heads_on_commit]"
>> + bind $w.f.id_$i <Key-Down> "set sel_ix [expr ($i + 1) % $nr_heads_on_commit]"
>> + grid $w.f.id_$i -sticky w -padx 20
>> + }
>> +
>> + pack $w.f -side top -fill x -padx 4
>> + ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
>> + bind $w <Key-Return> "set confirm_ok 1; destroy $w"
>> + pack $w.ok -side left -fill x -padx 20 -pady 20
>> + ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
>> + bind $w <Key-Escape> [list destroy $w]
>> + pack $w.cancel -side right -fill x -padx 20 -pady 20
>> + bind $w <Visibility> "grab $w; focus $w.f.id_$sel_ix"
>> +
>> + tkwait window $w
>> +
>> + if {!$confirm_ok} return
>> +
>> + set head_to_checkout [lindex $heads_on_commit $sel_ix]
>> + set ref_to_checkout $head_to_checkout
>> + }
>> +
>> + # Handle remote branches
>> set command [list | git checkout]
>> - if {[string match "remotes/*" $newhead]} {
>> - set remote $newhead
>> - set newhead [string range $newhead [expr [string last / $newhead] + 1] end]
>> - # The following check is redundant - the menu option should
>> - # be disabled to begin with...
>> - if {[info exists headids($newhead)]} {
>> - error_popup [mc "A local branch named %s exists already" $newhead]
>> + if {[string match "remotes/*" $head_to_checkout]} {
>> + set remote $head_to_checkout
>> + set head_to_checkout [string range $head_to_checkout [expr [string last / $head_to_checkout] + 1] end]
>> + set ref_to_checkout $head_to_checkout
>> + if {[info exists headids($head_to_checkout)]} {
>> + error_popup [mc "A local branch named %s exists already" $head_to_checkout]
>> return
>> }
>> - lappend command -b $newhead --track $remote
>> + lappend command -b $head_to_checkout --track $remote
>> } else {
>> - lappend command $newhead
>> + lappend command $ref_to_checkout
>> }
>> lappend command 2>@1
>> nowbusy checkout [mc "Checking out"]
>> @@ -10011,11 +10081,11 @@ proc cobranch {} {
>> dodiffindex
>> }
>> } else {
>> - filerun $fd [list readcheckoutstat $fd $newhead $headmenuid]
>> + filerun $fd [list readcheckoutstat $fd $head_to_checkout $ref_to_checkout $id_to_checkout]
>> }
>> }
>>
>> -proc readcheckoutstat {fd newhead newheadid} {
>> +proc readcheckoutstat {fd head_to_checkout ref_to_checkout id_to_checkout} {
>> global mainhead mainheadid headids idheads showlocalchanges progresscoords
>> global viewmainheadid curview
>>
>> @@ -10033,18 +10103,19 @@ proc readcheckoutstat {fd newhead newheadid} {
>> error_popup $err
>> return
>> }
>> - set oldmainid $mainheadid
>> - if {! [info exists headids($newhead)]} {
>> - set headids($newhead) $newheadid
>> - lappend idheads($newheadid) $newhead
>> - addedhead $newheadid $newhead
>> - }
>> - set mainhead $newhead
>> - set mainheadid $newheadid
>> - set viewmainheadid($curview) $newheadid
>> - redrawtags $oldmainid
>> - redrawtags $newheadid
>> - selbyid $newheadid
>> + set old_main_id $mainheadid
>> +
>> + if {$head_to_checkout ne "" && ! [info exists headids($head_to_checkout)]} {
>> + set headids($head_to_checkout) $id_to_checkout
>> + lappend idheads($id_to_checkout) $head_to_checkout
>> + addedhead $id_to_checkout $head_to_checkout
>> + }
>> + set mainhead $ref_to_checkout
>> + set mainheadid $id_to_checkout
>> + set viewmainheadid($curview) $id_to_checkout
>> + redrawtags $old_main_id
>> + redrawtags $id_to_checkout
>> + selbyid $id_to_checkout
>> if {$showlocalchanges} {
>> dodiffindex
>> }
>
next prev parent reply other threads:[~2023-07-08 12:09 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 14:41 [PATCH 0/9] gitk: improve keyboard support Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 1/9] gitk: add procedures to get commit info from selected row Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 2/9] gitk: use term "current branch" in gui Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 3/9] gitk: add keyboard bind for reset Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 4/9] gitk: show branch name in reset dialog Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 5/9] gitk: add keyboard bind for checkout Jens Lidestrom via GitGitGadget
2023-07-02 12:10 ` Jens Lideström
2023-06-27 14:41 ` [PATCH 6/9] gitk: add keyboard bind for create and remove branch Jens Lidestrom via GitGitGadget
2023-06-28 5:59 ` Johannes Sixt
2023-06-28 7:12 ` Jens Lideström
2023-06-28 20:30 ` Johannes Sixt
2023-07-02 11:50 ` Jens Lideström
2023-06-27 14:41 ` [PATCH 7/9] gitk: add keyboard bind to cherry-pick Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 8/9] gitk: focus ok button in reset dialog Jens Lidestrom via GitGitGadget
2023-06-27 14:41 ` [PATCH 9/9] gitk: default select reset hard in dialog Jens Lidestrom via GitGitGadget
2023-06-28 5:46 ` Johannes Sixt
2023-06-28 7:16 ` Jens Lideström
2023-07-02 12:09 ` Jens Lideström
2023-06-28 6:09 ` [PATCH 0/9] gitk: improve keyboard support Johannes Sixt
2023-06-28 7:01 ` Jens Lideström
2023-06-28 17:32 ` Jens Lideström
2023-06-28 20:32 ` Johannes Sixt
2023-07-02 12:28 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 00/10] " Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 01/10] gitk: add procedures to get commit info from selected row Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 02/10] gitk: use term "current branch" in gui Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 03/10] gitk: add keyboard bind for reset command Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 04/10] gitk: show branch name in reset dialog Jens Lidestrom via GitGitGadget
2023-07-03 18:45 ` [PATCH v2 05/10] gitk: add keyboard bind for checkout command Jens Lidestrom via GitGitGadget
2023-07-05 17:29 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström [this message]
2023-07-03 18:45 ` [PATCH v2 06/10] gitk: add keyboard bind for remove branch command Jens Lidestrom via GitGitGadget
2023-07-05 20:00 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 07/10] gitk: add keyboard bind for cherry-pick command Jens Lidestrom via GitGitGadget
2023-07-05 20:07 ` Johannes Sixt
2023-07-08 12:09 ` Jens Lideström
2023-07-03 18:45 ` [PATCH v2 08/10] gitk: add keyboard bind for create branch command Jens Lidestrom via GitGitGadget
2023-07-05 20:02 ` Johannes Sixt
2023-07-03 18:45 ` [PATCH v2 09/10] gitk: improve keyboard convenience in reset dialog Jens Lidestrom via GitGitGadget
2023-07-05 19:52 ` Johannes Sixt
2023-07-03 18:45 ` [PATCH v2 10/10] gitk: allow checkout of remote branch Jens Lidestrom via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a56a2c80-e28c-1445-c863-039d3ad82da8@lidestrom.se \
--to=jens@lidestrom.se \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=j6t@kdbg.org \
--cc=paulus@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).