{"thread":{"id":"29321","subject":"[PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","startedAt":"2012-01-09T13:43:17Z","lastAt":"2012-01-14T12:08:37Z","messageCount":8,"participants":["Bert Wesarg","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"182161","messageId":"cccd6193cf3bfe170e14270204d735a842bb8563.1326116492.git.bert.wesarg@googlemail.com","threadId":"29321","inReplyTo":null,"subject":"[PATCH 1/1] git-gui: fix hunk parsing for corner case changes","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-09T13:43:17Z","receivedAt":"2012-01-09T13:43:17Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"The simple hunk parsing code did not recognize hunks when there is no\nsecond number after the comma. Like in these cases:\n\n  @@ -1 +0,0 @@\n  -1\n\nWhich resulted in this hunk header:\n\n  @@ -1 +0,1 +1 +0,0 @@\n\nOr:\n\n  @@ -1 +1 @@\n  -1\n  +2\n\nResulted in:\n\n  @@ -1 +1 @@\n  ,1 +1 +1 @@\n  ,0 @@\n\nWhile trying to stage only the '-1' line.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n---\n lib/diff.tcl |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex ec44055..63f8742 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -672,9 +672,11 @@ proc apply_range_or_line {x y} {\n \t\t# $i_l is now at the beginning of a line\n \n \t\t# pick start line number from hunk header\n-\t\tset hh [$ui_diff get $i_l \"$i_l + 1 lines\"]\n-\t\tset hh [lindex [split $hh ,] 0]\n-\t\tset hln [lindex [split $hh -] 1]\n+\t\tif {![regexp {^@@ -(\\d+)(?:,\\d+)? \\+(?:\\d+)(?:,\\d+)? @@(?:\\s|$)} \\\n+\t\t\t[$ui_diff get $i_l \"$i_l + 1 lines\"] hh hln]} {\n+\t\t\tunlock_index\n+\t\t\treturn\n+\t\t}\n \n \t\t# There is a special situation to take care of. Consider this\n \t\t# hunk:\n-- \n1.7.8.1.873.gfea665\n"},{"id":"182160","messageId":"37339be035746797fcec7634e3560ffcd5b26cf3.1326116492.git.bert.wesarg@googlemail.com","threadId":"29321","inReplyTo":"cccd6193cf3bfe170e14270204d735a842bb8563.1326116492.git.bert.wesarg@googlemail.com","subject":"[PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-09T13:43:18Z","receivedAt":"2012-01-09T13:43:18Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Selecting also the trailing newline of a line for staging/unstaging would\nhave resulted in also staging/unstaging of the next line.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n---\n lib/diff.tcl |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex 63f8742..a750ea7 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -632,7 +632,13 @@ proc apply_range_or_line {x y} {\n \t}\n \n \tset first_l [$ui_diff index \"$first linestart\"]\n-\tset last_l [$ui_diff index \"$last lineend\"]\n+\t# don't include the next line if $last points to the start of a line\n+\t# ie. <lno>.0\n+\tif {[lindex [split $last .] 1] == 0} {\n+\t\tset last_l [$ui_diff index \"$last -1 line lineend\"]\n+\t} else {\n+\t\tset last_l [$ui_diff index \"$last lineend\"]\n+\t}\n \n \tif {$current_diff_path eq {} || $current_diff_header eq {}} return\n \tif {![lock_index apply_hunk]} return\n-- \n1.7.8.1.873.gfea665\n"},{"id":"182162","messageId":"a9ba4550a29d7f3c653561e7029f0920bf8eb008.1326116492.git.bert.wesarg@googlemail.com","threadId":"29321","inReplyTo":"37339be035746797fcec7634e3560ffcd5b26cf3.1326116492.git.bert.wesarg@googlemail.com","subject":"[RFC/PATCH 3/3] git-gui: support for reverting hunks and lines","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-09T13:43:19Z","receivedAt":"2012-01-09T13:43:19Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n---\n git-gui.sh   |  106 +++++++++++++++++++++++++++++++++++++++------------------\n lib/diff.tcl |   23 ++++++++++---\n 2 files changed, 90 insertions(+), 39 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex ba4e5c1..955cbf8 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -3289,36 +3289,35 @@ pack .vpane.lower.commarea.buffer -side left -fill y\n \n # -- Commit Message Buffer Context Menu\n #\n-set ctxm .vpane.lower.commarea.buffer.ctxm\n-menu $ctxm -tearoff 0\n-$ctxm add command \\\n+set ui_comm_ctxm .vpane.lower.commarea.buffer.ctxm\n+menu $ui_comm_ctxm -tearoff 0\n+$ui_comm_ctxm add command \\\n \t-label [mc Cut] \\\n \t-command {tk_textCut $ui_comm}\n-$ctxm add command \\\n+$ui_comm_ctxm add command \\\n \t-label [mc Copy] \\\n \t-command {tk_textCopy $ui_comm}\n-$ctxm add command \\\n+$ui_comm_ctxm add command \\\n \t-label [mc Paste] \\\n \t-command {tk_textPaste $ui_comm}\n-$ctxm add command \\\n+$ui_comm_ctxm add command \\\n \t-label [mc Delete] \\\n \t-command {catch {$ui_comm delete sel.first sel.last}}\n-$ctxm add separator\n-$ctxm add command \\\n+$ui_comm_ctxm add separator\n+$ui_comm_ctxm add command \\\n \t-label [mc \"Select All\"] \\\n \t-command {focus $ui_comm;$ui_comm tag add sel 0.0 end}\n-$ctxm add command \\\n+$ui_comm_ctxm add command \\\n \t-label [mc \"Copy All\"] \\\n \t-command {\n \t\t$ui_comm tag add sel 0.0 end\n \t\ttk_textCopy $ui_comm\n \t\t$ui_comm tag remove sel 0.0 end\n \t}\n-$ctxm add separator\n-$ctxm add command \\\n+$ui_comm_ctxm add separator\n+$ui_comm_ctxm add command \\\n \t-label [mc \"Sign Off\"] \\\n \t-command do_signoff\n-set ui_comm_ctxm $ctxm\n \n # -- Diff Header\n #\n@@ -3366,9 +3365,9 @@ tlabel .vpane.lower.diff.header.path \\\n pack .vpane.lower.diff.header.status -side left\n pack .vpane.lower.diff.header.file -side left\n pack .vpane.lower.diff.header.path -fill x\n-set ctxm .vpane.lower.diff.header.ctxm\n-menu $ctxm -tearoff 0\n-$ctxm add command \\\n+set hctxm .vpane.lower.diff.header.ctxm\n+menu $hctxm -tearoff 0\n+$hctxm add command \\\n \t-label [mc Copy] \\\n \t-command {\n \t\tclipboard clear\n@@ -3377,8 +3376,8 @@ $ctxm add command \\\n \t\t\t-type STRING \\\n \t\t\t-- $current_diff_path\n \t}\n-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]\n-bind_button3 .vpane.lower.diff.header.path \"tk_popup $ctxm %X %Y\"\n+lappend diff_actions [list $hctxm entryconf [$hctxm index last] -state]\n+bind_button3 .vpane.lower.diff.header.path \"tk_popup $hctxm %X %Y\"\n \n # -- Diff Body\n #\n@@ -3491,29 +3490,61 @@ proc create_common_diff_popup {ctxm} {\n \t\t-command do_options\n }\n \n-set ctxm .vpane.lower.diff.body.ctxm\n-menu $ctxm -tearoff 0\n-$ctxm add command \\\n+set ctxmw .vpane.lower.diff.body.ctxmw\n+menu $ctxmw -tearoff 0\n+$ctxmw add command \\\n \t-label [mc \"Apply/Reverse Hunk\"] \\\n \t-command {apply_hunk $cursorX $cursorY}\n-set ui_diff_applyhunk [$ctxm index last]\n-lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]\n-$ctxm add command \\\n+set ui_diff_applyhunk [$ctxmw index last]\n+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyhunk -state]\n+$ctxmw add command \\\n \t-label [mc \"Apply/Reverse Line\"] \\\n \t-command {apply_range_or_line $cursorX $cursorY; do_rescan}\n-set ui_diff_applyline [$ctxm index last]\n-lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]\n-$ctxm add separator\n-$ctxm add command \\\n+set ui_diff_applyline [$ctxmw index last]\n+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyline -state]\n+$ctxmw add separator\n+$ctxmw add command \\\n+\t-label [mc \"Revert Hunk\"] \\\n+\t-command {apply_hunk $cursorX $cursorY 1}\n+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyhunk -state]\n+$ctxmw add command \\\n+\t-label [mc \"Revert Line\"] \\\n+\t-command {apply_range_or_line $cursorX $cursorY 1; do_rescan}\n+set ui_diff_revertline [$ctxmw index last]\n+lappend diff_actions [list $ctxmw entryconf $ui_diff_applyline -state]\n+$ctxmw add separator\n+$ctxmw add command \\\n \t-label [mc \"Show Less Context\"] \\\n \t-command show_less_context\n-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]\n-$ctxm add command \\\n+lappend diff_actions [list $ctxmw entryconf [$ctxmw index last] -state]\n+$ctxmw add command \\\n \t-label [mc \"Show More Context\"] \\\n \t-command show_more_context\n-lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]\n-$ctxm add separator\n-create_common_diff_popup $ctxm\n+lappend diff_actions [list $ctxmw entryconf [$ctxmw index last] -state]\n+$ctxmw add separator\n+create_common_diff_popup $ctxmw\n+\n+set ctxmi .vpane.lower.diff.body.ctxmi\n+menu $ctxmi -tearoff 0\n+$ctxmi add command \\\n+\t-label [mc \"Apply/Reverse Hunk\"] \\\n+\t-command {apply_hunk $cursorX $cursorY}\n+lappend diff_actions [list $ctxmi entryconf $ui_diff_applyhunk -state]\n+$ctxmi add command \\\n+\t-label [mc \"Apply/Reverse Line\"] \\\n+\t-command {apply_range_or_line $cursorX $cursorY; do_rescan}\n+lappend diff_actions [list $ctxmi entryconf $ui_diff_applyline -state]\n+$ctxmi add separator\n+$ctxmi add command \\\n+\t-label [mc \"Show Less Context\"] \\\n+\t-command show_less_context\n+lappend diff_actions [list $ctxmi entryconf [$ctxmi index last] -state]\n+$ctxmi add command \\\n+\t-label [mc \"Show More Context\"] \\\n+\t-command show_more_context\n+lappend diff_actions [list $ctxmi entryconf [$ctxmi index last] -state]\n+$ctxmi add separator\n+create_common_diff_popup $ctxmi\n \n set ctxmmg .vpane.lower.diff.body.ctxmmg\n menu $ctxmmg -tearoff 0\n@@ -3581,7 +3612,7 @@ proc has_textconv {path} {\n \t}\n }\n \n-proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {\n+proc popup_diff_menu {ctxmw ctxmi ctxmmg ctxmsm x y X Y} {\n \tglobal current_diff_path file_states\n \tset ::cursorX $x\n \tset ::cursorY $y\n@@ -3597,6 +3628,7 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {\n \t} else {\n \t\tset has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]\n \t\tif {$::ui_index eq $::current_diff_side} {\n+\t\t\tset ctxm $ctxmi\n \t\t\tset l [mc \"Unstage Hunk From Commit\"]\n \t\t\tif {$has_range} {\n \t\t\t\tset t [mc \"Unstage Lines From Commit\"]\n@@ -3604,11 +3636,14 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {\n \t\t\t\tset t [mc \"Unstage Line From Commit\"]\n \t\t\t}\n \t\t} else {\n+\t\t\tset ctxm $ctxmw\n \t\t\tset l [mc \"Stage Hunk For Commit\"]\n \t\t\tif {$has_range} {\n \t\t\t\tset t [mc \"Stage Lines For Commit\"]\n+\t\t\t\tset r [mc \"Revert Lines\"]\n \t\t\t} else {\n \t\t\t\tset t [mc \"Stage Line For Commit\"]\n+\t\t\t\tset r [mc \"Revert Line\"]\n \t\t\t}\n \t\t}\n \t\tif {$::is_3way_diff\n@@ -3624,10 +3659,13 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {\n \t\t}\n \t\t$ctxm entryconf $::ui_diff_applyhunk -state $s -label $l\n \t\t$ctxm entryconf $::ui_diff_applyline -state $s -label $t\n+\t\tif {$::ui_workdir eq $::current_diff_side} {\n+\t\t\t$ctxm entryconf $::ui_diff_revertline -state $s -label $r\n+\t\t}\n \t\ttk_popup $ctxm $X $Y\n \t}\n }\n-bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]\n+bind_button3 $ui_diff [list popup_diff_menu $ctxmw $ctxmi $ctxmmg $ctxmsm %x %y %X %Y]\n \n # -- Status Bar\n #\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex a750ea7..83e6f6a 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -544,7 +544,7 @@ proc read_diff {fd conflict_size cont_info} {\n \t}\n }\n \n-proc apply_hunk {x y} {\n+proc apply_hunk {x y {revert 0}} {\n \tglobal current_diff_path current_diff_header current_diff_side\n \tglobal ui_diff ui_index file_states\n \n@@ -561,7 +561,12 @@ proc apply_hunk {x y} {\n \t\t\treturn\n \t\t}\n \t} else {\n-\t\tset failed_msg [mc \"Failed to stage selected hunk.\"]\n+\t\tif {$revert} {\n+\t\t\tset failed_msg [mc \"Failed to revert selected hunk.\"]\n+\t\t\tset apply_cmd {apply --reverse --whitespace=nowarn}\n+\t\t} else {\n+\t\t\tset failed_msg [mc \"Failed to stage selected hunk.\"]\n+\t\t}\n \t\tif {[string index $mi 1] ne {M}} {\n \t\t\tunlock_index\n \t\t\treturn\n@@ -604,6 +609,8 @@ proc apply_hunk {x y} {\n \n \tif {$current_diff_side eq $ui_index} {\n \t\tset mi ${o}M\n+\t} elseif {$revert} {\n+\t\tset mi \"[string index $mi 0]$o\"\n \t} elseif {[string index $mi 0] eq {_}} {\n \t\tset mi M$o\n \t} else {\n@@ -617,7 +624,7 @@ proc apply_hunk {x y} {\n \t}\n }\n \n-proc apply_range_or_line {x y} {\n+proc apply_range_or_line {x y {revert 0}} {\n \tglobal current_diff_path current_diff_header current_diff_side\n \tglobal ui_diff ui_index file_states\n \n@@ -654,8 +661,14 @@ proc apply_range_or_line {x y} {\n \t\t\treturn\n \t\t}\n \t} else {\n-\t\tset failed_msg [mc \"Failed to stage selected line.\"]\n-\t\tset to_context {-}\n+\t\tif {$revert} {\n+\t\t\tset failed_msg [mc \"Failed to revert selected line.\"]\n+\t\t\tset apply_cmd {apply --reverse --whitespace=nowarn}\n+\t\t\tset to_context {+}\n+\t\t} else {\n+\t\t\tset failed_msg [mc \"Failed to stage selected line.\"]\n+\t\t\tset to_context {-}\n+\t\t}\n \t\tif {[string index $mi 1] ne {M}} {\n \t\t\tunlock_index\n \t\t\treturn\n-- \n1.7.8.1.873.gfea665\n"},{"id":"182532","messageId":"CAKPyHN3dp_t+hVsX_dBB8OnU=oM2t1DsdKFDghD7L9qAEtYgfg@mail.gmail.com","threadId":"29321","inReplyTo":"cccd6193cf3bfe170e14270204d735a842bb8563.1326116492.git.bert.wesarg@googlemail.com","subject":"Re: [PATCH 1/1] git-gui: fix hunk parsing for corner case changes","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-14T05:25:28Z","receivedAt":"2012-01-14T05:25:28Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Hi Pat,\n\nOn Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n> The simple hunk parsing code did not recognize hunks when there is no\n> second number after the comma. Like in these cases:\n>\n>  @@ -1 +0,0 @@\n>  -1\n>\n> Which resulted in this hunk header:\n>\n>  @@ -1 +0,1 +1 +0,0 @@\n>\n> Or:\n>\n>  @@ -1 +1 @@\n>  -1\n>  +2\n>\n> Resulted in:\n>\n>  @@ -1 +1 @@\n>  ,1 +1 +1 @@\n>  ,0 @@\n>\n> While trying to stage only the '-1' line.\n>\n\ncould you please consider pushing this into the 1.7.9 release. I see\nno point in waiting for the next release.\n\nThanks.\n\nBert\n"},{"id":"182533","messageId":"CAKPyHN0tqQKuPONj_F9MXbgoHxeoZ7pFVSLPNWHddnA8340MGA@mail.gmail.com","threadId":"29321","inReplyTo":"37339be035746797fcec7634e3560ffcd5b26cf3.1326116492.git.bert.wesarg@googlemail.com","subject":"Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-14T05:26:14Z","receivedAt":"2012-01-14T05:26:14Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Hi Pat,\n\nOn Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n> Selecting also the trailing newline of a line for staging/unstaging would\n> have resulted in also staging/unstaging of the next line.\n>\n\nsame here, could you please consider pushing this into the 1.7.9\nrelease. I see no point in waiting for the next release.\n\nThanks.\n\nBert\n"},{"id":"182535","messageId":"7vaa5qydj7.fsf@alter.siamese.dyndns.org","threadId":"29321","inReplyTo":"CAKPyHN0tqQKuPONj_F9MXbgoHxeoZ7pFVSLPNWHddnA8340MGA@mail.gmail.com","subject":"Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-14T07:00:12Z","receivedAt":"2012-01-14T07:00:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bert Wesarg <bert.wesarg@googlemail.com> writes:\n\n> On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n>> Selecting also the trailing newline of a line for staging/unstaging would\n>> have resulted in also staging/unstaging of the next line.\n>\n> same here, could you please consider pushing this into the 1.7.9\n> release. I see no point in waiting for the next release.\n\nI do not use git-gui myself, so I wasn't paying much attention to these\ntwo patches.\n\nIf these two fixes are for a new feature that was not present in v1.7.8\nbut has already been merged before v1.7.8-rc1, then do please make sure to\npush them forward.\n\nOn the other hand, if they are fixes for an old feature that was already\nin v1.7.8, then it is a bit too late for the next release.\n\nThanks.\n"},{"id":"182543","messageId":"CAKPyHN0Mj-cus5WWDpHG_mtWJhe6_4hxEzSn6pk0a88hytgVVg@mail.gmail.com","threadId":"29321","inReplyTo":"7vaa5qydj7.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-14T11:23:34Z","receivedAt":"2012-01-14T11:23:34Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Sat, Jan 14, 2012 at 08:00, Junio C Hamano <gitster@pobox.com> wrote:\n> Bert Wesarg <bert.wesarg@googlemail.com> writes:\n>\n>> On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n>>> Selecting also the trailing newline of a line for staging/unstaging would\n>>> have resulted in also staging/unstaging of the next line.\n>>\n>> same here, could you please consider pushing this into the 1.7.9\n>> release. I see no point in waiting for the next release.\n>\n> I do not use git-gui myself, so I wasn't paying much attention to these\n> two patches.\n>\n> If these two fixes are for a new feature that was not present in v1.7.8\n> but has already been merged before v1.7.8-rc1, then do please make sure to\n> push them forward.\n>\n> On the other hand, if they are fixes for an old feature that was already\n> in v1.7.8, then it is a bit too late for the next release.\n>\n\nThanks, considering this, than these two patches have to wait for the\nnext release.\n\nBert\n\n> Thanks.\n"},{"id":"182546","messageId":"CAKPyHN1CQ4nHDSgsd2862_AugsDR6m1BcZ+rgOkPJr4E6eYaEA@mail.gmail.com","threadId":"29321","inReplyTo":"37339be035746797fcec7634e3560ffcd5b26cf3.1326116492.git.bert.wesarg@googlemail.com","subject":"Re: [PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2012-01-14T12:08:37Z","receivedAt":"2012-01-14T12:08:37Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Mon, Jan 9, 2012 at 14:43, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n> Selecting also the trailing newline of a line for staging/unstaging would\n> have resulted in also staging/unstaging of the next line.\n\nThe fix is not complete, this logic should only be applied if we have\nactually a range. I will send a replacement patch in the coming days.\n\nBert\n\n>\n> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n> ---\n>  lib/diff.tcl |    8 +++++++-\n>  1 files changed, 7 insertions(+), 1 deletions(-)\n>\n> diff --git a/lib/diff.tcl b/lib/diff.tcl\n> index 63f8742..a750ea7 100644\n> --- a/lib/diff.tcl\n> +++ b/lib/diff.tcl\n> @@ -632,7 +632,13 @@ proc apply_range_or_line {x y} {\n>        }\n>\n>        set first_l [$ui_diff index \"$first linestart\"]\n> -       set last_l [$ui_diff index \"$last lineend\"]\n> +       # don't include the next line if $last points to the start of a line\n> +       # ie. <lno>.0\n> +       if {[lindex [split $last .] 1] == 0} {\n> +               set last_l [$ui_diff index \"$last -1 line lineend\"]\n> +       } else {\n> +               set last_l [$ui_diff index \"$last lineend\"]\n> +       }\n>\n>        if {$current_diff_path eq {} || $current_diff_header eq {}} return\n>        if {![lock_index apply_hunk]} return\n> --\n> 1.7.8.1.873.gfea665\n>\n"}]}