aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/diff/unified_encoder.go
diff options
context:
space:
mode:
authorTom Payne <twpayne@gmail.com>2020-04-29 04:15:25 +0100
committerTom Payne <twpayne@gmail.com>2020-04-30 02:47:49 +0100
commitaab967d28e8ece09c1d94241cb8da25be1e6b6cf (patch)
treeb47cd823381bf1d641da87bdb1e59a3891945e39 /plumbing/format/diff/unified_encoder.go
parentc7b6d19fba4a389926bdf6fcf74fb628d439c82c (diff)
downloadgo-git-aab967d28e8ece09c1d94241cb8da25be1e6b6cf.tar.gz
plumbing: diff, don't emit unnecessary resets
Diffstat (limited to 'plumbing/format/diff/unified_encoder.go')
-rw-r--r--plumbing/format/diff/unified_encoder.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go
index 6472db2..bd115f8 100644
--- a/plumbing/format/diff/unified_encoder.go
+++ b/plumbing/format/diff/unified_encoder.go
@@ -142,21 +142,21 @@ func (e *UnifiedEncoder) header(from, to File, isBinary bool) error {
e.pathLines(isBinary, aDir+from.Path(), bDir+to.Path())
}
- e.buf.WriteString(e.color.Reset())
+ e.buf.WriteString(e.color.Reset(Meta))
case from == nil:
e.buf.WriteString(e.color[Meta])
fmt.Fprintf(&e.buf, diffInit, to.Path(), to.Path())
fmt.Fprintf(&e.buf, newFileMode, to.Mode())
fmt.Fprintf(&e.buf, indexNoMode, plumbing.ZeroHash, to.Hash())
e.pathLines(isBinary, noFilePath, bDir+to.Path())
- e.buf.WriteString(e.color.Reset())
+ e.buf.WriteString(e.color.Reset(Meta))
case to == nil:
e.buf.WriteString(e.color[Meta])
fmt.Fprintf(&e.buf, diffInit, from.Path(), from.Path())
fmt.Fprintf(&e.buf, deletedFileMode, from.Mode())
fmt.Fprintf(&e.buf, indexNoMode, from.Hash(), plumbing.ZeroHash)
e.pathLines(isBinary, aDir+from.Path(), noFilePath)
- e.buf.WriteString(e.color.Reset())
+ e.buf.WriteString(e.color.Reset(Meta))
}
return nil
@@ -338,13 +338,13 @@ func (c *hunk) WriteTo(buf *bytes.Buffer, color ColorConfig) {
}
buf.WriteString(chunkEnd)
- buf.WriteString(color.Reset())
+ buf.WriteString(color.Reset(Frag))
if c.ctxPrefix != "" {
buf.WriteByte(' ')
buf.WriteString(color[Func])
buf.WriteString(c.ctxPrefix)
- buf.WriteString(color.Reset())
+ buf.WriteString(color.Reset(Func))
}
buf.WriteByte('\n')
@@ -377,22 +377,23 @@ type op struct {
}
func (o *op) String(color ColorConfig) string {
- var setColor, prefix, suffix string
+ var prefix, suffix string
+ var colorKey ColorKey
switch o.t {
case Add:
prefix = addLine
- setColor = color[New]
+ colorKey = New
case Delete:
prefix = deleteLine
- setColor = color[Old]
+ colorKey = Old
case Equal:
prefix = equalLine
- setColor = color[Context]
+ colorKey = Context
}
n := len(o.text)
if n > 0 && o.text[n-1] != '\n' {
suffix = noNewLine
}
- return fmt.Sprintf(prefix, setColor, o.text, color.Reset(), suffix)
+ return fmt.Sprintf(prefix, color[colorKey], o.text, color.Reset(colorKey), suffix)
}