From: Jeff Epler <hidden> Date: 2016-06-15 22:47:35
Compared to the first version, I fixed a bug concerning staging line(s)
when all following lines are deletions (a preexisting bug in git-gui).
This version is made based off the master branch of git-gui.git, rather
than the master branch of git.git.
The first change fixes a long-standing git-gui bug in an area that the
new feature is rewriting anyway. If there's interest in the new feature
then maybe the two should just be squashed (using the message from the
second). If not, it'd be nice to see the bugfix applied anyway.
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 | 224 ++++++++++++++++++++++++++++++++--------------------------
2 files changed, 135 insertions(+), 104 deletions(-)
From: Jeff Epler <hidden> Date: 2016-06-15 22:47:35
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(-)
From: Jeff Epler <hidden> Date: 2016-06-15 22:47:35
---
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
commit block as well.
git-gui.sh | 15 +++-
lib/diff.tcl | 225 ++++++++++++++++++++++++++++++++--------------------------
2 files changed, 135 insertions(+), 105 deletions(-)
@@ -3194,7 +3194,7 @@ set ui_diff_applyhunk [$ctxm index last] lappenddiff_actions[list$ctxmentryconf$ui_diff_applyhunk-state]$ctxmaddcommand\-label[mc"Apply/Reverse Line"]\--command{apply_line$cursorX$cursorY;do_rescan}+-command{apply_range_or_line$cursorX$cursorY;do_rescan}setui_diff_applyline[$ctxmindexlast] lappenddiff_actions[list$ctxmentryconf$ui_diff_applyline-state]$ctxmaddseparator
@@ -3234,12 +3234,21 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {if{[stringfirst{U}$state]>=0}{tk_popup$ctxmmg$X$Y}else{+sethas_range[expr{[$::ui_difftagnextrangesel0.0]!={}}]if{$::ui_indexeq$::current_diff_side}{setl[mc"Unstage Hunk From Commit"]-sett[mc"Unstage Line From Commit"]+if{$has_range}{+sett[mc"Unstage Lines From Commit"]+}else{+sett[mc"Unstage Line From Commit"]+}}else{setl[mc"Stage Hunk For Commit"]-sett[mc"Stage Line For Commit"]+if{$has_range}{+sett[mc"Stage Lines For Commit"]+}else{+sett[mc"Stage Line For Commit"]+}}if{$::is_3way_diff||$::is_submodule_diff||$current_diff_patheq{}
@@ -559,120 +572,128 @@ proc apply_line {x y} {}}-setthe_l[$ui_diffindex@$x,$y]+setwholepatch{}-# operate only on change lines-setc1[$ui_diffget"$the_l linestart"]-if{$c1ne{+}&&$c1ne{-}}{-unlock_index-return-}-setsign$c1--seti_l[$ui_diffsearch-backwards-regexp^@@$the_l0.0]-if{$i_leq{}}{-unlock_index-return-}-# $i_l is now at the beginning of a line+while{$first_l<$last_l}{+seti_l[$ui_diffsearch-backwards-regexp^@@$first_l0.0]+if{$i_leq{}}{+# If there's not a @@ above, then the selected range+# must have come before the first_l @@+seti_l[$ui_diffsearch-regexp^@@$first_l$last_l]+}+if{$i_leq{}}{+unlock_index+return+}+# $i_l is now at the beginning of a line-# pick start line number from hunk header-sethh[$ui_diffget$i_l"$i_l + 1 lines"]-sethh[lindex[split$hh,]0]-sethln[lindex[split$hh-]1]+# pick start line number from hunk header+sethh[$ui_diffget$i_l"$i_l + 1 lines"]+sethh[lindex[split$hh,]0]+sethln[lindex[split$hh-]1]-# There is a special situation to take care of. Consider this hunk:-#-# @@ -10,4 +10,4 @@-# context before-# -old 1-# -old 2-# +new 1-# +new 2-# context after-#-# We used to keep the context lines in the order they appear in the-# hunk. But then it is not possible to correctly stage only-# "-old 1" and "+new 1" - it would result in this staged text:-#-# context before-# old 2-# new 1-# context after-#-# (By symmetry it is not possible to *un*stage "old 2" and "new 2".)-#-# We resolve the problem by introducing an asymmetry, namely, when-# a "+" line is *staged*, it is moved in front of the context lines-# that are generated from the "-" lines that are immediately before-# the "+" block. That is, we construct this patch:-#-# @@ -10,4 +10,5 @@-# context before-# +new 1-# old 1-# old 2-# context after-#-# But we do *not* treat "-" lines that are *un*staged in a special-# way.-#-# With this asymmetry it is possible to stage the change-# "old 1" -> "new 1" directly, and to stage the change-# "old 2" -> "new 2" by first staging the entire hunk and-# then unstaging the change "old 1" -> "new 1".--# This is non-empty if and only if we are _staging_ changes;-# then it accumulates the consecutive "-" lines (after converting-# them to context lines) in order to be moved after the "+" change-# line.-setpre_context{}--setn0-seti_l[$ui_diffindex"$i_l + 1 lines"]-setpatch{}-while{[$ui_diffcompare$i_l<"end - 1 chars"]&&-[$ui_diffget$i_l"$i_l + 2 chars"]ne{@@}}{-setnext_l[$ui_diffindex"$i_l + 1 lines"]-setc1[$ui_diffget$i_l]-if{[$ui_diffcompare$i_l<=$the_l]&&-[$ui_diffcompare$the_l<$next_l]}{-# the line to stage/unstage-setln[$ui_diffget$i_l$next_l]-if{$c1eq{-}}{-setn[expr$n+1]+# There is a special situation to take care of. Consider this+# hunk:+#+# @@ -10,4 +10,4 @@+# context before+# -old 1+# -old 2+# +new 1+# +new 2+# context after+#+# We used to keep the context lines in the order they appear in+# the hunk. But then it is not possible to correctly stage only+# "-old 1" and "+new 1" - it would result in this staged text:+#+# context before+# old 2+# new 1+# context after+#+# (By symmetry it is not possible to *un*stage "old 2" and "new+# 2".)+#+# We resolve the problem by introducing an asymmetry, namely,+# when a "+" line is *staged*, it is moved in front of the+# context lines that are generated from the "-" lines that are+# immediately before the "+" block. That is, we construct this+# patch:+#+# @@ -10,4 +10,5 @@+# context before+# +new 1+# old 1+# old 2+# context after+#+# But we do *not* treat "-" lines that are *un*staged in a+# special way.+#+# With this asymmetry it is possible to stage the change "old+# 1" -> "new 1" directly, and to stage the change "old 2" ->+# "new 2" by first staging the entire hunk and then unstaging+# the change "old 1" -> "new 1".++# This is non-empty if and only if we are _staging_ changes;+# then it accumulates the consecutive "-" lines (after+# converting them to context lines) in order to be moved after+# the "+" change line.+setpre_context{}++setn0+setm0+seti_l[$ui_diffindex"$i_l + 1 lines"]+setpatch{}+while{[$ui_diffcompare$i_l<"end - 1 chars"]&&+[$ui_diffget$i_l"$i_l + 2 chars"]ne{@@}}{+setnext_l[$ui_diffindex"$i_l + 1 lines"]+setc1[$ui_diffget$i_l]+if{[$ui_diffcompare$first_l<=$i_l]&&+[$ui_diffcompare$i_l<$last_l]&&+($c1eq{-}||$c1eq{+})}{+# a line to stage/unstage+setln[$ui_diffget$i_l$next_l]+if{$c1eq{-}}{+setn[expr$n+1]+setpatch"$patch$pre_context$ln"+}else{+setm[expr$m+1]+setpatch"$patch$ln$pre_context"+}+setpre_context{}+}elseif{$c1ne{-}&&$c1ne{+}}{+# context line+setln[$ui_diffget$i_l$next_l]setpatch"$patch$pre_context$ln"-}else{-setpatch"$patch$ln$pre_context"-}-setpre_context{}-}elseif{$c1ne{-}&&$c1ne{+}}{-# context line-setln[$ui_diffget$i_l$next_l]-setpatch"$patch$pre_context$ln"-setn[expr$n+1]-setpre_context{}-}elseif{$c1eq$to_context}{-# turn change line into context line-setln[$ui_diffget"$i_l + 1 chars"$next_l]-if{$c1eq{-}}{-setpre_context"$pre_context $ln"-}else{-setpatch"$patch $ln"+setn[expr$n+1]+setm[expr$m+1]+setpre_context{}+}elseif{$c1eq$to_context}{+# turn change line into context line+setln[$ui_diffget"$i_l + 1 chars"$next_l]+if{$c1eq{-}}{+setpre_context"$pre_context $ln"+}else{+setpatch"$patch $ln"+}+setn[expr$n+1]+setm[expr$m+1]}-setn[expr$n+1]+seti_l$next_l}-seti_l$next_l+setpatch"$patch$pre_context"+setwholepatch"$wholepatch@@ -$hln,$n +$hln,$m @@\n$patch"+setfirst_l[$ui_diffindex"$next_l + 1 lines"]}-setpatch"$patch$pre_context"-setpatch"@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"if{[catch{setenc[get_path_encoding$current_diff_path]setp[evalgit_write$apply_cmd]fconfigure$p-translationbinary-encoding$encputs-nonewline$p$current_diff_header-puts-nonewline$p$patch+puts-nonewline$p$wholepatchclose$p}err]}{error_popup[append$failed_msg"\n\n$err"]}
From: Jeff Epler <hidden> Date: 2016-06-15 22:47:36
I've found another problem, which I'll work on as soon as I find a
chance.
When staging multiple "+" lines preceded by a "-" line that must be
turned into context, the converted "-" line must come after *all* the
"+" lines, not just the first one.
Jeff
From: Peter Baumann <hidden> Date: 2016-06-15 22:47:38
On Wed, Oct 21, 2009 at 04:20:21PM -0500, Jeff Epler wrote:
Compared to the first version, I fixed a bug concerning staging line(s)
when all following lines are deletions (a preexisting bug in git-gui).
This version is made based off the master branch of git-gui.git, rather
than the master branch of git.git.
The first change fixes a long-standing git-gui bug in an area that the
new feature is rewriting anyway. If there's interest in the new feature
then maybe the two should just be squashed (using the message from the
second). If not, it'd be nice to see the bugfix applied anyway.
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 | 224 ++++++++++++++++++++++++++++++++--------------------------
2 files changed, 135 insertions(+), 104 deletions(-)
Hi,
On Thu, Oct 29, 2009 at 08:34:54AM +0100, Peter Baumann wrote:
On Wed, Oct 21, 2009 at 04:20:21PM -0500, Jeff Epler wrote:
quoted
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 | 224 ++++++++++++++++++++++++++++++++--------------------------
2 files changed, 135 insertions(+), 104 deletions(-)
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:47:50
Jeff Epler [off-list ref] wrote:
quoted hunk
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(-)
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:47:50
Jeff Epler [off-list ref] wrote:
I've found another problem, which I'll work on as soon as I find a
chance.
When staging multiple "+" lines preceded by a "-" line that must be
turned into context, the converted "-" line must come after *all* the
"+" lines, not just the first one.
So the reason this series got stuck was this message, this bug is
enough to suggest we shouldn't apply it to my tree yet, so I've
been waiting for an update on the topic.
Also, I need a Signed-off-by line.
--
Shawn.
On Sat, Dec 05, 2009 at 01:36:13PM -0800, Shawn O. Pearce wrote:
Jeff Epler [off-list ref] wrote:
quoted
I've found another problem, which I'll work on as soon as I find a
chance.
When staging multiple "+" lines preceded by a "-" line that must be
turned into context, the converted "-" line must come after *all* the
"+" lines, not just the first one.
So the reason this series got stuck was this message, this bug is
enough to suggest we shouldn't apply it to my tree yet, so I've
been waiting for an update on the topic.
In an attempt to help this series forward I tried to reproduce this bug
but were unsuccessfull. It seems that a change like this:
Thanks Jeff that was the missing piece. I was able to reproduce the
behavior and I can confirm it is gone with the new series. I was not yet
able to read through all of the code.
cheers Heiko