Ejemplo n.º 1
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.º 2
0
func (db *DiffBuiltin) Execute(p *Params, args []string) {
	if len(args) < 2 {
		fmt.Printf("expected two arguments; got %d\n", len(args))
		return
	}
	var e error
	var oa, ob objects.Object
	if oa, e = api.ObjectFromRevision(p.Repo, args[0]); e != nil {
		fmt.Printf(e.Error())
		return
	}
	if ob, e = api.ObjectFromRevision(p.Repo, args[1]); e != nil {
		fmt.Printf(e.Error())
		return
	}
	var ot objects.ObjectType
	if oah, obh := oa.Header().Type(), ob.Header().Type(); oah != obh {
		fmt.Printf("objects are not the same type: \n%s [%s]\n%s [%s]\n", args[0], oah.String(), args[1], obh.String())
		return
	} else {
		ot = oah
	}
	switch ot {
	case objects.ObjectBlob:
		oab, _ := oa.(*objects.Blob)
		obb, _ := ob.(*objects.Blob)
		d := diff.NewBlobComparator().Diff(oab, obb, gdiff.LineSplit)
		gdiff.Unified().Print(d, os.Stdout)
	case objects.ObjectTree:
		oat, _ := oa.(*objects.Tree)
		obt, _ := ob.(*objects.Tree)
		td := diff.NewTreeDiffer(p.Repo, diff.NewBlobComparator())
		if result, err := td.Diff(oat, obt); err != nil {
			fmt.Printf(err.Error())
		} else {
			fmt.Printf(result.String())
		}
		//TODO
	default:
		fmt.Printf("objects are of type %s; only blobs (files) and trees are currently supported", ot)
	}
}