Beispiel #1
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
	})
}
Beispiel #2
0
func assertSymbolicRef(t *testing.T, symbolicRef objects.Ref, tget string) {
	symbolic, target := symbolicRef.Target()
	util.Assert(t, symbolic)
	if target == nil {
		t.Fatalf("nil target")
	}
	util.AssertEqualString(t, target.(string), tget)
	util.AssertPanic(t, func() {
		oid := target.(*objects.ObjectId)
		oid.String() // for compilation
	})
	util.AssertPanic(t, func() {
		oid := symbolicRef.ObjectId()
		oid.String() // for compilation
	})
}
Beispiel #3
0
// PeelRef resolves the final target oid of the ref and returns
// a peeled ref for this target. It examines the target of the
// given ref and if the target is symbolic, it is followed and
// resolved. This process repeats as many times as necessary to
// obtain a peeled ref.
func PeelRef(repo Repository, r objects.Ref) (objects.Ref, error) {
	var (
		err      error
		symbolic bool
		target   interface{}
	)

	// TODO: make a limit
	for {
		symbolic, target = r.Target()
		if symbolic {
			r, err = repo.Ref(target.(string))
			if err != nil {
				return nil, err
			}
		} else {
			break
		}
	}
	return r, nil
}
Beispiel #4
0
// TODO: come up with a better name for this
func (f *formatter) Deref(r objects.Ref) (int, error) {
	return fmt.Fprintf(f.Writer, "%s %s^{}", r.Commit(), r.Name())
}
Beispiel #5
0
func (f *formatter) Ref(r objects.Ref) (int, error) {
	_, rf := r.Target() // symbolic or oid
	return fmt.Fprintf(f.Writer, "%s %s", rf, r.Name())
}