MCPcopy Index your code
hub / github.com/go-git/go-git / filePatchWithContext

Function filePatchWithContext

plumbing/object/patch.go:49–97  ·  view source on GitHub ↗
(ctx context.Context, c *Change)

Source from the content-addressed store, hash-verified

47}
48
49func filePatchWithContext(ctx context.Context, c *Change) (fdiff.FilePatch, error) {
50 from, to, err := c.Files()
51 if err != nil {
52 return nil, err
53 }
54 fromContent, fIsBinary, err := fileContent(from)
55 if err != nil {
56 return nil, err
57 }
58
59 toContent, tIsBinary, err := fileContent(to)
60 if err != nil {
61 return nil, err
62 }
63
64 if fIsBinary || tIsBinary {
65 return &textFilePatch{from: c.From, to: c.To}, nil
66 }
67
68 diffs := diff.Do(fromContent, toContent)
69
70 var chunks []fdiff.Chunk
71 for _, d := range diffs {
72 select {
73 case <-ctx.Done():
74 return nil, ErrCanceled
75 default:
76 }
77
78 var op fdiff.Operation
79 switch d.Type {
80 case dmp.DiffEqual:
81 op = fdiff.Equal
82 case dmp.DiffDelete:
83 op = fdiff.Delete
84 case dmp.DiffInsert:
85 op = fdiff.Add
86 }
87
88 chunks = append(chunks, &textChunk{d.Text, op})
89 }
90
91 return &textFilePatch{
92 chunks: chunks,
93 from: c.From,
94 to: c.To,
95 }, nil
96
97}
98
99func fileContent(f *File) (content string, isBinary bool, err error) {
100 if f == nil {

Callers 1

getPatchContextFunction · 0.85

Calls 3

DoFunction · 0.92
fileContentFunction · 0.85
FilesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…