// Decode transform an core.Object into a Blob struct func (b *Blob) Decode(o core.Object) error { b.Hash = o.Hash() b.Size = o.Size() b.obj = o return nil }
func (r *Reader) readOFSDelta(raw core.Object, steps int64) error { start := r.r.position offset, err := decodeOffset(r.r, steps) if err != nil { return err } buf := bytes.NewBuffer(nil) if err := r.inflate(buf); err != nil { return err } ref, ok := r.offsets[start+offset] if !ok { return PackEntryNotFoundErr.n("offset %d", start+offset) } referenced, _ := r.s.Get(ref) d, _ := ioutil.ReadAll(referenced.Reader()) patched := patchDelta(d, buf.Bytes()) if patched == nil { return PatchingErr.n("hash %q", ref) } raw.SetType(referenced.Type()) raw.SetSize(int64(len(patched))) raw.Writer().Write(patched) return nil }
func (r *Reader) readREFDelta(raw core.Object) error { var ref core.Hash if _, err := r.r.Read(ref[:]); err != nil { return err } buf := bytes.NewBuffer(nil) if err := r.inflate(buf); err != nil { return err } referenced, ok := r.s.Get(ref) if !ok { return ObjectNotFoundErr.n("%s", ref) } d, _ := ioutil.ReadAll(referenced.Reader()) patched := patchDelta(d, buf.Bytes()) if patched == nil { return PatchingErr.n("hash %q", ref) } raw.SetType(referenced.Type()) raw.SetSize(int64(len(patched))) raw.Writer().Write(patched) return nil }
// Decode transform an core.Object into a Blob struct func (c *Commit) Decode(o core.Object) error { c.Hash = o.Hash() r := bufio.NewReader(o.Reader()) var message bool for { line, err := r.ReadSlice('\n') if err != nil && err != io.EOF { return err } line = bytes.TrimSpace(line) if !message { if len(line) == 0 { message = true continue } split := bytes.SplitN(line, []byte{' '}, 2) switch string(split[0]) { case "tree": c.tree = core.NewHash(string(split[1])) case "parent": c.parents = append(c.parents, core.NewHash(string(split[1]))) case "author": c.Author.Decode(split[1]) case "committer": c.Committer.Decode(split[1]) } } else { c.Message += string(line) + "\n" } if err == io.EOF { return nil } } }
// Decode transform an core.Object into a Tree struct func (t *Tree) Decode(o core.Object) error { t.Hash = o.Hash() if o.Size() == 0 { return nil } t.Entries = make(map[string]TreeEntry) r := bufio.NewReader(o.Reader()) for { mode, err := r.ReadString(' ') if err != nil { if err == io.EOF { break } return err } fm, err := strconv.ParseInt(mode[:len(mode)-1], 8, 32) if err != nil && err != io.EOF { return err } name, err := r.ReadString(0) if err != nil && err != io.EOF { return err } var hash core.Hash _, err = r.Read(hash[:]) if err != nil && err != io.EOF { return err } baseName := name[:len(name)-1] t.Entries[baseName] = TreeEntry{ Hash: hash, Mode: os.FileMode(fm), Name: baseName, } } return nil }
func (r *Reader) readObject(raw core.Object) error { return r.inflate(raw.Writer()) }