当前位置: 首页>>代码示例>>Golang>>正文


Golang packfile.NewScanner函数代码示例

本文整理汇总了Golang中gopkg/in/src-d/go-git/v4/plumbing/format/packfile.NewScanner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewScanner函数的具体用法?Golang NewScanner怎么用?Golang NewScanner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewScanner函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: buildIndex

func (w *PackWriter) buildIndex() {
	s := packfile.NewScanner(w.synced)
	d, err := packfile.NewDecoder(s, nil)
	if err != nil {
		w.result <- err
		return
	}

	checksum, err := d.Decode()
	if err != nil {
		w.result <- err
		return
	}

	w.checksum = checksum
	w.index.PackfileChecksum = checksum
	w.index.Version = idxfile.VersionSupported

	offsets := d.Offsets()
	for h, crc := range d.CRCs() {
		w.index.Add(h, uint64(offsets[h]), crc)
	}

	w.result <- err
}
开发者ID:src-d,项目名称:go-git,代码行数:25,代码来源:writers.go

示例2: 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

示例3: unpackFixtures

func unpackFixtures(c *C, fixtures ...[]packedFixture) map[string]*Repository {
	repos := make(map[string]*Repository, 0)
	for _, group := range fixtures {
		for _, fixture := range group {
			if _, existing := repos[fixture.url]; existing {
				continue
			}

			comment := Commentf("fixture packfile: %q", fixture.packfile)

			repos[fixture.url] = NewMemoryRepository()

			f, err := os.Open(fixture.packfile)
			c.Assert(err, IsNil, comment)

			r := packfile.NewScanner(f)
			d, err := packfile.NewDecoder(r, repos[fixture.url].s)
			c.Assert(err, IsNil, comment)
			_, err = d.Decode()
			c.Assert(err, IsNil, comment)
			c.Assert(f.Close(), IsNil, comment)
		}
	}

	return repos
}
开发者ID:alcortesm,项目名称:go-git,代码行数:26,代码来源:common_test.go

示例4: 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

示例5: TestNewDecodeNonSeekable

func (s *ReaderSuite) TestNewDecodeNonSeekable(c *C) {
	scanner := packfile.NewScanner(nil)
	d, err := packfile.NewDecoder(scanner, nil)

	c.Assert(d, IsNil)
	c.Assert(err, NotNil)
}
开发者ID:src-d,项目名称:go-git,代码行数:7,代码来源:decoder_test.go

示例6: NewRepositoryFromPackfile

func (s *BaseSuite) NewRepositoryFromPackfile(f *fixtures.Fixture) *Repository {
	h := f.PackfileHash.String()
	if r, ok := s.cache[h]; ok {
		return r
	}

	r := NewMemoryRepository()

	p := f.Packfile()
	defer p.Close()

	n := packfile.NewScanner(p)
	d, err := packfile.NewDecoder(n, r.s)
	if err != nil {
		panic(err)
	}

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

	s.cache[h] = r
	return r
}
开发者ID:src-d,项目名称:go-git,代码行数:25,代码来源:common_test.go

示例7: TestDecodeInMemory

func (s *ReaderSuite) TestDecodeInMemory(c *C) {
	fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
		scanner := packfile.NewScanner(f.Packfile())
		d, err := packfile.NewDecoder(scanner, nil)
		c.Assert(err, IsNil)

		ch, err := d.Decode()
		c.Assert(err, IsNil)
		c.Assert(ch, Equals, f.PackfileHash)
	})
}
开发者ID:src-d,项目名称:go-git,代码行数:11,代码来源:decoder_test.go

示例8: 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

示例9: TestOffsets

func (s *ReaderSuite) TestOffsets(c *C) {
	f := fixtures.Basic().One()
	scanner := packfile.NewScanner(f.Packfile())
	d, err := packfile.NewDecoder(scanner, nil)
	c.Assert(err, IsNil)

	c.Assert(d.Offsets(), HasLen, 0)

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

	c.Assert(d.Offsets(), HasLen, 31)
}
开发者ID:src-d,项目名称:go-git,代码行数:13,代码来源:decoder_test.go

示例10: TestSetOffsets

func (s *ReaderSuite) TestSetOffsets(c *C) {
	f := fixtures.Basic().One()
	scanner := packfile.NewScanner(f.Packfile())
	d, err := packfile.NewDecoder(scanner, nil)
	c.Assert(err, IsNil)

	h := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
	d.SetOffsets(map[plumbing.Hash]int64{h: 42})

	o := d.Offsets()
	c.Assert(o, HasLen, 1)
	c.Assert(o[h], Equals, int64(42))
}
开发者ID:src-d,项目名称:go-git,代码行数:13,代码来源:decoder_test.go

示例11: buildRepositories

func (s *BaseSuite) buildRepositories(c *C, f fixtures.Fixtures) {
	for _, fixture := range f {
		r := NewMemoryRepository()

		f := fixture.Packfile()
		defer f.Close()

		n := packfile.NewScanner(f)
		d, err := packfile.NewDecoder(n, r.s)
		c.Assert(err, IsNil)
		_, err = d.Decode()
		c.Assert(err, IsNil)

		s.Repositories[fixture.URL] = r
	}
}
开发者ID:alcortesm,项目名称:go-git,代码行数:16,代码来源:common_test.go

示例12: 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

示例13: 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

示例14: TestReadObjectAt

func (s *ReaderSuite) TestReadObjectAt(c *C) {
	f := fixtures.Basic().One()
	scanner := packfile.NewScanner(f.Packfile())
	d, err := packfile.NewDecoder(scanner, nil)
	c.Assert(err, IsNil)

	// when the packfile is ref-delta based, the offsets are required
	if f.Is("ref-delta") {
		offsets := getOffsetsFromIdx(f.Idx())
		d.SetOffsets(offsets)
	}

	// the objects at reference 186, is a delta, so should be recall,
	// without being read before.
	obj, err := d.DecodeObjectAt(186)
	c.Assert(err, IsNil)
	c.Assert(obj.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
}
开发者ID:src-d,项目名称:go-git,代码行数:18,代码来源:decoder_test.go

示例15: 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


注:本文中的gopkg/in/src-d/go-git/v4/plumbing/format/packfile.NewScanner函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。