diff options
author | Michael Muré <batolettre@gmail.com> | 2020-12-21 11:05:47 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2021-02-14 12:18:59 +0100 |
commit | 5c4e7de01281da51e32b4926dc0ef15b17a2d397 (patch) | |
tree | 505bab1389c6ce3fd10427fdfa266405b7250611 /repository/gogit.go | |
parent | 5f6a39145d9ac109d430190d0d352544d27b6561 (diff) | |
download | git-bug-5c4e7de01281da51e32b4926dc0ef15b17a2d397.tar.gz |
repository: partially add two new functions to RepoData
Diffstat (limited to 'repository/gogit.go')
-rw-r--r-- | repository/gogit.go | 27 |
1 files changed, 27 insertions, 0 deletions
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() |