Skip to content

Commit

Permalink
Merge pull request src-d#749 from irias/master
Browse files Browse the repository at this point in the history
plumbing: diff, fix crash when a small ending equal-chunk
  • Loading branch information
mcuadros committed Feb 17, 2018
2 parents 638e0d2 + 9720a5f commit 886dc83
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plumbing/format/diff/unified_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,15 @@ func (c *hunksGenerator) processEqualsLines(ls []string, i int) {
c.current.AddOp(Equal, c.afterContext...)
c.afterContext = nil
} else {
c.current.AddOp(Equal, c.afterContext[:c.ctxLines]...)
ctxLines := c.ctxLines
if ctxLines > len(c.afterContext) {
ctxLines = len(c.afterContext)
}
c.current.AddOp(Equal, c.afterContext[:ctxLines]...)
c.hunks = append(c.hunks, c.current)

c.current = nil
c.beforeContext = c.afterContext[c.ctxLines:]
c.beforeContext = c.afterContext[ctxLines:]
c.afterContext = nil
}
}
Expand Down
37 changes: 37 additions & 0 deletions plumbing/format/diff/unified_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,43 @@ index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb0
V
W
`,
}, {
patch: oneChunkPatch,
desc: "modified deleting lines file with context to 6",
context: 6,
diff: `diff --git a/onechunk.txt b/onechunk.txt
index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb06c417c82 100644
--- a/onechunk.txt
+++ b/onechunk.txt
@@ -1,27 +1,23 @@
-A
B
C
D
E
F
G
-H
I
J
K
L
M
N
O
P
Q
R
S
T
-U
V
W
X
Y
Z
`,
}, {
patch: oneChunkPatch,

Expand Down

0 comments on commit 886dc83

Please sign in to comment.