Skip to contentSkip to conversation

git-gui: Allow staging multiple lines at once

RFC PATCH In review Jeff Epler 5 participants 6 messages Jun 15, 2016

lore
Share & tools
lore

Jeff Epler

author
#0 lore raw

RFC PATCH 1/1 git-gui: Allow staging multiple lines at once

When applying less than a full hunk, it's still often desirable to apply a number of consecutive lines.

This change makes it possible to sweep out a range of lines in the diff view with the left mouse button, then right click and "Stage Lines For Commit".

The selected lines may span multiple hunks.

---
The diff looks bigger than it is because it changed the indentation level of about 80 lines, and that made it necessary to reflow a lengthy comment block as well.

This introduces new user interface strings. I felt this was probably a better decision than using the inaccurate "Stage Line For Commit" when a block of text was swept out.

I wonder a bit about the message [mc "Apply/Reverse Line"] -- as far as I can tell, it is never shown to a user, so why is it translated?

 git-gui/git-gui.sh   |   15 +++-
 git-gui/lib/diff.tcl |  222 +++++++++++++++++++++++++++----------------------
 2 files changed, 134 insertions(+), 103 deletions(-)
git-gui/git-gui.sh +12 -3
index 14b92ba..a80ed0d 100755
@@ -3165,7 +3165,7 @@ set ui_diff_applyhunk [$ctxm index last]
 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
 $ctxm add command \
 	-label [mc "Apply/Reverse Line"] \
-	-command {apply_line $cursorX $cursorY; do_rescan}
+	-command {apply_range_or_line $cursorX $cursorY; do_rescan}
 set ui_diff_applyline [$ctxm index last]
 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
 $ctxm add separator
@@ -3205,12 +3205,21 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
 	if {[string first {U} $state] >= 0} {
 		tk_popup $ctxmmg $X $Y
 	} else {
+		set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
 		if {$::ui_index eq $::current_diff_side} {
 			set l [mc "Unstage Hunk From Commit"]
-			set t [mc "Unstage Line From Commit"]
+			if {$has_range} {
+				set t [mc "Unstage Lines From Commit"]
+			} else {
+				set t [mc "Unstage Line From Commit"]
+			}
 		} else {
 			set l [mc "Stage Hunk For Commit"]
-			set t [mc "Stage Line For Commit"]
+			if {$has_range} {
+				set t [mc "Stage Lines For Commit"]
+			} else {
+				set t [mc "Stage Line For Commit"]
+			}
 		}
 		if {$::is_3way_diff
 			|| $current_diff_path eq {}
git-gui/lib/diff.tcl +122 -100

251 lines not on this page · raw message

Signature · 1 line
1.6.5.rc1.49.ge970
#1 lore raw
Quoted 7 lines · Jeff Epler

When applying less than a full hunk, it's still often desirable to apply a number of consecutive lines.

This change makes it possible to sweep out a range of lines in the diff view with the left mouse button, then right click and "Stage Lines For Commit".

The selected lines may span multiple hunks.

Great! I've wished for this feature...

Thanks,
-Geert

#2 lore raw
In reply to Jeff Epler
Quoted 7 lines · Jeff Epler

When applying less than a full hunk, it's still often desirable to apply a number of consecutive lines.

This change makes it possible to sweep out a range of lines in the diff view with the left mouse button, then right click and "Stage Lines For Commit".

The selected lines may span multiple hunks.

Superb! Will test.

-- Hannes

#3 lore raw
In reply to Jeff Epler

Am 19.10.2009 21:54 schrieb Jeff Epler:

Quoted 8 lines

When applying less than a full hunk, it's still often desirable to apply a number of consecutive lines.

This change makes it possible to sweep out a range of lines in the diff view with the left mouse button, then right click and "Stage Lines For Commit".

The selected lines may span multiple hunks.

Awesome! I've been waiting for that very feature. Thanks in advance. -- Dirk

#4 lore raw
In reply to Jeff Epler
Quoted 7 lines · Jeff Epler

When applying less than a full hunk, it's still often desirable to apply a number of consecutive lines.

This change makes it possible to sweep out a range of lines in the diff view with the left mouse button, then right click and "Stage Lines For Commit".

The selected lines may span multiple hunks.

Thanks a lot! Very nice. I've been planning to implement this sometime myself but never got around it.

Tested it and it works like a charm. I will include Shawn in the CC: so he can comment.

cheers Heiko