Skip to contentSkip to conversation

git-gui: (un)stage a range of changes at once

PATCH Applied [email protected] 2 participants 4 messages Jun 15, 2016 Library code

lore
Share & tools
lore
#0 lore raw

v3 cover git-gui: (un)stage a range of changes at once

From: Jeff Epler <[email protected]>

This set of patches allows git-gui to stage multiple lines at once by selecting the range and then using the "apply lines" item in the context menu.

Compared to the earlier versions, I've fixed all the bugs I became aware of. I've also added the missing signed-off-by.

The first patch fixes an existing bug in git-gui when staging a deletion followed by another deletion followed by the end of the file.

Jeff Epler (2):
Fix applying a line when all following lines are deletions Make it possible to apply a range of changes at once

 git-gui.sh   |   15 +++-
 lib/diff.tcl |  241 ++++++++++++++++++++++++++++++++++------------------------
 2 files changed, 153 insertions(+), 103 deletions(-)
#1 lore raw

PATCH v3 1/2 Fix applying a line when all following lines are deletions

From: Jeff Epler <[email protected]>

If a diff looked like
@@
context
-del1
-del2
and you wanted to stage the deletion 'del1', the generated patch wouldn't apply because it was missing the line 'del2' converted to context, but this line was counted in the @@-line

---
 lib/diff.tcl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
lib/diff.tcl +1 -0
index bd5d189..066755b 100644
@@ -664,6 +664,7 @@ proc apply_line {x y} {
 		}
 		set i_l $next_l
 	}
+	set patch "$patch$pre_context"
 	set patch "@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"
 
 	if {[catch {
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH v3 2/2 Make it possible to apply a range of changes at once

In reply to [email protected]

From: Jeff Epler <[email protected]>

---
 git-gui.sh   |   15 +++-
 lib/diff.tcl |  242 ++++++++++++++++++++++++++++++++++------------------------
 2 files changed, 153 insertions(+), 104 deletions(-)
git-gui.sh +12 -3
index 718277a..803423f 100755
@@ -3199,7 +3199,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
@@ -3239,12 +3239,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 || $::is_submodule_diff
 			|| $current_diff_path eq {}
lib/diff.tcl +141 -101

271 lines not on this page · raw message

Signature · 1 line
1.6.3.3