MCPcopy Create free account
hub / github.com/antonmedv/gitmal / ApplyFragment

Method ApplyFragment

pkg/gitdiff/apply_binary.go:36–63  ·  view source on GitHub ↗

ApplyFragment applies the changes in the fragment f and writes the result to dst. ApplyFragment can be called at most once. If an error occurs while applying, ApplyFragment returns an *ApplyError that annotates the error with additional information. If the error is because of a conflict between a f

(f *BinaryFragment)

Source from the content-addressed store, hash-verified

34// a conflict between a fragment and the source, the wrapped error will be a
35// *Conflict.
36func (a *BinaryApplier) ApplyFragment(f *BinaryFragment) error {
37 if f == nil {
38 return applyError(errors.New("nil fragment"))
39 }
40 if a.closed {
41 return applyError(errApplierClosed)
42 }
43 if a.dirty {
44 return applyError(errApplyInProgress)
45 }
46
47 // mark an apply as in progress, even if it fails before making changes
48 a.dirty = true
49
50 switch f.Method {
51 case BinaryPatchLiteral:
52 if _, err := a.dst.Write(f.Data); err != nil {
53 return applyError(err)
54 }
55 case BinaryPatchDelta:
56 if err := applyBinaryDeltaFragment(a.dst, a.src, f.Data); err != nil {
57 return applyError(err)
58 }
59 default:
60 return applyError(fmt.Errorf("unsupported binary patch method: %v", f.Method))
61 }
62 return nil
63}
64
65// Close writes any data following the last applied fragment and prevents
66// future calls to ApplyFragment.

Callers 1

TestApplyBinaryFragmentFunction · 0.95

Calls 5

applyErrorFunction · 0.85
applyBinaryDeltaFragmentFunction · 0.85
NewMethod · 0.80
WriteMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestApplyBinaryFragmentFunction · 0.76