Beispiel #1
0
// ApplyDelta writes to taget the result of applying the modification deltas in delta to base.
func ApplyDelta(target, base plumbing.Object, delta []byte) error {
	r, err := base.Reader()
	if err != nil {
		return err
	}

	w, err := target.Writer()
	if err != nil {
		return err
	}

	src, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}

	dst := PatchDelta(src, delta)
	target.SetSize(int64(len(dst)))

	if _, err := w.Write(dst); err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
// Encode transforms a Tag into a plumbing.Object.
func (t *Tag) Encode(o plumbing.Object) error {
	o.SetType(plumbing.TagObject)
	w, err := o.Writer()
	if err != nil {
		return err
	}
	defer checkClose(w, &err)

	if _, err = fmt.Fprintf(w,
		"object %s\ntype %s\ntag %s\ntagger ",
		t.Target.String(), t.TargetType.Bytes(), t.Name); err != nil {
		return err
	}

	if err = t.Tagger.Encode(w); err != nil {
		return err
	}

	if _, err = fmt.Fprint(w, "\n\n"); err != nil {
		return err
	}

	if _, err = fmt.Fprint(w, t.Message); err != nil {
		return err
	}

	return err
}
Beispiel #3
0
func (d *Decoder) fillRegularObjectContent(obj plumbing.Object) (uint32, error) {
	w, err := obj.Writer()
	if err != nil {
		return 0, err
	}

	_, crc, err := d.s.NextObject(w)
	return crc, err
}
Beispiel #4
0
// Encode transforms a Blob into a plumbing.Object.
func (b *Blob) Encode(o plumbing.Object) error {
	w, err := o.Writer()
	if err != nil {
		return err
	}
	defer checkClose(w, &err)
	r, err := b.Reader()
	if err != nil {
		return err
	}
	defer checkClose(r, &err)
	_, err = io.Copy(w, r)
	o.SetType(plumbing.BlobObject)
	return err
}