Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 886dc83

Browse files
authored
Merge pull request #749 from irias/master
plumbing: diff, fix crash when a small ending equal-chunk
2 parents 638e0d2 + 9720a5f commit 886dc83

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Diff for: plumbing/format/diff/unified_encoder.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,15 @@ func (c *hunksGenerator) processEqualsLines(ls []string, i int) {
262262
c.current.AddOp(Equal, c.afterContext...)
263263
c.afterContext = nil
264264
} else {
265-
c.current.AddOp(Equal, c.afterContext[:c.ctxLines]...)
265+
ctxLines := c.ctxLines
266+
if ctxLines > len(c.afterContext) {
267+
ctxLines = len(c.afterContext)
268+
}
269+
c.current.AddOp(Equal, c.afterContext[:ctxLines]...)
266270
c.hunks = append(c.hunks, c.current)
267271

268272
c.current = nil
269-
c.beforeContext = c.afterContext[c.ctxLines:]
273+
c.beforeContext = c.afterContext[ctxLines:]
270274
c.afterContext = nil
271275
}
272276
}

Diff for: plumbing/format/diff/unified_encoder_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,43 @@ index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb0
475475
V
476476
W
477477
`,
478+
}, {
479+
patch: oneChunkPatch,
480+
desc: "modified deleting lines file with context to 6",
481+
context: 6,
482+
diff: `diff --git a/onechunk.txt b/onechunk.txt
483+
index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb06c417c82 100644
484+
--- a/onechunk.txt
485+
+++ b/onechunk.txt
486+
@@ -1,27 +1,23 @@
487+
-A
488+
B
489+
C
490+
D
491+
E
492+
F
493+
G
494+
-H
495+
I
496+
J
497+
K
498+
L
499+
M
500+
N
501+
502+
O
503+
P
504+
Q
505+
R
506+
S
507+
T
508+
-U
509+
V
510+
W
511+
X
512+
Y
513+
Z
514+
`,
478515
}, {
479516
patch: oneChunkPatch,
480517

0 commit comments

Comments
 (0)