Skip to content

Commit f266577

Browse files
committed
Merge branch 'en/merge-ort-prepare-to-remove-recursive' into jch
* en/merge-ort-prepare-to-remove-recursive: merge-ort: support having merge verbosity be set to 0 merge-ort: allow rename detection to be disabled merge-ort: add new merge_ort_generic() function
2 parents f4ef85e + e0ea342 commit f266577

File tree

5 files changed

+106
-11
lines changed

5 files changed

+106
-11
lines changed

Documentation/merge-strategies.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ find-renames[=<n>];;
8282
rename-threshold=<n>;;
8383
Deprecated synonym for `find-renames=<n>`.
8484

85+
no-renames;;
86+
Turn off rename detection. This overrides the `merge.renames`
87+
configuration variable.
88+
See also linkgit:git-diff[1] `--no-renames`.
89+
8590
subtree[=<path>];;
8691
This option is a more advanced form of 'subtree' strategy, where
8792
the strategy makes a guess on how two trees must be shifted to
@@ -107,7 +112,7 @@ For a path that is a submodule, the same caution as 'ort' applies to this
107112
strategy.
108113
+
109114
The 'recursive' strategy takes the same options as 'ort'. However,
110-
there are three additional options that 'ort' ignores (not documented
115+
there are two additional options that 'ort' ignores (not documented
111116
above) that are potentially useful with the 'recursive' strategy:
112117

113118
patience;;
@@ -121,11 +126,6 @@ diff-algorithm=[patience|minimal|histogram|myers];;
121126
specifically uses `diff-algorithm=histogram`, while `recursive`
122127
defaults to the `diff.algorithm` config setting.
123128

124-
no-renames;;
125-
Turn off rename detection. This overrides the `merge.renames`
126-
configuration variable.
127-
See also linkgit:git-diff[1] `--no-renames`.
128-
129129
resolve::
130130
This can only resolve two heads (i.e. the current branch
131131
and another branch you pulled from) using a 3-way merge

merge-ort-wrappers.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include "git-compat-util.h"
22
#include "gettext.h"
33
#include "hash.h"
4+
#include "hex.h"
5+
#include "lockfile.h"
46
#include "merge-ort.h"
57
#include "merge-ort-wrappers.h"
68
#include "read-cache-ll.h"
9+
#include "repository.h"
10+
#include "tag.h"
711
#include "tree.h"
812

913
#include "commit.h"
@@ -64,3 +68,63 @@ int merge_ort_recursive(struct merge_options *opt,
6468

6569
return tmp.clean;
6670
}
71+
72+
static struct commit *get_ref(struct repository *repo,
73+
const struct object_id *oid,
74+
const char *name)
75+
{
76+
struct object *object;
77+
78+
object = deref_tag(repo, parse_object(repo, oid),
79+
name, strlen(name));
80+
if (!object)
81+
return NULL;
82+
if (object->type == OBJ_TREE)
83+
return make_virtual_commit(repo, (struct tree*)object, name);
84+
if (object->type != OBJ_COMMIT)
85+
return NULL;
86+
if (repo_parse_commit(repo, (struct commit *)object))
87+
return NULL;
88+
return (struct commit *)object;
89+
}
90+
91+
int merge_ort_generic(struct merge_options *opt,
92+
const struct object_id *head,
93+
const struct object_id *merge,
94+
int num_merge_bases,
95+
const struct object_id *merge_bases,
96+
struct commit **result)
97+
{
98+
int clean;
99+
struct lock_file lock = LOCK_INIT;
100+
struct commit *head_commit = get_ref(opt->repo, head, opt->branch1);
101+
struct commit *next_commit = get_ref(opt->repo, merge, opt->branch2);
102+
struct commit_list *ca = NULL;
103+
104+
if (merge_bases) {
105+
int i;
106+
for (i = 0; i < num_merge_bases; ++i) {
107+
struct commit *base;
108+
if (!(base = get_ref(opt->repo, &merge_bases[i],
109+
oid_to_hex(&merge_bases[i]))))
110+
return error(_("Could not parse object '%s'"),
111+
oid_to_hex(&merge_bases[i]));
112+
commit_list_insert(base, &ca);
113+
}
114+
}
115+
116+
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
117+
clean = merge_ort_recursive(opt, head_commit, next_commit, ca,
118+
result);
119+
free_commit_list(ca);
120+
if (clean < 0) {
121+
rollback_lock_file(&lock);
122+
return clean;
123+
}
124+
125+
if (write_locked_index(opt->repo->index, &lock,
126+
COMMIT_LOCK | SKIP_IF_UNCHANGED))
127+
return error(_("Unable to write index."));
128+
129+
return clean ? 0 : 1;
130+
}

merge-ort-wrappers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ int merge_ort_recursive(struct merge_options *opt,
2222
const struct commit_list *ancestors,
2323
struct commit **result);
2424

25+
/*
26+
* rename-detecting three-way merge. num_merge_bases must be at least 1.
27+
* Recursive ancestor consolidation will be performed if num_merge_bases > 1.
28+
* Wrapper mimicking the old merge_recursive_generic() function.
29+
*/
30+
int merge_ort_generic(struct merge_options *opt,
31+
const struct object_id *head,
32+
const struct object_id *merge,
33+
int num_merge_bases,
34+
const struct object_id *merge_bases,
35+
struct commit **result);
36+
2537
#endif

merge-ort.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ static void path_msg(struct merge_options *opt,
799799
return; /* Do not record mere hints in headers */
800800
if (opt->priv->call_depth && opt->verbosity < 5)
801801
return; /* Ignore messages from inner merges */
802+
if (!opt->verbosity)
803+
return;
802804

803805
/* Ensure path_conflicts (ptr to array of logical_conflict) allocated */
804806
path_conflicts = strmap_get(&opt->priv->conflicts, primary_path);
@@ -3449,6 +3451,11 @@ static int detect_and_process_renames(struct merge_options *opt)
34493451

34503452
if (!possible_renames(renames))
34513453
goto cleanup;
3454+
if (opt->detect_renames == 0) {
3455+
renames->redo_after_renames = 0;
3456+
renames->cached_pairs_valid_side = 0;
3457+
goto cleanup;
3458+
}
34523459

34533460
trace2_region_enter("merge", "regular renames", opt->repo);
34543461
detection_run |= detect_regular_renames(opt, MERGE_SIDE1);
@@ -4879,9 +4886,9 @@ static inline void set_commit_tree(struct commit *c, struct tree *t)
48794886
c->maybe_tree = t;
48804887
}
48814888

4882-
static struct commit *make_virtual_commit(struct repository *repo,
4883-
struct tree *tree,
4884-
const char *comment)
4889+
struct commit *make_virtual_commit(struct repository *repo,
4890+
struct tree *tree,
4891+
const char *comment)
48854892
{
48864893
struct commit *commit = alloc_commit_node(repo);
48874894

@@ -5187,6 +5194,8 @@ static void merge_ort_internal(struct merge_options *opt,
51875194
ancestor_name = "empty tree";
51885195
} else if (merge_bases) {
51895196
ancestor_name = "merged common ancestors";
5197+
} else if (opt->ancestor) {
5198+
ancestor_name = opt->ancestor;
51905199
} else {
51915200
strbuf_add_unique_abbrev(&merge_base_abbrev,
51925201
&merged_merge_bases->object.oid,
@@ -5276,8 +5285,13 @@ void merge_incore_recursive(struct merge_options *opt,
52765285
{
52775286
trace2_region_enter("merge", "incore_recursive", opt->repo);
52785287

5279-
/* We set the ancestor label based on the merge_bases */
5280-
assert(opt->ancestor == NULL);
5288+
/*
5289+
* We set the ancestor label based on the merge_bases...but we
5290+
* allow one exception through so that builtin/am can override
5291+
* with its constructed fake ancestor.
5292+
*/
5293+
assert(opt->ancestor == NULL ||
5294+
(merge_bases && !merge_bases->next));
52815295

52825296
trace2_region_enter("merge", "merge_start", opt->repo);
52835297
merge_start(opt, result);

merge-ort.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ struct merge_result {
4444
unsigned _properly_initialized;
4545
};
4646

47+
/* Mostly internal function also used by merge-ort-wrappers.c */
48+
struct commit *make_virtual_commit(struct repository *repo,
49+
struct tree *tree,
50+
const char *comment);
51+
4752
/*
4853
* rename-detecting three-way merge with recursive ancestor consolidation.
4954
* working tree and index are untouched.

0 commit comments

Comments
 (0)