當前位置: 首頁>>代碼示例>>Golang>>正文


Golang plumbing.Object類代碼示例

本文整理匯總了Golang中gopkg/in/src-d/go-git/v4/plumbing.Object的典型用法代碼示例。如果您正苦於以下問題:Golang Object類的具體用法?Golang Object怎麽用?Golang Object使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Object類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Encode

// 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
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:29,代碼來源:tag.go

示例2: fillRegularObjectContent

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
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:9,代碼來源:decoder.go

示例3: fillOFSDeltaObjectContent

func (d *Decoder) fillOFSDeltaObjectContent(obj plumbing.Object, offset int64) (uint32, error) {
	buf := bytes.NewBuffer(nil)
	_, crc, err := d.s.NextObject(buf)
	if err != nil {
		return 0, err
	}

	base, err := d.recallByOffset(offset)
	if err != nil {
		return 0, err
	}

	obj.SetType(base.Type())
	return crc, ApplyDelta(obj, base, buf.Bytes())
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:15,代碼來源:decoder.go

示例4: Encode

// 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
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:16,代碼來源:blobs.go

示例5: toObject

func (iter *ObjectIter) toObject(obj plumbing.Object) (Object, error) {
	switch obj.Type() {
	case plumbing.BlobObject:
		blob := &Blob{}
		return blob, blob.Decode(obj)
	case plumbing.TreeObject:
		tree := &Tree{r: iter.r}
		return tree, tree.Decode(obj)
	case plumbing.CommitObject:
		commit := &Commit{}
		return commit, commit.Decode(obj)
	case plumbing.TagObject:
		tag := &Tag{}
		return tag, tag.Decode(obj)
	default:
		return nil, plumbing.ErrInvalidType
	}
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:18,代碼來源:objects.go

示例6: SetObject

func (o *ObjectStorage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
	h := obj.Hash()
	o.Objects[h] = obj

	switch obj.Type() {
	case plumbing.CommitObject:
		o.Commits[h] = o.Objects[h]
	case plumbing.TreeObject:
		o.Trees[h] = o.Objects[h]
	case plumbing.BlobObject:
		o.Blobs[h] = o.Objects[h]
	case plumbing.TagObject:
		o.Tags[h] = o.Objects[h]
	default:
		return h, ErrUnsupportedObjectType
	}

	return h, nil
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:19,代碼來源:storage.go

示例7: ApplyDelta

// 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
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:26,代碼來源:delta.go

示例8: Decode

// Decode transforms a plumbing.Object into a Blob struct.
func (b *Blob) Decode(o plumbing.Object) error {
	if o.Type() != plumbing.BlobObject {
		return ErrUnsupportedObject
	}

	b.Hash = o.Hash()
	b.Size = o.Size()
	b.obj = o

	return nil
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:12,代碼來源:blobs.go

示例9: Decode

// Decode transforms a plumbing.Object into a Tag struct.
func (t *Tag) Decode(o plumbing.Object) (err error) {
	if o.Type() != plumbing.TagObject {
		return ErrUnsupportedObject
	}

	t.Hash = o.Hash()

	reader, err := o.Reader()
	if err != nil {
		return err
	}
	defer checkClose(reader, &err)

	r := bufio.NewReader(reader)
	for {
		line, err := r.ReadSlice('\n')
		if err != nil && err != io.EOF {
			return err
		}

		line = bytes.TrimSpace(line)
		if len(line) == 0 {
			break // Start of message
		}

		split := bytes.SplitN(line, []byte{' '}, 2)
		switch string(split[0]) {
		case "object":
			t.Target = plumbing.NewHash(string(split[1]))
		case "type":
			t.TargetType, err = plumbing.ParseObjectType(string(split[1]))
			if err != nil {
				return err
			}
		case "tag":
			t.Name = string(split[1])
		case "tagger":
			t.Tagger.Decode(split[1])
		}

		if err == io.EOF {
			return nil
		}
	}

	data, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}
	t.Message = string(data)

	return nil
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:54,代碼來源:tag.go

示例10: SetObject

func (s *Storage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
	key, err := s.buildKey(obj.Hash(), obj.Type())
	if err != nil {
		return obj.Hash(), err
	}

	r, err := obj.Reader()
	if err != nil {
		return obj.Hash(), err
	}

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

	bins := driver.BinMap{
		urlField: s.url,
		"hash":   obj.Hash().String(),
		"type":   obj.Type().String(),
		"blob":   c,
	}

	err = s.client.Put(nil, key, bins)
	return obj.Hash(), err
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:26,代碼來源:storage.go

示例11: SetObject

// Set adds a new object to the storage.
func (s *ObjectStorage) SetObject(o plumbing.Object) (plumbing.Hash, error) {
	if o.Type() == plumbing.OFSDeltaObject || o.Type() == plumbing.REFDeltaObject {
		return plumbing.ZeroHash, plumbing.ErrInvalidType
	}

	ow, err := s.dir.NewObject()
	if err != nil {
		return plumbing.ZeroHash, err
	}

	defer ow.Close()

	or, err := o.Reader()
	if err != nil {
		return plumbing.ZeroHash, err
	}

	defer or.Close()

	if err := ow.WriteHeader(o.Type(), o.Size()); err != nil {
		return plumbing.ZeroHash, err
	}

	if _, err := io.Copy(ow, or); err != nil {
		return plumbing.ZeroHash, err
	}

	return o.Hash(), nil
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:30,代碼來源:object.go


注:本文中的gopkg/in/src-d/go-git/v4/plumbing.Object類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。