MCPcopy
hub / github.com/go-git/go-git / Encode

Method Encode

plumbing/format/diff/unified_encoder.go:78–98  ·  view source on GitHub ↗

Encode encodes patch.

(patch Patch)

Source from the content-addressed store, hash-verified

76
77// Encode encodes patch.
78func (e *UnifiedEncoder) Encode(patch Patch) error {
79 sb := &strings.Builder{}
80
81 if message := patch.Message(); message != "" {
82 sb.WriteString(message)
83 if !strings.HasSuffix(message, "\n") {
84 sb.WriteByte('\n')
85 }
86 }
87
88 for _, filePatch := range patch.FilePatches() {
89 e.writeFilePatchHeader(sb, filePatch)
90 g := newHunksGenerator(filePatch.Chunks(), e.contextLines)
91 for _, hunk := range g.Generate() {
92 hunk.writeTo(sb, e.color)
93 }
94 }
95
96 _, err := e.Write([]byte(sb.String()))
97 return err
98}
99
100func (e *UnifiedEncoder) writeFilePatchHeader(sb *strings.Builder, filePatch FilePatch) {
101 from, to := filePatch.Files()

Callers 3

EncodeMethod · 0.95
TestBothFilesEmptyMethod · 0.95
TestBinaryFileMethod · 0.95

Calls 9

writeFilePatchHeaderMethod · 0.95
newHunksGeneratorFunction · 0.85
GenerateMethod · 0.80
MessageMethod · 0.65
FilePatchesMethod · 0.65
ChunksMethod · 0.65
StringMethod · 0.65
writeToMethod · 0.45
WriteMethod · 0.45

Tested by 2

TestBothFilesEmptyMethod · 0.76
TestBinaryFileMethod · 0.76