Beispiel #1
0
// TreePretty formats this tree object into a human-friendly table
// that is the same as the output of git-cat-file -p <tree>.
func (f *formatter) TreePretty(t *objects.Tree) (int, error) {
	N := 0
	for _, e := range t.Entries() {
		n, err := fmt.Fprintf(f.Writer, "%.6o %s %s\t%s\n", e.Mode(), e.ObjectType(), e.ObjectId(), e.Name())
		N += n
		if err != nil {
			return N, err
		}
	}
	return N, nil
}
Beispiel #2
0
// Tree formats this tree object into an API-friendly string that is
// the same as the output of git-cat-file tree <tree>.
func (f *formatter) Tree(t *objects.Tree) (int, error) {
	N := 0
	for _, e := range t.Entries() {
		n, err := fmt.Fprintf(f.Writer, "%o %s%s%s", e.Mode(), e.Name(), string(token.NUL), string(e.ObjectId().Bytes()))
		N += n
		if err != nil {
			return N, err
		}
	}
	return N, nil
}
Beispiel #3
0
func (d *treeDiffer) Diff(ta, tb *objects.Tree) (*TreeDiff, error) {
	result := new(TreeDiff)
	entriesA, entriesB := ta.Entries(), tb.Entries()
	if blobsA, blobsB, err := findBlobDiffs(d.repository, entriesA, entriesB); err != nil {
		return nil, err
	} else {
		for _, blob := range blobsA {
			result.makeDeletionEdit(blob)
		}
		for _, blob := range blobsB {
			result.makeInsertionEdit(blob)
		}
	}
	result.categorizeEdits(d.repository, d.blobDiffer)
	return result, nil
}
Beispiel #4
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())
}