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


Golang memory.NewStorage函數代碼示例

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


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

示例1: simpleDeltaTest

func (s *EncoderSuite) simpleDeltaTest(c *C) {
	srcObject := newObject(plumbing.BlobObject, []byte("0"))
	targetObject := newObject(plumbing.BlobObject, []byte("01"))

	deltaObject, err := GetDelta(srcObject, targetObject)
	c.Assert(err, IsNil)

	srcToPack := newObjectToPack(srcObject)
	_, err = s.enc.encode([]*ObjectToPack{
		srcToPack,
		newDeltaObjectToPack(srcToPack, targetObject, deltaObject),
	})
	c.Assert(err, IsNil)

	scanner := NewScanner(s.buf)

	storage := memory.NewStorage()
	d, err := NewDecoder(scanner, storage)
	c.Assert(err, IsNil)

	_, err = d.Decode()
	c.Assert(err, IsNil)

	decSrc, err := storage.EncodedObject(srcObject.Type(), srcObject.Hash())
	c.Assert(err, IsNil)
	c.Assert(decSrc, DeepEquals, srcObject)

	decTarget, err := storage.EncodedObject(targetObject.Type(), targetObject.Hash())
	c.Assert(err, IsNil)
	c.Assert(decTarget, DeepEquals, targetObject)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:31,代碼來源:encoder_test.go

示例2: TestFetch

func (s *RemoteSuite) TestFetch(c *C) {
	sto := memory.NewStorage()
	r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture})
	r.upSrv = &MockGitUploadPackService{}

	c.Assert(r.Connect(), IsNil)

	err := r.Fetch(&FetchOptions{
		RefSpecs: []config.RefSpec{FixRefSpec},
	})

	c.Assert(err, IsNil)
	c.Assert(sto.Objects, HasLen, 31)

	expectedRefs := []*plumbing.Reference{
		plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
		plumbing.NewReferenceFromStrings("refs/remotes/origin/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
		plumbing.NewReferenceFromStrings("refs/tags/v1.0.0", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
	}

	for _, exp := range expectedRefs {
		r, _ := sto.Reference(exp.Name())
		c.Assert(exp.String(), Equals, r.String())
	}
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:25,代碼來源:remote_test.go

示例3: TestDecodeCRCs

func (s *IdxfileSuite) TestDecodeCRCs(c *C) {
	f := fixtures.Basic().ByTag("ofs-delta").One()

	scanner := packfile.NewScanner(f.Packfile())
	storage := memory.NewStorage()

	pd, err := packfile.NewDecoder(scanner, storage)
	c.Assert(err, IsNil)
	_, err = pd.Decode()
	c.Assert(err, IsNil)

	i := &Idxfile{Version: VersionSupported}

	offsets := pd.Offsets()
	for h, crc := range pd.CRCs() {
		i.Add(h, uint64(offsets[h]), crc)
	}

	buf := bytes.NewBuffer(nil)
	e := NewEncoder(buf)
	_, err = e.Encode(i)
	c.Assert(err, IsNil)

	idx := &Idxfile{}

	d := NewDecoder(buf)
	err = d.Decode(idx)
	c.Assert(err, IsNil)

	c.Assert(idx.Entries, DeepEquals, i.Entries)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:31,代碼來源:decoder_test.go

示例4: TestFetchDepth

func (s *RemoteSuite) TestFetchDepth(c *C) {
	url := s.GetBasicLocalRepositoryURL()
	sto := memory.NewStorage()
	r := newRemote(sto, nil, &config.RemoteConfig{Name: "foo", URL: url})

	refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
	err := r.Fetch(&FetchOptions{
		RefSpecs: []config.RefSpec{refspec},
		Depth:    1,
	})

	c.Assert(err, IsNil)
	c.Assert(sto.Objects, HasLen, 18)

	expectedRefs := []*plumbing.Reference{
		plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
		plumbing.NewReferenceFromStrings("refs/remotes/origin/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
	}

	for _, exp := range expectedRefs {
		r, _ := sto.Reference(exp.Name())
		c.Assert(exp.String(), Equals, r.String())
	}

	h, err := sto.Shallow()
	c.Assert(err, IsNil)
	c.Assert(h, HasLen, 2)
	c.Assert(h, DeepEquals, []plumbing.Hash{
		plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881"),
		plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
	})
}
開發者ID:src-d,項目名稱:go-git,代碼行數:32,代碼來源:remote_test.go

示例5: storageFromPackfile

func (s *DiffTreeSuite) storageFromPackfile(f *fixtures.Fixture) storer.EncodedObjectStorer {
	sto, ok := s.cache[f.URL]
	if ok {
		return sto
	}

	sto = memory.NewStorage()

	pf := f.Packfile()

	defer pf.Close()

	n := packfile.NewScanner(pf)
	d, err := packfile.NewDecoder(n, sto)
	if err != nil {
		panic(err)
	}

	_, err = d.Decode()
	if err != nil {
		panic(err)
	}

	s.cache[f.URL] = sto
	return sto
}
開發者ID:src-d,項目名稱:go-git,代碼行數:26,代碼來源:difftree_test.go

示例6: emptyPackfile

func (s *SendPackSuite) emptyPackfile() io.ReadCloser {
	var buf bytes.Buffer
	e := packfile.NewEncoder(&buf, memory.NewStorage(), false)
	_, err := e.Encode(nil)
	if err != nil {
		panic(err)
	}

	return ioutil.NopCloser(&buf)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:10,代碼來源:send_pack.go

示例7: checkObjectNumber

func (s *FetchPackSuite) checkObjectNumber(c *C, r io.Reader, n int) {
	b, err := ioutil.ReadAll(r)
	c.Assert(err, IsNil)
	buf := bytes.NewBuffer(b)
	scanner := packfile.NewScanner(buf)
	storage := memory.NewStorage()
	d, err := packfile.NewDecoder(scanner, storage)
	c.Assert(err, IsNil)
	_, err = d.Decode()
	c.Assert(err, IsNil)
	c.Assert(len(storage.Objects), Equals, n)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:12,代碼來源:fetch_pack.go

示例8: TestFetchNoErrAlreadyUpToDate

func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) {
	url := s.GetBasicLocalRepositoryURL()
	sto := memory.NewStorage()
	r := newRemote(sto, nil, &config.RemoteConfig{Name: "foo", URL: url})

	refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
	o := &FetchOptions{
		RefSpecs: []config.RefSpec{refspec},
	}

	err := r.Fetch(o)
	c.Assert(err, IsNil)
	err = r.Fetch(o)
	c.Assert(err, Equals, NoErrAlreadyUpToDate)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:15,代碼來源:remote_test.go

示例9: TestFetchNoErrAlreadyUpToDate

func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) {
	sto := memory.NewStorage()
	r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture})
	r.upSrv = &MockGitUploadPackService{}

	c.Assert(r.Connect(), IsNil)

	o := &FetchOptions{
		RefSpecs: []config.RefSpec{FixRefSpec},
	}

	err := r.Fetch(o)
	c.Assert(err, IsNil)
	err = r.Fetch(o)
	c.Assert(err, Equals, NoErrAlreadyUpToDate)
}
開發者ID:alcortesm,項目名稱:go-git,代碼行數:16,代碼來源:remote_test.go

示例10: TestDecode

func (s *ReaderSuite) TestDecode(c *C) {
	fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
		scanner := packfile.NewScanner(f.Packfile())
		storage := memory.NewStorage()

		d, err := packfile.NewDecoder(scanner, storage)
		c.Assert(err, IsNil)
		defer d.Close()

		ch, err := d.Decode()
		c.Assert(err, IsNil)
		c.Assert(ch, Equals, f.PackfileHash)

		assertObjects(c, storage, expectedHashes)
	})
}
開發者ID:src-d,項目名稱:go-git,代碼行數:16,代碼來源:decoder_test.go

示例11: TestFetchWithProgress

func (s *RemoteSuite) TestFetchWithProgress(c *C) {
	url := s.GetBasicLocalRepositoryURL()
	sto := memory.NewStorage()
	buf := bytes.NewBuffer(nil)

	r := newRemote(sto, buf, &config.RemoteConfig{Name: "foo", URL: url})

	refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
	err := r.Fetch(&FetchOptions{
		RefSpecs: []config.RefSpec{refspec},
	})

	c.Assert(err, IsNil)
	c.Assert(sto.Objects, HasLen, 31)

	c.Assert(buf.Len(), Not(Equals), 0)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:17,代碼來源:remote_test.go

示例12: TestDecodeMultipleTimes

func (s *ReaderSuite) TestDecodeMultipleTimes(c *C) {
	f := fixtures.Basic().ByTag("packfile").One()
	scanner := packfile.NewScanner(f.Packfile())
	storage := memory.NewStorage()

	d, err := packfile.NewDecoder(scanner, storage)
	c.Assert(err, IsNil)
	defer d.Close()

	ch, err := d.Decode()
	c.Assert(err, IsNil)
	c.Assert(ch, Equals, f.PackfileHash)

	ch, err = d.Decode()
	c.Assert(err, Equals, packfile.ErrAlreadyDecoded)
	c.Assert(ch, Equals, plumbing.ZeroHash)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:17,代碼來源:decoder_test.go

示例13: newPackfileIter

func newPackfileIter(f billy.File, t plumbing.ObjectType, seen map[plumbing.Hash]bool) (storer.EncodedObjectIter, error) {
	s := packfile.NewScanner(f)
	_, total, err := s.Header()
	if err != nil {
		return nil, err
	}

	d, err := packfile.NewDecoder(s, memory.NewStorage())
	if err != nil {
		return nil, err
	}

	return &packfileIter{
		f: f,
		d: d,
		t: t,

		total: total,
		seen:  seen,
	}, nil
}
開發者ID:src-d,項目名稱:go-git,代碼行數:21,代碼來源:object.go

示例14: getFromPackfile

// Get returns the object with the given hash, by searching for it in
// the packfile.
func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.EncodedObject, error) {
	pack, offset := s.findObjectInPackfile(h)
	if offset == -1 {
		return nil, plumbing.ErrObjectNotFound
	}

	f, err := s.dir.ObjectPack(pack)
	if err != nil {
		return nil, err
	}

	defer f.Close()

	p := packfile.NewScanner(f)
	d, err := packfile.NewDecoder(p, memory.NewStorage())
	if err != nil {
		return nil, err
	}

	d.SetOffsets(s.index[pack])
	return d.DecodeObjectAt(offset)
}
開發者ID:src-d,項目名稱:go-git,代碼行數:24,代碼來源:object.go

示例15: TestDecodeNoSeekableWithTxStorer

func (s *ReaderSuite) TestDecodeNoSeekableWithTxStorer(c *C) {
	fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
		reader := nonSeekableReader{
			r: f.Packfile(),
		}

		scanner := packfile.NewScanner(reader)

		var storage storer.EncodedObjectStorer = memory.NewStorage()
		_, isTxStorer := storage.(storer.Transactioner)
		c.Assert(isTxStorer, Equals, true)

		d, err := packfile.NewDecoder(scanner, storage)
		c.Assert(err, IsNil)
		defer d.Close()

		ch, err := d.Decode()
		c.Assert(err, IsNil)
		c.Assert(ch, Equals, f.PackfileHash)

		assertObjects(c, storage, expectedHashes)
	})
}
開發者ID:src-d,項目名稱:go-git,代碼行數:23,代碼來源:decoder_test.go


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