Ejemplo n.º 1
0
Archivo: blobs.go Proyecto: jbrukh/ggit
func (*blobComparator) Diff(a, b *objects.Blob, seq gdiff.Sequencer) gdiff.Diff {
	fa, fb := format.NewStrFormat(), format.NewStrFormat()
	fa.Object(a)
	fb.Object(b)
	s1, s2 := fa.String(), fb.String()
	differ := gdiff.MyersDiffer()
	return differ.Diff(s1, s2, seq)
}
Ejemplo n.º 2
0
func Benchmark__tagString(b *testing.B) {
	b.StopTimer()
	f := format.NewStrFormat()
	_, tag := justTag()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		f.Tag(tag)
	}
}
Ejemplo n.º 3
0
func Benchmark__treeString(b *testing.B) {
	b.StopTimer()
	f := format.NewStrFormat()
	_, tree := justTree()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		f.Tree(tree)
	}
}
Ejemplo n.º 4
0
func Benchmark__commitString(b *testing.B) {
	b.StopTimer()
	f := format.NewStrFormat()
	_, commit := justCommit()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		f.Commit(commit)
	}
}
Ejemplo n.º 5
0
func Benchmark__blobString(b *testing.B) {
	b.StopTimer()
	f := format.NewStrFormat()
	_, blob := justBlob()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		f.Blob(blob)
	}
}
Ejemplo n.º 6
0
Archivo: util.go Proyecto: jbrukh/ggit
// produce the SHA1 hash for any Object.
func MakeHash(o objects.Object) (hash.Hash, error) {
	sha.Reset()
	kind := string(o.Header().Type())
	f := format.NewStrFormat()
	if _, err := f.Object(o); err != nil {
		return nil, err
	}
	content := f.String()
	len := len([]byte(content))
	value := kind + string(token.SP) + fmt.Sprint(len) + string(token.NUL) + content
	toHash := []byte(value)
	sha.Write(toHash)
	return sha, nil
}
Ejemplo n.º 7
0
// Test_readCommits will compare the commit output of
// git and ggit for a string of commits.
func Test_readTree(t *testing.T) {
	testCase := test.Tree
	repo := Open(testCase.Repo())
	info := testCase.Info().(*test.InfoTree)
	f := format.NewStrFormat()

	var (
		oid = objects.OidNow(info.TreeOid)
	)
	o, err := repo.ObjectFromOid(oid)
	util.AssertNoErr(t, err)

	// check the id
	util.Assert(t, o.ObjectId().String() == info.TreeOid)

	// check the header
	util.Assert(t, o.Header().Type() == objects.ObjectTree)
	util.AssertEqualInt(t, int(o.Header().Size()), info.TreeSize)

	// get the tree
	// now convert to a tag and check the fields
	var tree *objects.Tree
	util.AssertPanicFree(t, func() {
		tree = o.(*objects.Tree)
	})

	// check entries
	entries := tree.Entries()
	util.AssertEqualInt(t, info.N, len(entries))
	util.Assert(t, info.N > 2)

	// check a file
	file := entries[0]
	util.AssertEqualString(t, info.File1Oid, file.ObjectId().String())
	util.Assert(t, file.Mode() == objects.ModeBlob)
	// TODO: add checks for type, etc.

	// check the output
	// check the whole representation, which will catch
	// most of the other stuff
	f.Reset()
	f.Object(o)
	util.AssertEqualString(t, info.TreeRepr, f.String())
}