From 5c4e7de01281da51e32b4926dc0ef15b17a2d397 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 21 Dec 2020 11:05:47 +0100 Subject: repository: partially add two new functions to RepoData --- repository/gogit.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'repository/gogit.go') diff --git a/repository/gogit.go b/repository/gogit.go index 5abdef39..64ccb773 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -595,6 +595,14 @@ func (repo *GoGitRepo) FindCommonAncestor(commit1 Hash, commit2 Hash) (Hash, err return Hash(commits[0].Hash.String()), nil } +func (repo *GoGitRepo) ResolveRef(ref string) (Hash, error) { + r, err := repo.r.Reference(plumbing.ReferenceName(ref), false) + if err != nil { + return "", err + } + return Hash(r.Hash().String()), nil +} + // UpdateRef will create or update a Git reference func (repo *GoGitRepo) UpdateRef(ref string, hash Hash) error { return repo.r.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName(ref), plumbing.NewHash(hash.String()))) @@ -679,6 +687,25 @@ func (repo *GoGitRepo) ListCommits(ref string) ([]Hash, error) { return hashes, nil } +func (repo *GoGitRepo) ReadCommit(hash Hash) (Commit, error) { + commit, err := repo.r.CommitObject(plumbing.NewHash(hash.String())) + if err != nil { + return Commit{}, err + } + + parents := make([]Hash, len(commit.ParentHashes)) + for i, parentHash := range commit.ParentHashes { + parents[i] = Hash(parentHash.String()) + } + + return Commit{ + Hash: hash, + Parents: parents, + TreeHash: Hash(commit.TreeHash.String()), + }, nil + +} + func (repo *GoGitRepo) AllClocks() (map[string]lamport.Clock, error) { repo.clocksMutex.Lock() defer repo.clocksMutex.Unlock() -- cgit