aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/diff/unified_encoder.go
diff options
context:
space:
mode:
authorTom Payne <twpayne@gmail.com>2020-04-29 03:47:19 +0100
committerTom Payne <twpayne@gmail.com>2020-04-29 04:08:02 +0100
commit9f7a8726be44235a65a1f2cee18b4fa4f56341fe (patch)
treedc06f8cdc28ddf687d1915e3a0995657070c4dc5 /plumbing/format/diff/unified_encoder.go
parent06dad218498f62255799d03dc6411dba481ce71b (diff)
downloadgo-git-9f7a8726be44235a65a1f2cee18b4fa4f56341fe.tar.gz
plumbing: diff, fix coloring of hunk context
Diffstat (limited to 'plumbing/format/diff/unified_encoder.go')
-rw-r--r--plumbing/format/diff/unified_encoder.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go
index 7b0c31e..6472db2 100644
--- a/plumbing/format/diff/unified_encoder.go
+++ b/plumbing/format/diff/unified_encoder.go
@@ -15,7 +15,7 @@ const (
chunkStart = "@@ -"
chunkMiddle = " +"
- chunkEnd = " @@%s\n"
+ chunkEnd = " @@"
chunkCount = "%d,%d"
noFilePath = "/dev/null"
@@ -230,7 +230,7 @@ func (c *hunksGenerator) processHunk(i int, op Operation) {
var ctxPrefix string
linesBefore := len(c.beforeContext)
if linesBefore > c.ctxLines {
- ctxPrefix = " " + c.beforeContext[linesBefore-c.ctxLines-1]
+ ctxPrefix = c.beforeContext[linesBefore-c.ctxLines-1]
c.beforeContext = c.beforeContext[linesBefore-c.ctxLines:]
linesBefore = c.ctxLines
}
@@ -337,9 +337,18 @@ func (c *hunk) WriteTo(buf *bytes.Buffer, color ColorConfig) {
fmt.Fprintf(buf, chunkCount, c.toLine, c.toCount)
}
- fmt.Fprintf(buf, chunkEnd, c.ctxPrefix)
+ buf.WriteString(chunkEnd)
buf.WriteString(color.Reset())
+ if c.ctxPrefix != "" {
+ buf.WriteByte(' ')
+ buf.WriteString(color[Func])
+ buf.WriteString(c.ctxPrefix)
+ buf.WriteString(color.Reset())
+ }
+
+ buf.WriteByte('\n')
+
for _, d := range c.ops {
buf.WriteString(d.String(color))
}