* [PATCH 1/1] git-gui: fix hunk parsing for corner case changes
@ 2012-01-09 13:43 Bert Wesarg
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-14 5:25 ` [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
0 siblings, 2 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-09 13:43 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
The simple hunk parsing code did not recognize hunks when there is no
second number after the comma. Like in these cases:
@@ -1 +0,0 @@
-1
Which resulted in this hunk header:
@@ -1 +0,1 +1 +0,0 @@
Or:
@@ -1 +1 @@
-1
+2
Resulted in:
@@ -1 +1 @@
,1 +1 +1 @@
,0 @@
While trying to stage only the '-1' line.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
lib/diff.tcl | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/diff.tcl b/lib/diff.tcl
index ec44055..63f8742 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -672,9 +672,11 @@ proc apply_range_or_line {x y} {
# $i_l is now at the beginning of a line
# pick start line number from hunk header
- set hh [$ui_diff get $i_l "$i_l + 1 lines"]
- set hh [lindex [split $hh ,] 0]
- set hln [lindex [split $hh -] 1]
+ if {![regexp {^@@ -(\d+)(?:,\d+)? \+(?:\d+)(?:,\d+)? @@(?:\s|$)} \
+ [$ui_diff get $i_l "$i_l + 1 lines"] hh hln]} {
+ unlock_index
+ return
+ }
# There is a special situation to take care of. Consider this
# hunk:
--
1.7.8.1.873.gfea665
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line
2012-01-09 13:43 [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
@ 2012-01-09 13:43 ` Bert Wesarg
2012-01-09 13:43 ` [RFC/PATCH 3/3] git-gui: support for reverting hunks and lines Bert Wesarg
` (2 more replies)
2012-01-14 5:25 ` [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
1 sibling, 3 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-09 13:43 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
Selecting also the trailing newline of a line for staging/unstaging would
have resulted in also staging/unstaging of the next line.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
lib/diff.tcl | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/lib/diff.tcl b/lib/diff.tcl
index 63f8742..a750ea7 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -632,7 +632,13 @@ proc apply_range_or_line {x y} {
}
set first_l [$ui_diff index "$first linestart"]
- set last_l [$ui_diff index "$last lineend"]
+ # don't include the next line if $last points to the start of a line
+ # ie. <lno>.0
+ if {[lindex [split $last .] 1] == 0} {
+ set last_l [$ui_diff index "$last -1 line lineend"]
+ } else {
+ set last_l [$ui_diff index "$last lineend"]
+ }
if {$current_diff_path eq {} || $current_diff_header eq {}} return
if {![lock_index apply_hunk]} return
--
1.7.8.1.873.gfea665
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC/PATCH 3/3] git-gui: support for reverting hunks and lines
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
@ 2012-01-09 13:43 ` Bert Wesarg
2012-01-14 5:26 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-14 12:08 ` Bert Wesarg
2 siblings, 0 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-09 13:43 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
git-gui.sh | 106 +++++++++++++++++++++++++++++++++++++++------------------
lib/diff.tcl | 23 ++++++++++---
2 files changed, 90 insertions(+), 39 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index ba4e5c1..955cbf8 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3289,36 +3289,35 @@ pack .vpane.lower.commarea.buffer -side left -fill y
# -- Commit Message Buffer Context Menu
#
-set ctxm .vpane.lower.commarea.buffer.ctxm
-menu $ctxm -tearoff 0
-$ctxm add command \
+set ui_comm_ctxm .vpane.lower.commarea.buffer.ctxm
+menu $ui_comm_ctxm -tearoff 0
+$ui_comm_ctxm add command \
-label [mc Cut] \
-command {tk_textCut $ui_comm}
-$ctxm add command \
+$ui_comm_ctxm add command \
-label [mc Copy] \
-command {tk_textCopy $ui_comm}
-$ctxm add command \
+$ui_comm_ctxm add command \
-label [mc Paste] \
-command {tk_textPaste $ui_comm}
-$ctxm add command \
+$ui_comm_ctxm add command \
-label [mc Delete] \
-command {catch {$ui_comm delete sel.first sel.last}}
-$ctxm add separator
-$ctxm add command \
+$ui_comm_ctxm add separator
+$ui_comm_ctxm add command \
-label [mc "Select All"] \
-command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
-$ctxm add command \
+$ui_comm_ctxm add command \
-label [mc "Copy All"] \
-command {
$ui_comm tag add sel 0.0 end
tk_textCopy $ui_comm
$ui_comm tag remove sel 0.0 end
}
-$ctxm add separator
-$ctxm add command \
+$ui_comm_ctxm add separator
+$ui_comm_ctxm add command \
-label [mc "Sign Off"] \
-command do_signoff
-set ui_comm_ctxm $ctxm
# -- Diff Header
#
@@ -3366,9 +3365,9 @@ tlabel .vpane.lower.diff.header.path \
pack .vpane.lower.diff.header.status -side left
pack .vpane.lower.diff.header.file -side left
pack .vpane.lower.diff.header.path -fill x
-set ctxm .vpane.lower.diff.header.ctxm
-menu $ctxm -tearoff 0
-$ctxm add command \
+set hctxm .vpane.lower.diff.header.ctxm
+menu $hctxm -tearoff 0
+$hctxm add command \
-label [mc Copy] \
-command {
clipboard clear
@@ -3377,8 +3376,8 @@ $ctxm add command \
-type STRING \
-- $current_diff_path
}
-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
-bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
+lappend diff_actions [list $hctxm entryconf [$hctxm index last] -state]
+bind_button3 .vpane.lower.diff.header.path "tk_popup $hctxm %X %Y"
# -- Diff Body
#
@@ -3491,29 +3490,61 @@ proc create_common_diff_popup {ctxm} {
-command do_options
}
-set ctxm .vpane.lower.diff.body.ctxm
-menu $ctxm -tearoff 0
-$ctxm add command \
+set ctxmw .vpane.lower.diff.body.ctxmw
+menu $ctxmw -tearoff 0
+$ctxmw add command \
-label [mc "Apply/Reverse Hunk"] \
-command {apply_hunk $cursorX $cursorY}
-set ui_diff_applyhunk [$ctxm index last]
-lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
-$ctxm add command \
+set ui_diff_applyhunk [$ctxmw index last]
+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyhunk -state]
+$ctxmw add command \
-label [mc "Apply/Reverse Line"] \
-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
-$ctxm add command \
+set ui_diff_applyline [$ctxmw index last]
+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyline -state]
+$ctxmw add separator
+$ctxmw add command \
+ -label [mc "Revert Hunk"] \
+ -command {apply_hunk $cursorX $cursorY 1}
+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyhunk -state]
+$ctxmw add command \
+ -label [mc "Revert Line"] \
+ -command {apply_range_or_line $cursorX $cursorY 1; do_rescan}
+set ui_diff_revertline [$ctxmw index last]
+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyline -state]
+$ctxmw add separator
+$ctxmw add command \
-label [mc "Show Less Context"] \
-command show_less_context
-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
-$ctxm add command \
+lappend diff_actions [list $ctxmw entryconf [$ctxmw index last] -state]
+$ctxmw add command \
-label [mc "Show More Context"] \
-command show_more_context
-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
-$ctxm add separator
-create_common_diff_popup $ctxm
+lappend diff_actions [list $ctxmw entryconf [$ctxmw index last] -state]
+$ctxmw add separator
+create_common_diff_popup $ctxmw
+
+set ctxmi .vpane.lower.diff.body.ctxmi
+menu $ctxmi -tearoff 0
+$ctxmi add command \
+ -label [mc "Apply/Reverse Hunk"] \
+ -command {apply_hunk $cursorX $cursorY}
+lappend diff_actions [list $ctxmi entryconf $ui_diff_applyhunk -state]
+$ctxmi add command \
+ -label [mc "Apply/Reverse Line"] \
+ -command {apply_range_or_line $cursorX $cursorY; do_rescan}
+lappend diff_actions [list $ctxmi entryconf $ui_diff_applyline -state]
+$ctxmi add separator
+$ctxmi add command \
+ -label [mc "Show Less Context"] \
+ -command show_less_context
+lappend diff_actions [list $ctxmi entryconf [$ctxmi index last] -state]
+$ctxmi add command \
+ -label [mc "Show More Context"] \
+ -command show_more_context
+lappend diff_actions [list $ctxmi entryconf [$ctxmi index last] -state]
+$ctxmi add separator
+create_common_diff_popup $ctxmi
set ctxmmg .vpane.lower.diff.body.ctxmmg
menu $ctxmmg -tearoff 0
@@ -3581,7 +3612,7 @@ proc has_textconv {path} {
}
}
-proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
+proc popup_diff_menu {ctxmw ctxmi ctxmmg ctxmsm x y X Y} {
global current_diff_path file_states
set ::cursorX $x
set ::cursorY $y
@@ -3597,6 +3628,7 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
} else {
set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
if {$::ui_index eq $::current_diff_side} {
+ set ctxm $ctxmi
set l [mc "Unstage Hunk From Commit"]
if {$has_range} {
set t [mc "Unstage Lines From Commit"]
@@ -3604,11 +3636,14 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
set t [mc "Unstage Line From Commit"]
}
} else {
+ set ctxm $ctxmw
set l [mc "Stage Hunk For Commit"]
if {$has_range} {
set t [mc "Stage Lines For Commit"]
+ set r [mc "Revert Lines"]
} else {
set t [mc "Stage Line For Commit"]
+ set r [mc "Revert Line"]
}
}
if {$::is_3way_diff
@@ -3624,10 +3659,13 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
}
$ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
$ctxm entryconf $::ui_diff_applyline -state $s -label $t
+ if {$::ui_workdir eq $::current_diff_side} {
+ $ctxm entryconf $::ui_diff_revertline -state $s -label $r
+ }
tk_popup $ctxm $X $Y
}
}
-bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
+bind_button3 $ui_diff [list popup_diff_menu $ctxmw $ctxmi $ctxmmg $ctxmsm %x %y %X %Y]
# -- Status Bar
#
diff --git a/lib/diff.tcl b/lib/diff.tcl
index a750ea7..83e6f6a 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -544,7 +544,7 @@ proc read_diff {fd conflict_size cont_info} {
}
}
-proc apply_hunk {x y} {
+proc apply_hunk {x y {revert 0}} {
global current_diff_path current_diff_header current_diff_side
global ui_diff ui_index file_states
@@ -561,7 +561,12 @@ proc apply_hunk {x y} {
return
}
} else {
- set failed_msg [mc "Failed to stage selected hunk."]
+ if {$revert} {
+ set failed_msg [mc "Failed to revert selected hunk."]
+ set apply_cmd {apply --reverse --whitespace=nowarn}
+ } else {
+ set failed_msg [mc "Failed to stage selected hunk."]
+ }
if {[string index $mi 1] ne {M}} {
unlock_index
return
@@ -604,6 +609,8 @@ proc apply_hunk {x y} {
if {$current_diff_side eq $ui_index} {
set mi ${o}M
+ } elseif {$revert} {
+ set mi "[string index $mi 0]$o"
} elseif {[string index $mi 0] eq {_}} {
set mi M$o
} else {
@@ -617,7 +624,7 @@ proc apply_hunk {x y} {
}
}
-proc apply_range_or_line {x y} {
+proc apply_range_or_line {x y {revert 0}} {
global current_diff_path current_diff_header current_diff_side
global ui_diff ui_index file_states
@@ -654,8 +661,14 @@ proc apply_range_or_line {x y} {
return
}
} else {
- set failed_msg [mc "Failed to stage selected line."]
- set to_context {-}
+ if {$revert} {
+ set failed_msg [mc "Failed to revert selected line."]
+ set apply_cmd {apply --reverse --whitespace=nowarn}
+ set to_context {+}
+ } else {
+ set failed_msg [mc "Failed to stage selected line."]
+ set to_context {-}
+ }
if {[string index $mi 1] ne {M}} {
unlock_index
return
--
1.7.8.1.873.gfea665
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] git-gui: fix hunk parsing for corner case changes
2012-01-09 13:43 [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
@ 2012-01-14 5:25 ` Bert Wesarg
1 sibling, 0 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-14 5:25 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
Hi Pat,
On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> The simple hunk parsing code did not recognize hunks when there is no
> second number after the comma. Like in these cases:
>
> @@ -1 +0,0 @@
> -1
>
> Which resulted in this hunk header:
>
> @@ -1 +0,1 +1 +0,0 @@
>
> Or:
>
> @@ -1 +1 @@
> -1
> +2
>
> Resulted in:
>
> @@ -1 +1 @@
> ,1 +1 +1 @@
> ,0 @@
>
> While trying to stage only the '-1' line.
>
could you please consider pushing this into the 1.7.9 release. I see
no point in waiting for the next release.
Thanks.
Bert
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-09 13:43 ` [RFC/PATCH 3/3] git-gui: support for reverting hunks and lines Bert Wesarg
@ 2012-01-14 5:26 ` Bert Wesarg
2012-01-14 7:00 ` Junio C Hamano
2012-01-14 12:08 ` Bert Wesarg
2 siblings, 1 reply; 8+ messages in thread
From: Bert Wesarg @ 2012-01-14 5:26 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
Hi Pat,
On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> Selecting also the trailing newline of a line for staging/unstaging would
> have resulted in also staging/unstaging of the next line.
>
same here, could you please consider pushing this into the 1.7.9
release. I see no point in waiting for the next release.
Thanks.
Bert
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line
2012-01-14 5:26 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
@ 2012-01-14 7:00 ` Junio C Hamano
2012-01-14 11:23 ` Bert Wesarg
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2012-01-14 7:00 UTC (permalink / raw)
To: Bert Wesarg; +Cc: Pat Thoyts, git
Bert Wesarg <bert.wesarg@googlemail.com> writes:
> On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
>> Selecting also the trailing newline of a line for staging/unstaging would
>> have resulted in also staging/unstaging of the next line.
>
> same here, could you please consider pushing this into the 1.7.9
> release. I see no point in waiting for the next release.
I do not use git-gui myself, so I wasn't paying much attention to these
two patches.
If these two fixes are for a new feature that was not present in v1.7.8
but has already been merged before v1.7.8-rc1, then do please make sure to
push them forward.
On the other hand, if they are fixes for an old feature that was already
in v1.7.8, then it is a bit too late for the next release.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line
2012-01-14 7:00 ` Junio C Hamano
@ 2012-01-14 11:23 ` Bert Wesarg
0 siblings, 0 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-14 11:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Pat Thoyts, git
On Sat, Jan 14, 2012 at 08:00, Junio C Hamano <gitster@pobox.com> wrote:
> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>
>> On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
>>> Selecting also the trailing newline of a line for staging/unstaging would
>>> have resulted in also staging/unstaging of the next line.
>>
>> same here, could you please consider pushing this into the 1.7.9
>> release. I see no point in waiting for the next release.
>
> I do not use git-gui myself, so I wasn't paying much attention to these
> two patches.
>
> If these two fixes are for a new feature that was not present in v1.7.8
> but has already been merged before v1.7.8-rc1, then do please make sure to
> push them forward.
>
> On the other hand, if they are fixes for an old feature that was already
> in v1.7.8, then it is a bit too late for the next release.
>
Thanks, considering this, than these two patches have to wait for the
next release.
Bert
> Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-09 13:43 ` [RFC/PATCH 3/3] git-gui: support for reverting hunks and lines Bert Wesarg
2012-01-14 5:26 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
@ 2012-01-14 12:08 ` Bert Wesarg
2 siblings, 0 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-01-14 12:08 UTC (permalink / raw)
To: Pat Thoyts; +Cc: git, Bert Wesarg
On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> Selecting also the trailing newline of a line for staging/unstaging would
> have resulted in also staging/unstaging of the next line.
The fix is not complete, this logic should only be applied if we have
actually a range. I will send a replacement patch in the coming days.
Bert
>
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
> lib/diff.tcl | 8 +++++++-
> 1 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/lib/diff.tcl b/lib/diff.tcl
> index 63f8742..a750ea7 100644
> --- a/lib/diff.tcl
> +++ b/lib/diff.tcl
> @@ -632,7 +632,13 @@ proc apply_range_or_line {x y} {
> }
>
> set first_l [$ui_diff index "$first linestart"]
> - set last_l [$ui_diff index "$last lineend"]
> + # don't include the next line if $last points to the start of a line
> + # ie. <lno>.0
> + if {[lindex [split $last .] 1] == 0} {
> + set last_l [$ui_diff index "$last -1 line lineend"]
> + } else {
> + set last_l [$ui_diff index "$last lineend"]
> + }
>
> if {$current_diff_path eq {} || $current_diff_header eq {}} return
> if {![lock_index apply_hunk]} return
> --
> 1.7.8.1.873.gfea665
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-01-14 12:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-09 13:43 [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
2012-01-09 13:43 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-09 13:43 ` [RFC/PATCH 3/3] git-gui: support for reverting hunks and lines Bert Wesarg
2012-01-14 5:26 ` [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line Bert Wesarg
2012-01-14 7:00 ` Junio C Hamano
2012-01-14 11:23 ` Bert Wesarg
2012-01-14 12:08 ` Bert Wesarg
2012-01-14 5:25 ` [PATCH 1/1] git-gui: fix hunk parsing for corner case changes Bert Wesarg
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).