Example #1
0
File: pack.go Project: jbrukh/ggit
func (p *Pack) parseDeltaEntry(bytes []byte, pot PackedObjectType, oid *objects.ObjectId, i int) *PackedObject {
	var (
		deltaDeflated packedDelta
		baseOffset    int64
		dp            *packedObjectParser
		err           error
	)
	e := p.idx.entries[i]
	switch pot {
	case ObjectRefDelta:
		var oid *objects.ObjectId
		deltaDeflated, oid = readPackedRefDelta(bytes)
		e := p.idx.entryById(oid)
		if e == nil {
			util.PanicErrf("nil entry for base object with id %s", oid.String())
		}
		baseOffset = e.offset
	case ObjectOffsetDelta:
		if deltaDeflated, baseOffset, err = readPackedOffsetDelta(bytes); err != nil {
			util.PanicErrf("Err parsing size: %v. Could not determine size for %s", err, e.String())
		}
		baseOffset = e.offset - baseOffset
	}
	base := p.findObjectByOffset(baseOffset)
	bytes = []byte(deltaDeflated)
	if dp, err = newPackedObjectParser(bytes, oid); err != nil {
		util.PanicErr(err.Error())
	}
	return dp.applyDelta(base, oid)
}
Example #2
0
func testFirstParent(t *testing.T, repo Repository, oid *objects.ObjectId, parentOid *objects.ObjectId) {
	rev := oid.String() // rev == oid here
	testObjectExpected(t, repo, rev, oid, objects.ObjectCommit)
	for i := 4; i <= 40; i++ {
		testObjectExpected(t, repo, rev[:i]+"^", parentOid, objects.ObjectCommit)
	}
}
Example #3
0
func testFirstParentVariations(t *testing.T, repo Repository, oid *objects.ObjectId, parentOid *objects.ObjectId) {
	rev := oid.String()
	testObjectExpected(t, repo, rev+"^", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"^1", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~1", parentOid, objects.ObjectCommit)
}
Example #4
0
func Test_ParseObjectId(t *testing.T) {
	var oid *objects.ObjectId
	oidStr := "ff6ccb68859fd52216ec8dadf98d2a00859f5369"
	t1 := ObjectParserForString(oidStr)
	oid = t1.ParseOid()
	util.Assert(t, oid.String() == oidStr)
}
Example #5
0
// testShortOid retrives the object by all possible combinations of
// shortening its id.
func testShortOid(t *testing.T, repo Repository, oid *objects.ObjectId) {
	rev := oid.String()
	for i := 4; i <= 40; i++ {
		o, err := ObjectFromRevision(repo, rev[:i])
		util.AssertNoErr(t, err)
		util.AssertEqualString(t, o.ObjectId().String(), oid.String())
	}
}
Example #6
0
func testParentlessCommit(t *testing.T, repo Repository, oid *objects.ObjectId) {
	rev := oid.String()
	testObjectExpected(t, repo, rev, oid, objects.ObjectCommit)
	_, err := ObjectFromRevision(repo, rev+"~1")
	util.Assert(t, err != nil)
	_, err = ObjectFromRevision(repo, rev+"^")
	util.Assert(t, err != nil)
}
Example #7
0
func testSecondAncestorVariations(t *testing.T, repo Repository, oid *objects.ObjectId, parentOid *objects.ObjectId) {
	rev := oid.String()
	testObjectExpected(t, repo, rev+"^^", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"^1^1", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"^^1", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"^1^", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~~", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~1~", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~1~1", parentOid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~~1", parentOid, objects.ObjectCommit)
}
Example #8
0
func testPackedTagDerefInfo(t *testing.T, repo Repository, spec string, oid *objects.ObjectId) {
	ref, err := repo.Ref(spec)
	util.AssertNoErr(t, err)
	util.AssertEqualString(t, ref.Name(), spec)
	// make sure target is symbolic and matches
	symbolic, target := ref.Target()
	util.Assert(t, !symbolic)
	if target == nil || ref.Commit() == nil {
		t.Fatalf("nil target or commit")
	}
	util.AssertEqualString(t, ref.Commit().String(), oid.String())
}
Example #9
0
func assertPeeledRef(t *testing.T, peeledRef objects.Ref, oid *objects.ObjectId) {
	symbolic, target := peeledRef.Target()
	util.Assert(t, !symbolic)
	if target == nil {
		t.Fatalf("nil target")
	}
	util.AssertEqualString(t, target.(*objects.ObjectId).String(), oid.String())
	util.AssertEqualString(t, peeledRef.ObjectId().String(), oid.String())
	util.AssertPanic(t, func() {
		s := target.(string)
		s += "" // for compilation
	})
}
Example #10
0
File: pack.go Project: jbrukh/ggit
func (idx *Idx) entryById(oid *objects.ObjectId) *PackedObjectId {
	trimmed := idx.entriesWithPrefix(oid.Bytes()[0])
	if trimmed == nil {
		return nil
	}
	id := oid.String()
	if idx.idToEntry[id] != nil {
		return idx.idToEntry[id]
	}
	gte := func(i int) bool {
		var oid *objects.ObjectId
		oid = trimmed[i].ObjectId
		return oid.String() >= id
	}
	i := sort.Search(len(trimmed), gte)
	if i >= len(trimmed) {
		return nil
	}
	result := trimmed[i]
	if result.ObjectId.String() != id {
		return nil
	}
	idx.idToEntry[id] = result
	return result
}
Example #11
0
func (f *formatter) ObjectId(oid *objects.ObjectId) (int, error) {
	return fmt.Fprint(f.Writer, oid.String())
}
Example #12
0
// testObjectExpected retrieves the commit with the given revision specification
// from the given repository and ensures that this operation went well and the
// returned object in fact has the expected oid.
func testObjectExpected(t *testing.T, repo Repository, rev string, expOid *objects.ObjectId, expType objects.ObjectType) {
	parent, err := ObjectFromRevision(repo, rev)
	util.AssertNoErr(t, err)
	util.Assert(t, parent.Header().Type() == expType)
	util.AssertEqualString(t, parent.ObjectId().String(), expOid.String())
}
Example #13
0
func testZeros(t *testing.T, repo Repository, oid *objects.ObjectId) {
	rev := oid.String()
	testObjectExpected(t, repo, rev+"^0", oid, objects.ObjectCommit)
	testObjectExpected(t, repo, rev+"~0", oid, objects.ObjectCommit)
}
Example #14
0
// objectFile turns an oid into a path relative to the
// git directory of a repository where that object should
// be located (if it is a loose object).
func objectFile(repo *DiskRepository, oid *objects.ObjectId) (file *os.File, err error) {
	hex := oid.String()
	path := path.Join(repo.path, DefaultObjectsDir, hex[0:2], hex[2:])
	return os.Open(path)
}