aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-01-24 19:45:21 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:19:00 +0100
commitdc5059bc3372941e2908739831188768335ac50b (patch)
tree7294aed90cf5f04809d7a99b4967b513bdb409d5 /repository
parent8d63c983c982f93cc48d3996d6bd097ddeeb327f (diff)
downloadgit-bug-dc5059bc3372941e2908739831188768335ac50b.tar.gz
entity: more progress on merging and signing
Diffstat (limited to 'repository')
-rw-r--r--repository/common.go53
-rw-r--r--repository/gogit.go7
-rw-r--r--repository/keyring.go2
-rw-r--r--repository/repo.go5
-rw-r--r--repository/repo_testing.go21
5 files changed, 3 insertions, 85 deletions
diff --git a/repository/common.go b/repository/common.go
index 7fd7ae19..4cefbd9e 100644
--- a/repository/common.go
+++ b/repository/common.go
@@ -8,59 +8,6 @@ import (
"golang.org/x/crypto/openpgp/errors"
)
-// nonNativeMerge is an implementation of a branch merge, for the case where
-// the underlying git implementation doesn't support it natively.
-func nonNativeMerge(repo RepoData, ref string, otherRef string, treeHashFn func() Hash) error {
- commit, err := repo.ResolveRef(ref)
- if err != nil {
- return err
- }
-
- otherCommit, err := repo.ResolveRef(otherRef)
- if err != nil {
- return err
- }
-
- if commit == otherCommit {
- // nothing to merge
- return nil
- }
-
- // fast-forward is possible if otherRef include ref
-
- otherCommits, err := repo.ListCommits(otherRef)
- if err != nil {
- return err
- }
-
- fastForwardPossible := false
- for _, hash := range otherCommits {
- if hash == commit {
- fastForwardPossible = true
- break
- }
- }
-
- if fastForwardPossible {
- return repo.UpdateRef(ref, otherCommit)
- }
-
- // fast-forward is not possible, we need to create a merge commit
-
- // we need a Tree to make the commit, an empty Tree will do
- emptyTreeHash, err := repo.StoreTree(nil)
- if err != nil {
- return err
- }
-
- newHash, err := repo.StoreCommit(emptyTreeHash, commit, otherCommit)
- if err != nil {
- return err
- }
-
- return repo.UpdateRef(ref, newHash)
-}
-
// nonNativeListCommits is an implementation for ListCommits, for the case where
// the underlying git implementation doesn't support if natively.
func nonNativeListCommits(repo RepoData, ref string) ([]Hash, error) {
diff --git a/repository/gogit.go b/repository/gogit.go
index d6eb8621..fe434d88 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -630,13 +630,6 @@ func (repo *GoGitRepo) UpdateRef(ref string, hash Hash) error {
return repo.r.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName(ref), plumbing.NewHash(hash.String())))
}
-// MergeRef merge other into ref and update the reference
-// If the update is not fast-forward, the callback treeHashFn will be called for the caller to generate
-// the Tree to store in the merge commit.
-func (repo *GoGitRepo) MergeRef(ref string, otherRef string, treeHashFn func() Hash) error {
- return nonNativeMerge(repo, ref, otherRef, treeHashFn)
-}
-
// RemoveRef will remove a Git reference
func (repo *GoGitRepo) RemoveRef(ref string) error {
return repo.r.Storer.RemoveReference(plumbing.ReferenceName(ref))
diff --git a/repository/keyring.go b/repository/keyring.go
index 64365c39..6cba303e 100644
--- a/repository/keyring.go
+++ b/repository/keyring.go
@@ -15,7 +15,7 @@ var ErrKeyringKeyNotFound = keyring.ErrKeyNotFound
type Keyring interface {
// Returns an Item matching the key or ErrKeyringKeyNotFound
Get(key string) (Item, error)
- // Stores an Item on the keyring
+ // Stores an Item on the keyring. Set is idempotent.
Set(item Item) error
// Removes the item with matching key
Remove(key string) error
diff --git a/repository/repo.go b/repository/repo.go
index d7afa983..87426333 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -138,11 +138,6 @@ type RepoData interface {
// UpdateRef will create or update a Git reference
UpdateRef(ref string, hash Hash) error
- // // MergeRef merge other into ref and update the reference
- // // If the update is not fast-forward, the callback treeHashFn will be called for the caller to generate
- // // the Tree to store in the merge commit.
- // MergeRef(ref string, otherRef string, treeHashFn func() Hash) error
-
// RemoveRef will remove a Git reference
RemoveRef(ref string) error
diff --git a/repository/repo_testing.go b/repository/repo_testing.go
index 4a5c48bb..92aa1691 100644
--- a/repository/repo_testing.go
+++ b/repository/repo_testing.go
@@ -197,6 +197,8 @@ func RepoDataTest(t *testing.T, repo RepoData) {
err = repo.RemoveRef("refs/bugs/ref1")
require.NoError(t, err)
+
+ // TODO: testing for commit's signature
}
// helper to test a RepoClock
@@ -238,22 +240,3 @@ func randomData() []byte {
}
return b
}
-
-func makeCommit(t *testing.T, repo RepoData, parents ...Hash) Hash {
- blobHash, err := repo.StoreData(randomData())
- require.NoError(t, err)
-
- treeHash, err := repo.StoreTree([]TreeEntry{
- {
- ObjectType: Blob,
- Hash: blobHash,
- Name: "foo",
- },
- })
- require.NoError(t, err)
-
- commitHash, err := repo.StoreCommit(treeHash, parents...)
- require.NoError(t, err)
-
- return commitHash
-}