aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-12-21 11:05:47 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:18:59 +0100
commit5c4e7de01281da51e32b4926dc0ef15b17a2d397 (patch)
tree505bab1389c6ce3fd10427fdfa266405b7250611 /repository/gogit.go
parent5f6a39145d9ac109d430190d0d352544d27b6561 (diff)
downloadgit-bug-5c4e7de01281da51e32b4926dc0ef15b17a2d397.tar.gz
repository: partially add two new functions to RepoData
Diffstat (limited to 'repository/gogit.go')
-rw-r--r--repository/gogit.go27
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()