MCPcopy Create free account
hub / github.com/bluekeyes/patch2pr / applyModify

Method applyModify

graphql_applier.go:159–184  ·  view source on GitHub ↗
(ctx context.Context, f *gitdiff.File)

Source from the content-addressed store, hash-verified

157}
158
159func (a *GraphQLApplier) applyModify(ctx context.Context, f *gitdiff.File) error {
160 data, exists, err := a.getContent(ctx, f.OldName)
161 if err != nil {
162 return err
163 }
164 if !exists {
165 return &Conflict{Type: ConflictModifiedFileMissing, File: f.OldName}
166 }
167
168 if len(f.TextFragments) > 0 || f.BinaryFragment != nil {
169 var b bytes.Buffer
170 if err := apply(&b, bytes.NewReader(data), f.OldName, f); err != nil {
171 return err
172 }
173 data = b.Bytes()
174 }
175
176 // delete the old file if it was removed
177 if f.OldName != f.NewName {
178 a.changes[f.OldName] = pendingChange{IsDelete: true}
179 }
180
181 a.changes[f.NewName] = pendingChange{Content: data}
182 a.modeCache[f.NewName] = defaultMode
183 return nil
184}
185
186func (a *GraphQLApplier) getContent(ctx context.Context, filePath string) ([]byte, bool, error) {
187 if existing, ok := a.changes[filePath]; ok {

Callers 1

ApplyMethod · 0.95

Calls 2

getContentMethod · 0.95
applyFunction · 0.85

Tested by

no test coverage detected