Exemplo n.º 1
0
func (c *Commit) Lookup(r *Repo, o *Oid) (err error) {
	ecode := C.git_commit_lookup(&c.git_commit, r.git_repo, o.git_oid)
	if ecode < GIT_SUCCESS {
		return LastError()
	}
	return err
}
Exemplo n.º 2
0
func (repo *Repository) LookupCommit(oid *Oid) (*Commit, error) {
	commit := new(Commit)
	ecode := C.git_commit_lookup(&commit.git_commit, repo.git_repository, oid.git_oid)
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return commit, nil
}
Exemplo n.º 3
0
func (v *Repository) LookupCommit(o *Oid) (*Commit, error) {
	commit := new(Commit)
	ecode := C.git_commit_lookup(&commit.ptr, v.ptr, o.toC())
	if ecode < 0 {
		return nil, LastError()
	}

	return commit, nil
}
Exemplo n.º 4
0
Arquivo: git.go Projeto: fsouza/gogit
// Head returns the commit at the head of the repository.
func (r *Repository) Head() (*Commit, error) {
	var reference *C.struct_git_reference
	if C.git_repository_head(&reference, r.repository) != C.GIT_OK {
		return nil, lastErr()
	}
	defer C.git_reference_free(reference)
	c := new(Commit)
	if C.git_commit_lookup(&c.commit, r.repository, C.git_reference_oid(reference)) != C.GIT_OK {
		return nil, lastErr()
	}
	return c, nil
}
Exemplo n.º 5
0
func (r *GitRepository) Commit(name, email string) error {
	var ret C.int

	var index *C.git_index
	ret = C.git_repository_index(&index, r.ptr)
	if ret < 0 {
		return GitErrorLast()
	}
	defer C.git_index_free(index)

	treeOid := new(C.git_oid)
	ret = C.git_index_write_tree(treeOid, index)
	if ret < 0 {
		return GitErrorLast()
	}

	tree := new(C.git_tree)
	ret = C.git_tree_lookup(&tree, r.ptr, treeOid)
	if ret < 0 {
		return GitErrorLast()
	}
	defer C.git_tree_free(tree)

	signature := new(C.git_signature)
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))
	cEmail := C.CString(email)
	defer C.free(unsafe.Pointer(cEmail))
	ret = C.git_signature_now(&signature, cName, cEmail)
	if ret < 0 {
		return GitErrorLast()
	}
	defer C.git_signature_free(signature)

	headOid := new(C.git_oid)
	cHead := C.CString("HEAD")
	defer C.free(unsafe.Pointer(cHead))
	ret = C.git_reference_name_to_id(headOid, r.ptr, cHead)

	commitOid := new(C.git_oid)
	cMessage := C.CString("")
	defer C.free(unsafe.Pointer(cMessage))

	if ret == 0 {
		head := new(C.git_commit)
		ret = C.git_commit_lookup(&head, r.ptr, headOid)
		if ret < 0 {
			return GitErrorLast()
		}
		defer C.git_commit_free(head)

		parents := make([]*C.git_commit, 1)
		parents[0] = head

		ret = C.git_commit_create(
			commitOid,
			r.ptr,
			cHead,
			signature,
			signature,
			nil,
			cMessage,
			tree,
			1,
			&parents[0],
		)
	} else {
		ret = C.git_commit_create(
			commitOid,
			r.ptr,
			cHead,
			signature,
			signature,
			nil,
			cMessage,
			tree,
			0,
			nil,
		)
	}

	if ret < 0 {
		return GitErrorLast()
	}

	ret = C.git_index_write(index)
	if ret < 0 {
		return GitErrorLast()
	}

	return nil
}