git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] git-gui: Fix "Stage/Unstage Line" with one line of context.
@ 2008-07-15 21:11 Johannes Sixt
  2008-07-15 21:11 ` [PATCH 2/2] git-gui: Allow "Stage Line" to stage adjacent changes independently Johannes Sixt
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Sixt @ 2008-07-15 21:11 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git, Johannes Sixt

To "Stage/Unstage Line" we construct a patch that contains exactly one
change (either addition or removal); the hunk header was forged by counting
the old side and adjusting the count by +/-1 for the new side. But when we
counted the context we never counted the changed line itself. If the hunk
had only one removal line and one line of context, like this:

    @@ -1,3 +1,2 @@
     context 1
    -removal
     context 2

We had constructed this patch:

    @@ -1,2 +1,1 @@
     context 1
    -removal
     context 2

which does not apply because git apply deduces that it must apply at the
end of the file. ("context 2" is considered garbage and ignored.) The fix
is that removal lines must be counted towards the context of the old side.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 lib/diff.tcl |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/diff.tcl b/lib/diff.tcl
index 96ba949..ee7f391 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -423,6 +423,9 @@ proc apply_line {x y} {
 			# the line to stage/unstage
 			set ln [$ui_diff get $i_l $next_l]
 			set patch "$patch$ln"
+			if {$c1 eq {-}} {
+				set n [expr $n+1]
+			}
 		} elseif {$c1 ne {-} && $c1 ne {+}} {
 			# context line
 			set ln [$ui_diff get $i_l $next_l]
-- 
1.5.6.3.323.g1e58

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-07-18  6:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-15 21:11 [PATCH 1/2] git-gui: Fix "Stage/Unstage Line" with one line of context Johannes Sixt
2008-07-15 21:11 ` [PATCH 2/2] git-gui: Allow "Stage Line" to stage adjacent changes independently Johannes Sixt
2008-07-15 21:49   ` Junio C Hamano
2008-07-16  0:35     ` Shawn O. Pearce
2008-07-17 13:21       ` [PATCH 2/2 v2] git-gui: "Stage Line": Treat independent changes in adjacent lines better Johannes Sixt
2008-07-18  6:21         ` Junio C Hamano
2008-07-16  7:15     ` [PATCH 2/2] git-gui: Allow "Stage Line" to stage adjacent changes independently Johannes Sixt

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).