[PATCH v4 0/2] merge-tree: allow specifying a base commit when --write-tree is passed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for Elijah's work. I'm very excited that merge-ort is integrated into
the git merge-tree, which means that we can use merge-ort in bare
repositories to optimize merge performance.

In this patch, I introduce a new --merge-base=<commit> option to allow
callers to specify a merge-base for the merge. This may allow users to
implement git cherry-pick and git rebase in bare repositories with git
merge-tree cmd.

Changes since v1:

 * Changed merge_incore_recursive() to merge_incore_nonrecursive() when
   merge-base is specified.
 * Fixed c style problem.
 * Moved commit lookup/die logic out to the parsing logic in
   cmd_merge_tree().
 * use test_commit for test

Changes since v2:

 * commit message
 * Rebased on top of en/merge-tree-sequence.
 * Set opt.ancestor to o->merge_base. Because opt.ancestor is a *char. To
   make it easier to pass parameters, I moved
   lookup_commit_reference_by_name() to real_ merge() again.
 * Added test comment.

Changes since v3:

 * support --merge-base in conjunction with --stdin

Kyle Zhao (2):
  merge-tree.c: add --merge-base=<commit> option
  merge-tree.c: support --merge-base in conjunction with --stdin

 Documentation/git-merge-tree.txt |  5 +++
 builtin/merge-tree.c             | 64 ++++++++++++++++++++++++++------
 t/t4301-merge-tree-write-tree.sh | 51 +++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 12 deletions(-)


base-commit: ec1edbcb56ac05e9980299b05924c5c1b51d68b4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1397%2Fkeyu98%2Fkz%2Fmerge-tree-option-merge-base-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1397/keyu98/kz/merge-tree-option-merge-base-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/1397

Range-diff vs v3:

 1:  554cbde49e8 ! 1:  bba854fc8fa merge-tree.c: add --merge-base=<commit> option
     @@ builtin/merge-tree.c
       #include "merge-ort.h"
       #include "object-store.h"
      @@ builtin/merge-tree.c: struct merge_tree_options {
     - 	int show_messages;
     - 	int name_only;
     - 	int use_stdin;
     -+	const char *merge_base;
       };
       
       static int real_merge(struct merge_tree_options *o,
     ++		      const char *merge_base,
     + 		      const char *branch1, const char *branch2,
     + 		      const char *prefix)
     + {
      @@ builtin/merge-tree.c: static int real_merge(struct merge_tree_options *o,
       	opt.branch1 = branch1;
       	opt.branch2 = branch2;
     @@ builtin/merge-tree.c: static int real_merge(struct merge_tree_options *o,
      -	if (!merge_bases && !o->allow_unrelated_histories)
      -		die(_("refusing to merge unrelated histories"));
      -	merge_bases = reverse_commit_list(merge_bases);
     -+	if (o->merge_base) {
     ++	if (merge_base) {
      +		struct commit *base_commit;
      +		struct tree *base_tree, *parent1_tree, *parent2_tree;
      +
     -+		base_commit = lookup_commit_reference_by_name(o->merge_base);
     ++		base_commit = lookup_commit_reference_by_name(merge_base);
      +		if (!base_commit)
     -+			die(_("could not lookup commit %s"), o->merge_base);
     ++			die(_("could not lookup commit %s"), merge_base);
      +
     -+		opt.ancestor = o->merge_base;
     ++		opt.ancestor = merge_base;
      +		base_tree = get_commit_tree(base_commit);
      +		parent1_tree = get_commit_tree(parent1);
      +		parent2_tree = get_commit_tree(parent2);
     @@ builtin/merge-tree.c: static int real_merge(struct merge_tree_options *o,
       	if (result.clean < 0)
       		die(_("failure to merge"));
       
     +@@ builtin/merge-tree.c: int cmd_merge_tree(int argc, const char **argv, const char *prefix)
     + 	struct merge_tree_options o = { .show_messages = -1 };
     + 	int expected_remaining_argc;
     + 	int original_argc;
     ++	const char *merge_base = NULL;
     + 
     + 	const char * const merge_tree_usage[] = {
     + 		N_("git merge-tree [--write-tree] [<options>] <branch1> <branch2>"),
      @@ builtin/merge-tree.c: int cmd_merge_tree(int argc, const char **argv, const char *prefix)
       			   &o.use_stdin,
       			   N_("perform multiple merges, one per line of input"),
       			   PARSE_OPT_NONEG),
      +		OPT_STRING(0, "merge-base",
     -+			   &o.merge_base,
     ++			   &merge_base,
      +			   N_("commit"),
      +			   N_("specify a merge-base for the merge")),
       		OPT_END()
       	};
       
     +@@ builtin/merge-tree.c: int cmd_merge_tree(int argc, const char **argv, const char *prefix)
     + 			if (!split[0] || !split[1] || split[2])
     + 				die(_("malformed input line: '%s'."), buf.buf);
     + 			strbuf_rtrim(split[0]);
     +-			result = real_merge(&o, split[0]->buf, split[1]->buf, prefix);
     ++			result = real_merge(&o, merge_base, split[0]->buf, split[1]->buf, prefix);
     + 			if (result < 0)
     + 				die(_("merging cannot continue; got unclean result of %d"), result);
     + 			strbuf_list_free(split);
     +@@ builtin/merge-tree.c: int cmd_merge_tree(int argc, const char **argv, const char *prefix)
     + 
     + 	/* Do the relevant type of merge */
     + 	if (o.mode == MODE_REAL)
     +-		return real_merge(&o, argv[0], argv[1], prefix);
     ++		return real_merge(&o, merge_base, argv[0], argv[1], prefix);
     + 	else
     + 		return trivial_merge(argv[0], argv[1], argv[2]);
     + }
      
       ## t/t4301-merge-tree-write-tree.sh ##
      @@ t/t4301-merge-tree-write-tree.sh: test_expect_success '--stdin with both a successful and a conflicted merge' '
 -:  ----------- > 2:  db47fbc663e merge-tree.c: support --merge-base in conjunction with --stdin

-- 
gitgitgadget



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux