aboutsummaryrefslogtreecommitdiffstats
path: root/repository/mock_repo.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/mock_repo.go
parent5f6a39145d9ac109d430190d0d352544d27b6561 (diff)
downloadgit-bug-5c4e7de01281da51e32b4926dc0ef15b17a2d397.tar.gz
repository: partially add two new functions to RepoData
Diffstat (limited to 'repository/mock_repo.go')
-rw-r--r--repository/mock_repo.go42
1 files changed, 35 insertions, 7 deletions
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 974c3fb2..227e0f2c 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -179,7 +179,7 @@ var _ RepoData = &mockRepoData{}
type commit struct {
treeHash Hash
- parent Hash
+ parents []Hash
}
type mockRepoData struct {
@@ -247,11 +247,19 @@ func (r *mockRepoData) StoreCommitWithParent(treeHash Hash, parent Hash) (Hash,
hash := Hash(fmt.Sprintf("%x", rawHash))
r.commits[hash] = commit{
treeHash: treeHash,
- parent: parent,
+ parents: []Hash{parent},
}
return hash, nil
}
+func (r *mockRepoData) ResolveRef(ref string) (Hash, error) {
+ h, ok := r.refs[ref]
+ if !ok {
+ return "", fmt.Errorf("unknown ref")
+ }
+ return h, nil
+}
+
func (r *mockRepoData) UpdateRef(ref string, hash Hash) error {
r.refs[ref] = hash
return nil
@@ -303,12 +311,29 @@ func (r *mockRepoData) ListCommits(ref string) ([]Hash, error) {
}
hashes = append([]Hash{hash}, hashes...)
- hash = commit.parent
+
+ if len(commit.parents) == 0 {
+ break
+ }
+ hash = commit.parents[0]
}
return hashes, nil
}
+func (r *mockRepoData) ReadCommit(hash Hash) (Commit, error) {
+ c, ok := r.commits[hash]
+ if !ok {
+ return Commit{}, fmt.Errorf("unknown commit")
+ }
+
+ return Commit{
+ Hash: hash,
+ Parents: c.parents,
+ TreeHash: c.treeHash,
+ }, nil
+}
+
func (r *mockRepoData) ReadTree(hash Hash) ([]TreeEntry, error) {
var data string
@@ -340,8 +365,11 @@ func (r *mockRepoData) FindCommonAncestor(hash1 Hash, hash2 Hash) (Hash, error)
if !ok {
return "", fmt.Errorf("unknown commit %v", hash1)
}
- ancestor1 = append(ancestor1, c.parent)
- hash1 = c.parent
+ if len(c.parents) == 0 {
+ break
+ }
+ ancestor1 = append(ancestor1, c.parents[0])
+ hash1 = c.parents[0]
}
for {
@@ -356,11 +384,11 @@ func (r *mockRepoData) FindCommonAncestor(hash1 Hash, hash2 Hash) (Hash, error)
return "", fmt.Errorf("unknown commit %v", hash1)
}
- if c.parent == "" {
+ if c.parents[0] == "" {
return "", fmt.Errorf("no ancestor found")
}
- hash2 = c.parent
+ hash2 = c.parents[0]
}
}