threads / patch / 23334

patchgit-gui: Fast staging/unstaging of hunks/lines

Subject: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

## tl;dr

6 messages between Apr 5, 2010 and Apr 12, 2010. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Bert Wesarg· Apr 5, 2010, 09:01 UTC · lore

This adds a shortcut to stage/unstage hunks or a range of lines. Which is done on a mouse button 1 release event and holding the control key in the diff view. If there is currently a selection only the selected lines will be staged/unstaged. Otherwise the hunk will be staged/unstaged.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui/git-gui.sh |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
Show changes to git-gui/git-gui.sh +16 −0
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 7d54511..e65a0e6 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -3452,6 +3452,22 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
 }
 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
 
+# applies/reverses hunks or lines on button-1 release
+proc immediate_apply_hunk_or_lines {x y} {
+	global current_diff_path file_states
+	set ::cursorX $x
+	set ::cursorY $y
+
+	set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
+	if {$has_range} {
+		apply_range_or_line $::cursorX $:cursorY
+		do_rescan
+	} else {
+		apply_hunk $::cursorX $::cursorY
+	}
+}
+bind $ui_diff <$M1B-ButtonRelease-1> {immediate_apply_hunk_or_lines %x %y}
+
 # -- Status Bar
 #
 set main_status [::status_bar::new .status]
-- 
1.7.0.3.418.gf56ac.dirty
Bert Wesarg· Apr 11, 2010, 07:38 UTC · re: Bert Wesarg · lore

Re: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

On Mon, Apr 5, 2010 at 11:01, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> This adds a shortcut to stage/unstage hunks or a range of lines. Which is done
> on a mouse button 1 release event and holding the control key in the diff view.
> If there is currently a selection only the selected lines will be staged/unstaged.
> Otherwise the hunk will be staged/unstaged.
Ping.
Show 37 quoted lines
>
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
>  git-gui/git-gui.sh |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
> index 7d54511..e65a0e6 100755
> --- a/git-gui/git-gui.sh
> +++ b/git-gui/git-gui.sh
> @@ -3452,6 +3452,22 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
>  }
>  bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
>
> +# applies/reverses hunks or lines on button-1 release
> +proc immediate_apply_hunk_or_lines {x y} {
> +       global current_diff_path file_states
> +       set ::cursorX $x
> +       set ::cursorY $y
> +
> +       set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
> +       if {$has_range} {
> +               apply_range_or_line $::cursorX $:cursorY
> +               do_rescan
> +       } else {
> +               apply_hunk $::cursorX $::cursorY
> +       }
> +}
> +bind $ui_diff <$M1B-ButtonRelease-1> {immediate_apply_hunk_or_lines %x %y}
> +
>  # -- Status Bar
>  #
>  set main_status [::status_bar::new .status]
> --
> 1.7.0.3.418.gf56ac.dirty
>
>
Johannes Sixt· Apr 11, 2010, 19:01 UTC · re: Bert Wesarg · lore

Re: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

On Sonntag, 11. April 2010, Bert Wesarg wrote:
> On Mon, Apr 5, 2010 at 11:01, Bert Wesarg <bert.wesarg@googlemail.com> 
wrote:
Show 6 quoted lines
> > This adds a shortcut to stage/unstage hunks or a range of lines. Which is
> > done on a mouse button 1 release event and holding the control key in the
> > diff view. If there is currently a selection only the selected lines will
> > be staged/unstaged. Otherwise the hunk will be staged/unstaged.
>
> Ping.
I gave the patch a quick try.

I don't think that I would use it a lot because it is very easy to mess up a staged change: The problem is that a click without anything selected will stage an entire hunk. I frequently use "Stage Line(s)" to separate neighboring changes that must go to separate commits, but with you feature it is very easy to forget to select something and, hence, to stage the entire hunk accidentally - which means that I would have to start over with the hunk and all the "quick" aspects of the feature would be lost.

That said, since I don't have Ctrl pressed very often while working in git-gui, the patch wouldn't hurt me, I think.

-- Hannes
Bert Wesarg· Apr 12, 2010, 06:49 UTC · re: Johannes Sixt · lore

Re: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

Hi,
On Sun, Apr 11, 2010 at 21:01, Johannes Sixt <j6t@kdbg.org> wrote:
Show 11 quoted lines
> On Sonntag, 11. April 2010, Bert Wesarg wrote:
>> On Mon, Apr 5, 2010 at 11:01, Bert Wesarg <bert.wesarg@googlemail.com>
> wrote:
>> > This adds a shortcut to stage/unstage hunks or a range of lines. Which is
>> > done on a mouse button 1 release event and holding the control key in the
>> > diff view. If there is currently a selection only the selected lines will
>> > be staged/unstaged. Otherwise the hunk will be staged/unstaged.
>>
>> Ping.
>
> I gave the patch a quick try.
Thanks,
Show 8 quoted lines
>
> I don't think that I would use it a lot because it is very easy to mess up a
> staged change: The problem is that a click without anything selected will
> stage an entire hunk. I frequently use "Stage Line(s)" to separate
> neighboring changes that must go to separate commits, but with you feature it
> is very easy to forget to select something and, hence, to stage the entire
> hunk accidentally - which means that I would have to start over with the hunk
> and all the "quick" aspects of the feature would be lost.

I don't feel comfortable with this ambiguity myself. I see two ways to solve this:

    a) Use Shift-Button-1 for lines
or
    b) Use Shift-Control-Button-1 for lines
and make Control-Button-1 only stage hunks.
May this interface be more usable?

Regards, Bert

> -- Hannes
>
Johannes Sixt· Apr 12, 2010, 17:45 UTC · re: Bert Wesarg · lore

Re: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

On Montag, 12. April 2010, Bert Wesarg wrote:
Show 10 quoted lines
> I don't feel comfortable with this ambiguity myself. I see two ways to
> solve this:
>
>     a) Use Shift-Button-1 for lines
>
> or
>
>     b) Use Shift-Control-Button-1 for lines
>
> and make Control-Button-1 only stage hunks.
That's worse, because you need Shift-Button-1 to extend a selection.

The problem is that the X-Windowsy way to overload single-click operations. Personally, I prefer to get an operative response only on double-click. It's still unused, I think.

-- Hannes
Bert Wesarg· Apr 12, 2010, 17:55 UTC · re: Johannes Sixt · lore

Re: [PATCH] git-gui: Fast staging/unstaging of hunks/lines

On Mon, Apr 12, 2010 at 19:45, Johannes Sixt <j6t@kdbg.org> wrote:
Show 17 quoted lines
> On Montag, 12. April 2010, Bert Wesarg wrote:
>> I don't feel comfortable with this ambiguity myself. I see two ways to
>> solve this:
>>
>>     a) Use Shift-Button-1 for lines
>>
>> or
>>
>>     b) Use Shift-Control-Button-1 for lines
>>
>> and make Control-Button-1 only stage hunks.
>
> That's worse, because you need Shift-Button-1 to extend a selection.
>
> The problem is that the X-Windowsy way to overload single-click operations.
> Personally, I prefer to get an operative response only on double-click. It's
> still unused, I think.

Good idea. But I fear that you can loose your selection, if you move the pointer accidentally while double clicking. Its still worth to try this.

Bert
>
> -- Hannes
>

← back to recent threads