Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/gitaly-git2go/apply.go')
-rw-r--r--cmd/gitaly-git2go/apply.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/cmd/gitaly-git2go/apply.go b/cmd/gitaly-git2go/apply.go
index 3a7f65b79..e5cc1339a 100644
--- a/cmd/gitaly-git2go/apply.go
+++ b/cmd/gitaly-git2go/apply.go
@@ -42,12 +42,14 @@ func (iter *patchIterator) Value() git2go.Patch { return iter.value }
func (iter *patchIterator) Err() error { return iter.error }
type applySubcommand struct {
- gitBinaryPath string
+ gitBinaryPath string
+ signingKeyPath string
}
func (cmd *applySubcommand) Flags() *flag.FlagSet {
fs := flag.NewFlagSet("apply", flag.ExitOnError)
fs.StringVar(&cmd.gitBinaryPath, "git-binary-path", "", "Path to the Git binary.")
+ fs.StringVar(&cmd.signingKeyPath, "signing-key", "", "Path to the OpenPGP signing key.")
return fs
}
@@ -126,30 +128,35 @@ func (cmd *applySubcommand) applyPatch(
}
}
- patchedTree, err := patchedIndex.WriteTreeTo(repo)
+ patchedTreeOID, err := patchedIndex.WriteTreeTo(repo)
if err != nil {
return nil, fmt.Errorf("write patched tree: %w", err)
}
+ patchedTree, err := repo.LookupTree(patchedTreeOID)
+ if err != nil {
+ return nil, fmt.Errorf("lookup tree: %w", err)
+ }
author := git.Signature(patch.Author)
- patchedCommitOID, err := repo.CreateCommitFromIds("", &author, committer, patch.Message, patchedTree, parentCommitOID)
+ patchedCommitID, err := git2goutil.NewCommitSubmitter(repo, cmd.signingKeyPath).
+ Commit(&author, committer, git.MessageEncodingUTF8, patch.Message, patchedTree, parentCommit)
if err != nil {
return nil, fmt.Errorf("create commit: %w", err)
}
- return patchedCommitOID, nil
+ return patchedCommitID, nil
}
// threeWayMerge attempts a three-way merge as a fallback if applying the patch fails.
// Fallback three-way merge is only possible if the patch records the pre-image blobs
// and the repository contains them. It works as follows:
//
-// 1. An index that contains only the pre-image blobs of the patch is built. This is done
-// by calling `git apply --build-fake-ancestor`. The tree of the index is the fake
-// ancestor tree.
-// 2. The fake ancestor tree is patched to produce the post-image tree of the patch.
-// 3. Three-way merge is performed with fake ancestor tree as the common ancestor, the
-// base commit's tree as our tree and the patched fake ancestor tree as their tree.
+// 1. An index that contains only the pre-image blobs of the patch is built. This is done
+// by calling `git apply --build-fake-ancestor`. The tree of the index is the fake
+// ancestor tree.
+// 2. The fake ancestor tree is patched to produce the post-image tree of the patch.
+// 3. Three-way merge is performed with fake ancestor tree as the common ancestor, the
+// base commit's tree as our tree and the patched fake ancestor tree as their tree.
func (cmd *applySubcommand) threeWayMerge(
ctx context.Context,
repo *git.Repository,