summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-10-15 13:47:59 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-10-15 13:47:59 +0900
commit280bd445515acffb83231dfee79c21719ad3bc7b (patch)
tree170dbd8e836c6111200970d172743a531f5e7387
parentEighth batch (diff)
parentmerge-recursive: fix the fix to the diff3 common ancestor label (diff)
downloadtgif-280bd445515acffb83231dfee79c21719ad3bc7b.tar.xz
Merge branch 'en/merge-recursive-cleanup'
The merge-recursive machiery is one of the most complex parts of the system that accumulated cruft over time. This large series cleans up the implementation quite a bit. * en/merge-recursive-cleanup: (26 commits) merge-recursive: fix the fix to the diff3 common ancestor label merge-recursive: fix the diff3 common ancestor label for virtual commits merge-recursive: alphabetize include list merge-recursive: add sanity checks for relevant merge_options merge-recursive: rename MERGE_RECURSIVE_* to MERGE_VARIANT_* merge-recursive: split internal fields into a separate struct merge-recursive: avoid losing output and leaking memory holding that output merge-recursive: comment and reorder the merge_options fields merge-recursive: consolidate unnecessary fields in merge_options merge-recursive: move some definitions around to clean up the header merge-recursive: rename merge_options argument to opt in header merge-recursive: rename 'mrtree' to 'result_tree', for clarity merge-recursive: use common name for ancestors/common/base_list merge-recursive: fix some overly long lines cache-tree: share code between functions writing an index as a tree merge-recursive: don't force external callers to do our logging merge-recursive: remove useless parameter in merge_trees() merge-recursive: exit early if index != head Ensure index matches head before invoking merge machinery, round N merge-recursive: remove another implicit dependency on the_repository ...
-rw-r--r--builtin/am.c2
-rw-r--r--builtin/checkout.c14
-rw-r--r--builtin/merge-recursive.c4
-rw-r--r--builtin/stash.c2
-rw-r--r--cache-tree.c85
-rw-r--r--cache-tree.h3
-rw-r--r--merge-recursive.c572
-rw-r--r--merge-recursive.h164
-rw-r--r--sequencer.c5
-rwxr-xr-xt/t3030-merge-recursive.sh9
-rwxr-xr-xt/t6036-recursive-corner-cases.sh8
-rwxr-xr-xt/t6047-diff3-conflict-markers.sh202
12 files changed, 736 insertions, 334 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 761cac39e0..8181c2aef3 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1526,7 +1526,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
o.branch1 = "HEAD";
their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
o.branch2 = their_tree_name;
- o.detect_directory_renames = 0;
+ o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE;
if (state->quiet)
o.verbosity = 0;
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1283727761..3634a3dac1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -709,11 +709,11 @@ static int merge_working_tree(const struct checkout_opts *opts,
* give up or do a real merge, depending on
* whether the merge flag was used.
*/
- struct tree *result;
struct tree *work;
struct tree *old_tree;
struct merge_options o;
struct strbuf sb = STRBUF_INIT;
+ struct strbuf old_commit_shortname = STRBUF_INIT;
if (!opts->merge)
return 1;
@@ -754,7 +754,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
*/
init_merge_options(&o, the_repository);
o.verbosity = 0;
- work = write_tree_from_memory(&o);
+ work = write_in_core_index_as_tree(the_repository);
ret = reset_tree(new_tree,
opts, 1,
@@ -762,19 +762,25 @@ static int merge_working_tree(const struct checkout_opts *opts,
if (ret)
return ret;
o.ancestor = old_branch_info->name;
+ if (old_branch_info->name == NULL) {
+ strbuf_add_unique_abbrev(&old_commit_shortname,
+ &old_branch_info->commit->object.oid,
+ DEFAULT_ABBREV);
+ o.ancestor = old_commit_shortname.buf;
+ }
o.branch1 = new_branch_info->name;
o.branch2 = "local";
ret = merge_trees(&o,
new_tree,
work,
- old_tree,
- &result);
+ old_tree);
if (ret < 0)
exit(128);
ret = reset_tree(new_tree,
opts, 0,
writeout_error);
strbuf_release(&o.obuf);
+ strbuf_release(&old_commit_shortname);
if (ret)
return ret;
}
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index 5b910e351e..a4bfd8fc51 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,3 +1,4 @@
+#include "cache.h"
#include "builtin.h"
#include "commit.h"
#include "tag.h"
@@ -63,6 +64,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
if (argc - i != 3) /* "--" "<head>" "<remote>" */
die(_("not handling anything other than two heads merge."));
+ if (repo_read_index_unmerged(the_repository))
+ die_resolve_conflict("merge");
+
o.branch1 = argv[++i];
o.branch2 = argv[++i];
diff --git a/builtin/stash.c b/builtin/stash.c
index 4fc44b35e4..bb4f6d8d76 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -427,6 +427,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
return error(_("could not save index tree"));
reset_head();
+ discard_cache();
+ read_cache();
}
}
diff --git a/cache-tree.c b/cache-tree.c
index 62edee45e4..1bd1b23d38 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -609,11 +609,66 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
return it;
}
+static int write_index_as_tree_internal(struct object_id *oid,
+ struct index_state *index_state,
+ int cache_tree_valid,
+ int flags,
+ const char *prefix)
+{
+ if (flags & WRITE_TREE_IGNORE_CACHE_TREE) {
+ cache_tree_free(&index_state->cache_tree);
+ cache_tree_valid = 0;
+ }
+
+ if (!index_state->cache_tree)
+ index_state->cache_tree = cache_tree();
+
+ if (!cache_tree_valid && cache_tree_update(index_state, flags) < 0)
+ return WRITE_TREE_UNMERGED_INDEX;
+
+ if (prefix) {
+ struct cache_tree *subtree;
+ subtree = cache_tree_find(index_state->cache_tree, prefix);
+ if (!subtree)
+ return WRITE_TREE_PREFIX_ERROR;
+ oidcpy(oid, &subtree->oid);
+ }
+ else
+ oidcpy(oid, &index_state->cache_tree->oid);
+
+ return 0;
+}
+
+struct tree* write_in_core_index_as_tree(struct repository *repo) {
+ struct object_id o;
+ int was_valid, ret;
+
+ struct index_state *index_state = repo->index;
+ was_valid = index_state->cache_tree &&
+ cache_tree_fully_valid(index_state->cache_tree);
+
+ ret = write_index_as_tree_internal(&o, index_state, was_valid, 0, NULL);
+ if (ret == WRITE_TREE_UNMERGED_INDEX) {
+ int i;
+ fprintf(stderr, "BUG: There are unmerged index entries:\n");
+ for (i = 0; i < index_state->cache_nr; i++) {
+ const struct cache_entry *ce = index_state->cache[i];
+ if (ce_stage(ce))
+ fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
+ (int)ce_namelen(ce), ce->name);
+ }
+ BUG("unmerged index entries when writing inmemory index");
+ }
+
+ return lookup_tree(repo, &index_state->cache_tree->oid);
+}
+
+
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
{
int entries, was_valid;
struct lock_file lock_file = LOCK_INIT;
- int ret = 0;
+ int ret;
hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR);
@@ -622,18 +677,14 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
ret = WRITE_TREE_UNREADABLE_INDEX;
goto out;
}
- if (flags & WRITE_TREE_IGNORE_CACHE_TREE)
- cache_tree_free(&index_state->cache_tree);
- if (!index_state->cache_tree)
- index_state->cache_tree = cache_tree();
+ was_valid = !(flags & WRITE_TREE_IGNORE_CACHE_TREE) &&
+ index_state->cache_tree &&
+ cache_tree_fully_valid(index_state->cache_tree);
- was_valid = cache_tree_fully_valid(index_state->cache_tree);
- if (!was_valid) {
- if (cache_tree_update(index_state, flags) < 0) {
- ret = WRITE_TREE_UNMERGED_INDEX;
- goto out;
- }
+ ret = write_index_as_tree_internal(oid, index_state, was_valid, flags,
+ prefix);
+ if (!ret && !was_valid) {
write_locked_index(index_state, &lock_file, COMMIT_LOCK);
/* Not being able to write is fine -- we are only interested
* in updating the cache-tree part, and if the next caller
@@ -643,18 +694,6 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
*/
}
- if (prefix) {
- struct cache_tree *subtree;
- subtree = cache_tree_find(index_state->cache_tree, prefix);
- if (!subtree) {
- ret = WRITE_TREE_PREFIX_ERROR;
- goto out;
- }
- oidcpy(oid, &subtree->oid);
- }
- else
- oidcpy(oid, &index_state->cache_tree->oid);
-
out:
rollback_lock_file(&lock_file);
return ret;
diff --git a/cache-tree.h b/cache-tree.h
index 757bbc48bc..639bfa5340 100644
--- a/cache-tree.h
+++ b/cache-tree.h
@@ -34,7 +34,7 @@ int cache_tree_fully_valid(struct cache_tree *);
int cache_tree_update(struct index_state *, int);
void cache_tree_verify(struct repository *, struct index_state *);
-/* bitmasks to write_cache_as_tree flags */
+/* bitmasks to write_index_as_tree flags */
#define WRITE_TREE_MISSING_OK 1
#define WRITE_TREE_IGNORE_CACHE_TREE 2
#define WRITE_TREE_DRY_RUN 4
@@ -46,6 +46,7 @@ void cache_tree_verify(struct repository *, struct index_state *);
#define WRITE_TREE_UNMERGED_INDEX (-2)
#define WRITE_TREE_PREFIX_ERROR (-3)
+struct tree* write_in_core_index_as_tree(struct repository *repo);
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
diff --git a/merge-recursive.c b/merge-recursive.c
index 22a12cfeba..e86571c91b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -4,30 +4,40 @@
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
#include "cache.h"
-#include "config.h"
+#include "merge-recursive.h"
+
#include "advice.h"
-#include "lockfile.h"
-#include "cache-tree.h"
-#include "object-store.h"
-#include "repository.h"
-#include "commit.h"
+#include "alloc.h"
+#include "attr.h"
#include "blob.h"
#include "builtin.h"
-#include "tree-walk.h"
+#include "cache-tree.h"
+#include "commit.h"
+#include "commit-reach.h"
+#include "config.h"
#include "diff.h"
#include "diffcore.h"
+#include "dir.h"
+#include "ll-merge.h"
+#include "lockfile.h"
+#include "object-store.h"
+#include "repository.h"
+#include "revision.h"
+#include "string-list.h"
+#include "submodule.h"
#include "tag.h"
-#include "alloc.h"
+#include "tree-walk.h"
#include "unpack-trees.h"
-#include "string-list.h"
#include "xdiff-interface.h"
-#include "ll-merge.h"
-#include "attr.h"
-#include "merge-recursive.h"
-#include "dir.h"
-#include "submodule.h"
-#include "revision.h"
-#include "commit-reach.h"
+
+struct merge_options_internal {
+ int call_depth;
+ int needed_rename_limit;
+ struct hashmap current_file_dir_set;
+ struct string_list df_conflict_file_set;
+ struct unpack_trees_options unpack_opts;
+ struct index_state orig_index;
+};
struct path_hashmap_entry {
struct hashmap_entry e;
@@ -54,6 +64,24 @@ static unsigned int path_hash(const char *path)
return ignore_case ? strihash(path) : strhash(path);
}
+/*
+ * For dir_rename_entry, directory names are stored as a full path from the
+ * toplevel of the repository and do not include a trailing '/'. Also:
+ *
+ * dir: original name of directory being renamed
+ * non_unique_new_dir: if true, could not determine new_dir
+ * new_dir: final name of directory being renamed
+ * possible_new_dirs: temporary used to help determine new_dir; see comments
+ * in get_directory_renames() for details
+ */
+struct dir_rename_entry {
+ struct hashmap_entry ent; /* must be the first member! */
+ char *dir;
+ unsigned non_unique_new_dir:1;
+ struct strbuf new_dir;
+ struct string_list possible_new_dirs;
+};
+
static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
char *dir)
{
@@ -92,6 +120,13 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry,
string_list_init(&entry->possible_new_dirs, 0);
}
+struct collision_entry {
+ struct hashmap_entry ent; /* must be the first member! */
+ char *target_file;
+ struct string_list source_files;
+ unsigned reported_already:1;
+};
+
static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
char *target_file)
{
@@ -284,7 +319,8 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
static int show(struct merge_options *opt, int v)
{
- return (!opt->call_depth && opt->verbosity >= v) || opt->verbosity >= 5;
+ return (!opt->priv->call_depth && opt->verbosity >= v) ||
+ opt->verbosity >= 5;
}
__attribute__((format (printf, 3, 4)))
@@ -295,7 +331,7 @@ static void output(struct merge_options *opt, int v, const char *fmt, ...)
if (!show(opt, v))
return;
- strbuf_addchars(&opt->obuf, ' ', opt->call_depth * 2);
+ strbuf_addchars(&opt->obuf, ' ', opt->priv->call_depth * 2);
va_start(ap, fmt);
strbuf_vaddf(&opt->obuf, fmt, ap);
@@ -310,7 +346,7 @@ static void output_commit_title(struct merge_options *opt, struct commit *commit
{
struct merge_remote_desc *desc;
- strbuf_addchars(&opt->obuf, ' ', opt->call_depth * 2);
+ strbuf_addchars(&opt->obuf, ' ', opt->priv->call_depth * 2);
desc = merge_remote_util(commit);
if (desc)
strbuf_addf(&opt->obuf, "virtual %s\n", desc->name);
@@ -358,6 +394,11 @@ static int add_cacheinfo(struct merge_options *opt,
return ret;
}
+static inline int merge_detect_rename(struct merge_options *opt)
+{
+ return (opt->detect_renames >= 0) ? opt->detect_renames : 1;
+}
+
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
{
parse_tree(tree);
@@ -373,74 +414,43 @@ static int unpack_trees_start(struct merge_options *opt,
struct tree_desc t[3];
struct index_state tmp_index = { NULL };
- memset(&opt->unpack_opts, 0, sizeof(opt->unpack_opts));
- if (opt->call_depth)
- opt->unpack_opts.index_only = 1;
+ memset(&opt->priv->unpack_opts, 0, sizeof(opt->priv->unpack_opts));
+ if (opt->priv->call_depth)
+ opt->priv->unpack_opts.index_only = 1;
else
- opt->unpack_opts.update = 1;
- opt->unpack_opts.merge = 1;
- opt->unpack_opts.head_idx = 2;
- opt->unpack_opts.fn = threeway_merge;
- opt->unpack_opts.src_index = opt->repo->index;
- opt->unpack_opts.dst_index = &tmp_index;
- opt->unpack_opts.aggressive = !merge_detect_rename(opt);
- setup_unpack_trees_porcelain(&opt->unpack_opts, "merge");
+ opt->priv->unpack_opts.update = 1;
+ opt->priv->unpack_opts.merge = 1;
+ opt->priv->unpack_opts.head_idx = 2;
+ opt->priv->unpack_opts.fn = threeway_merge;
+ opt->priv->unpack_opts.src_index = opt->repo->index;
+ opt->priv->unpack_opts.dst_index = &tmp_index;
+ opt->priv->unpack_opts.aggressive = !merge_detect_rename(opt);
+ setup_unpack_trees_porcelain(&opt->priv->unpack_opts, "merge");
init_tree_desc_from_tree(t+0, common);
init_tree_desc_from_tree(t+1, head);
init_tree_desc_from_tree(t+2, merge);
- rc = unpack_trees(3, t, &opt->unpack_opts);
+ rc = unpack_trees(3, t, &opt->priv->unpack_opts);
cache_tree_free(&opt->repo->index->cache_tree);
/*
- * Update opt->repo->index to match the new results, AFTER saving a copy
- * in opt->orig_index. Update src_index to point to the saved copy.
- * (verify_uptodate() checks src_index, and the original index is
- * the one that had the necessary modification timestamps.)
+ * Update opt->repo->index to match the new results, AFTER saving a
+ * copy in opt->priv->orig_index. Update src_index to point to the
+ * saved copy. (verify_uptodate() checks src_index, and the original
+ * index is the one that had the necessary modification timestamps.)
*/
- opt->orig_index = *opt->repo->index;
+ opt->priv->orig_index = *opt->repo->index;
*opt->repo->index = tmp_index;
- opt->unpack_opts.src_index = &opt->orig_index;
+ opt->priv->unpack_opts.src_index = &opt->priv->orig_index;
return rc;
}
static void unpack_trees_finish(struct merge_options *opt)
{
- discard_index(&opt->orig_index);
- clear_unpack_trees_porcelain(&opt->unpack_opts);
-}
-
-struct tree *write_tree_from_memory(struct merge_options *opt)
-{
- struct tree *result = NULL;
- struct index_state *istate = opt->repo->index;
-
- if (unmerged_index(istate)) {
- int i;
- fprintf(stderr, "BUG: There are unmerged index entries:\n");
- for (i = 0; i < istate->cache_nr; i++) {
- const struct cache_entry *ce = istate->cache[i];
- if (ce_stage(ce))
- fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
- (int)ce_namelen(ce), ce->name);
- }
- BUG("unmerged index entries in merge-recursive.c");
- }
-
- if (!istate->cache_tree)
- istate->cache_tree = cache_tree();
-
- if (!cache_tree_fully_valid(istate->cache_tree) &&
- cache_tree_update(istate, 0) < 0) {
- err(opt, _("error building trees"));
- return NULL;
- }
-
- result = lookup_tree(opt->repo, &istate->cache_tree->oid);
-
- return result;
+ discard_index(&opt->priv->orig_index);
+ clear_unpack_trees_porcelain(&opt->priv->unpack_opts);
}
static int save_files_dirs(const struct object_id *oid,
@@ -455,7 +465,7 @@ static int save_files_dirs(const struct object_id *oid,
FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
hashmap_entry_init(entry, path_hash(entry->path));
- hashmap_add(&opt->current_file_dir_set, entry);
+ hashmap_add(&opt->priv->current_file_dir_set, entry);
strbuf_setlen(base, baselen);
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -586,7 +596,7 @@ static void record_df_conflict_files(struct merge_options *opt,
* If we're merging merge-bases, we don't want to bother with
* any working directory changes.
*/
- if (opt->call_depth)
+ if (opt->priv->call_depth)
return;
/* Ensure D/F conflicts are adjacent in the entries list. */
@@ -598,7 +608,7 @@ static void record_df_conflict_files(struct merge_options *opt,
df_sorted_entries.cmp = string_list_df_name_compare;
string_list_sort(&df_sorted_entries);
- string_list_clear(&opt->df_conflict_file_set, 1);
+ string_list_clear(&opt->priv->df_conflict_file_set, 1);
for (i = 0; i < df_sorted_entries.nr; i++) {
const char *path = df_sorted_entries.items[i].string;
int len = strlen(path);
@@ -614,7 +624,7 @@ static void record_df_conflict_files(struct merge_options *opt,
len > last_len &&
memcmp(path, last_file, last_len) == 0 &&
path[last_len] == '/') {
- string_list_insert(&opt->df_conflict_file_set, last_file);
+ string_list_insert(&opt->priv->df_conflict_file_set, last_file);
}
/*
@@ -681,8 +691,8 @@ static void update_entry(struct stage_data *entry,
static int remove_file(struct merge_options *opt, int clean,
const char *path, int no_wd)
{
- int update_cache = opt->call_depth || clean;
- int update_working_directory = !opt->call_depth && !no_wd;
+ int update_cache = opt->priv->call_depth || clean;
+ int update_working_directory = !opt->priv->call_depth && !no_wd;
if (update_cache) {
if (remove_file_from_index(opt->repo->index, path))
@@ -712,7 +722,9 @@ static void add_flattened_path(struct strbuf *out, const char *s)
out->buf[i] = '_';
}
-static char *unique_path(struct merge_options *opt, const char *path, const char *branch)
+static char *unique_path(struct merge_options *opt,
+ const char *path,
+ const char *branch)
{
struct path_hashmap_entry *entry;
struct strbuf newpath = STRBUF_INIT;
@@ -723,16 +735,16 @@ static char *unique_path(struct merge_options *opt, const char *path, const char
add_flattened_path(&newpath, branch);
base_len = newpath.len;
- while (hashmap_get_from_hash(&opt->current_file_dir_set,
+ while (hashmap_get_from_hash(&opt->priv->current_file_dir_set,
path_hash(newpath.buf), newpath.buf) ||
- (!opt->call_depth && file_exists(newpath.buf))) {
+ (!opt->priv->call_depth && file_exists(newpath.buf))) {
strbuf_setlen(&newpath, base_len);
strbuf_addf(&newpath, "_%d", suffix++);
}
FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
hashmap_entry_init(entry, path_hash(entry->path));
- hashmap_add(&opt->current_file_dir_set, entry);
+ hashmap_add(&opt->priv->current_file_dir_set, entry);
return strbuf_detach(&newpath, NULL);
}
@@ -775,7 +787,7 @@ static int dir_in_way(struct index_state *istate, const char *path,
static int was_tracked_and_matches(struct merge_options *opt, const char *path,
const struct diff_filespec *blob)
{
- int pos = index_name_pos(&opt->orig_index, path, strlen(path));
+ int pos = index_name_pos(&opt->priv->orig_index, path, strlen(path));
struct cache_entry *ce;
if (0 > pos)
@@ -783,7 +795,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path,
return 0;
/* See if the file we were tracking before matches */
- ce = opt->orig_index.cache[pos];
+ ce = opt->priv->orig_index.cache[pos];
return (oid_eq(&ce->oid, &blob->oid) && ce->ce_mode == blob->mode);
}
@@ -792,7 +804,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path,
*/
static int was_tracked(struct merge_options *opt, const char *path)
{
- int pos = index_name_pos(&opt->orig_index, path, strlen(path));
+ int pos = index_name_pos(&opt->priv->orig_index, path, strlen(path));
if (0 <= pos)
/* we were tracking this path before the merge */
@@ -849,12 +861,12 @@ static int was_dirty(struct merge_options *opt, const char *path)
struct cache_entry *ce;
int dirty = 1;
- if (opt->call_depth || !was_tracked(opt, path))
+ if (opt->priv->call_depth || !was_tracked(opt, path))
return !dirty;
- ce = index_file_exists(opt->unpack_opts.src_index,
+ ce = index_file_exists(opt->priv->unpack_opts.src_index,
path, strlen(path), ignore_case);
- dirty = verify_uptodate(ce, &opt->unpack_opts) != 0;
+ dirty = verify_uptodate(ce, &opt->priv->unpack_opts) != 0;
return dirty;
}
@@ -864,8 +876,8 @@ static int make_room_for_path(struct merge_options *opt, const char *path)
const char *msg = _("failed to create path '%s'%s");
/* Unlink any D/F conflict files that are in the way */
- for (i = 0; i < opt->df_conflict_file_set.nr; i++) {
- const char *df_path = opt->df_conflict_file_set.items[i].string;
+ for (i = 0; i < opt->priv->df_conflict_file_set.nr; i++) {
+ const char *df_path = opt->priv->df_conflict_file_set.items[i].string;
size_t pathlen = strlen(path);
size_t df_pathlen = strlen(df_path);
if (df_pathlen < pathlen &&
@@ -875,7 +887,7 @@ static int make_room_for_path(struct merge_options *opt, const char *path)
_("Removing %s to make room for subdirectory\n"),
df_path);
unlink(df_path);
- unsorted_string_list_delete_item(&opt->df_conflict_file_set,
+ unsorted_string_list_delete_item(&opt->priv->df_conflict_file_set,
i, 0);
break;
}
@@ -916,7 +928,7 @@ static int update_file_flags(struct merge_options *opt,
{
int ret = 0;
- if (opt->call_depth)
+ if (opt->priv->call_depth)
update_wd = 0;
if (update_wd) {
@@ -935,9 +947,11 @@ static int update_file_flags(struct merge_options *opt,
}
buf = read_object_file(&contents->oid, &type, &size);
- if (!buf)
- return err(opt, _("cannot read object %s '%s'"),
- oid_to_hex(&contents->oid), path);
+ if (!buf) {
+ ret = err(opt, _("cannot read object %s '%s'"),
+ oid_to_hex(&contents->oid), path);
+ goto free_buf;
+ }
if (type != OBJ_BLOB) {
ret = err(opt, _("blob expected for %s '%s'"),
oid_to_hex(&contents->oid), path);
@@ -945,7 +959,8 @@ static int update_file_flags(struct merge_options *opt,
}
if (S_ISREG(contents->mode)) {
struct strbuf strbuf = STRBUF_INIT;
- if (convert_to_working_tree(opt->repo->index, path, buf, size, &strbuf)) {
+ if (convert_to_working_tree(opt->repo->index,
+ path, buf, size, &strbuf)) {
free(buf);
size = strbuf.len;
buf = strbuf_detach(&strbuf, NULL);
@@ -998,7 +1013,7 @@ static int update_file(struct merge_options *opt,
const char *path)
{
return update_file_flags(opt, contents, path,
- opt->call_depth || clean, !opt->call_depth);
+ opt->priv->call_depth || clean, !opt->priv->call_depth);
}
/* Low level file merging, update and removal */
@@ -1020,22 +1035,22 @@ static int merge_3way(struct merge_options *opt,
{
mmfile_t orig, src1, src2;
struct ll_merge_options ll_opts = {0};
- char *base_name, *name1, *name2;
+ char *base, *name1, *name2;
int merge_status;
ll_opts.renormalize = opt->renormalize;
ll_opts.extra_marker_size = extra_marker_size;
ll_opts.xdl_opts = opt->xdl_opts;
- if (opt->call_depth) {
+ if (opt->priv->call_depth) {
ll_opts.virtual_ancestor = 1;
ll_opts.variant = 0;
} else {
switch (opt->recursive_variant) {
- case MERGE_RECURSIVE_OURS:
+ case MERGE_VARIANT_OURS:
ll_opts.variant = XDL_MERGE_FAVOR_OURS;
break;
- case MERGE_RECURSIVE_THEIRS:
+ case MERGE_VARIANT_THEIRS:
ll_opts.variant = XDL_MERGE_FAVOR_THEIRS;
break;
default:
@@ -1044,16 +1059,13 @@ static int merge_3way(struct merge_options *opt,
}
}
- assert(a->path && b->path);
- if (strcmp(a->path, b->path) ||
- (opt->ancestor != NULL && strcmp(a->path, o->path) != 0)) {
- base_name = opt->ancestor == NULL ? NULL :
- mkpathdup("%s:%s", opt->ancestor, o->path);
+ assert(a->path && b->path && o->path && opt->ancestor);
+ if (strcmp(a->path, b->path) || strcmp(a->path, o->path) != 0) {
+ base = mkpathdup("%s:%s", opt->ancestor, o->path);
name1 = mkpathdup("%s:%s", branch1, a->path);
name2 = mkpathdup("%s:%s", branch2, b->path);
} else {
- base_name = opt->ancestor == NULL ? NULL :
- mkpathdup("%s", opt->ancestor);
+ base = mkpathdup("%s", opt->ancestor);
name1 = mkpathdup("%s", branch1);
name2 = mkpathdup("%s", branch2);
}
@@ -1062,11 +1074,11 @@ static int merge_3way(struct merge_options *opt,
read_mmblob(&src1, &a->oid);
read_mmblob(&src2, &b->oid);
- merge_status = ll_merge(result_buf, a->path, &orig, base_name,
+ merge_status = ll_merge(result_buf, a->path, &orig, base,
&src1, name1, &src2, name2,
opt->repo->index, &ll_opts);
- free(base_name);
+ free(base);
free(name1);
free(name2);
free(orig.ptr);
@@ -1161,7 +1173,7 @@ static int merge_submodule(struct merge_options *opt,
struct object_array merges;
int i;
- int search = !opt->call_depth;
+ int search = !opt->priv->call_depth;
/* store a in result in case we fail */
oidcpy(result, a);
@@ -1345,15 +1357,15 @@ static int merge_mode_and_contents(struct merge_options *opt,
&b->oid);
} else if (S_ISLNK(a->mode)) {
switch (opt->recursive_variant) {
- case MERGE_RECURSIVE_NORMAL:
+ case MERGE_VARIANT_NORMAL:
oidcpy(&result->blob.oid, &a->oid);
if (!oid_eq(&a->oid, &b->oid))
result->clean = 0;
break;
- case MERGE_RECURSIVE_OURS:
+ case MERGE_VARIANT_OURS:
oidcpy(&result->blob.oid, &a->oid);
break;
- case MERGE_RECURSIVE_THEIRS:
+ case MERGE_VARIANT_THEIRS:
oidcpy(&result->blob.oid, &b->oid);
break;
}
@@ -1379,10 +1391,11 @@ static int handle_rename_via_dir(struct merge_options *opt,
const struct rename *ren = ci->ren1;
const struct diff_filespec *dest = ren->pair->two;
char *file_path = dest->path;
- int mark_conflicted = (opt->detect_directory_renames == 1);
+ int mark_conflicted = (opt->detect_directory_renames ==
+ MERGE_DIRECTORY_RENAMES_CONFLICT);
assert(ren->dir_rename_original_dest);
- if (!opt->call_depth && would_lose_untracked(opt, dest->path)) {
+ if (!opt->priv->call_depth && would_lose_untracked(opt, dest->path)) {
mark_conflicted = 1;
file_path = unique_path(opt, dest->path, ren->branch);
output(opt, 1, _("Error: Refusing to lose untracked file at %s; "
@@ -1425,12 +1438,12 @@ static int handle_change_delete(struct merge_options *opt,
const char *update_path = path;
int ret = 0;
- if (dir_in_way(opt->repo->index, path, !opt->call_depth, 0) ||
- (!opt->call_depth && would_lose_untracked(opt, path))) {
+ if (dir_in_way(opt->repo->index, path, !opt->priv->call_depth, 0) ||
+ (!opt->priv->call_depth && would_lose_untracked(opt, path))) {
update_path = alt_path = unique_path(opt, path, change_branch);
}
- if (opt->call_depth) {
+ if (opt->priv->call_depth) {
/*
* We cannot arbitrarily accept either a_sha or b_sha as
* correct; since there is no true "middle point" between
@@ -1505,14 +1518,14 @@ static int handle_rename_delete(struct merge_options *opt,
opt->branch2 : opt->branch1);
if (handle_change_delete(opt,
- opt->call_depth ? orig->path : dest->path,
- opt->call_depth ? NULL : orig->path,
+ opt->priv->call_depth ? orig->path : dest->path,
+ opt->priv->call_depth ? NULL : orig->path,
orig, dest,
rename_branch, delete_branch,
_("rename"), _("renamed")))
return -1;
- if (opt->call_depth)
+ if (opt->priv->call_depth)
return remove_file_from_index(opt->repo->index, dest->path);
else
return update_stages(opt, dest->path, NULL,
@@ -1549,7 +1562,7 @@ static int handle_file_collision(struct merge_options *opt,
/*
* In the recursive case, we just opt to undo renames
*/
- if (opt->call_depth && (prev_path1 || prev_path2)) {
+ if (opt->priv->call_depth && (prev_path1 || prev_path2)) {
/* Put first file (a->oid, a->mode) in its original spot */
if (prev_path1) {
if (update_file(opt, 1, a, prev_path1))
@@ -1578,10 +1591,10 @@ static int handle_file_collision(struct merge_options *opt,
/* Remove rename sources if rename/add or rename/rename(2to1) */
if (prev_path1)
remove_file(opt, 1, prev_path1,
- opt->call_depth || would_lose_untracked(opt, prev_path1));
+ opt->priv->call_depth || would_lose_untracked(opt, prev_path1));
if (prev_path2)
remove_file(opt, 1, prev_path2,
- opt->call_depth || would_lose_untracked(opt, prev_path2));
+ opt->priv->call_depth || would_lose_untracked(opt, prev_path2));
/*
* Remove the collision path, if it wouldn't cause dirty contents
@@ -1623,12 +1636,12 @@ static int handle_file_collision(struct merge_options *opt,
null.mode = 0;
if (merge_mode_and_contents(opt, &null, a, b, collide_path,
- branch1, branch2, opt->call_depth * 2, &mfi))
+ branch1, branch2, opt->priv->call_depth * 2, &mfi))
return -1;
mfi.clean &= !alt_path;
if (update_file(opt, mfi.clean, &mfi.blob, update_path))
return -1;
- if (!mfi.clean && !opt->call_depth &&
+ if (!mfi.clean && !opt->priv->call_depth &&
update_stages(opt, collide_path, NULL, a, b))
return -1;
free(alt_path);
@@ -1668,7 +1681,7 @@ static int handle_rename_add(struct merge_options *opt,
&ci->ren1->src_entry->stages[other_stage],
prev_path_desc,
opt->branch1, opt->branch2,
- 1 + opt->call_depth * 2, &mfi))
+ 1 + opt->priv->call_depth * 2, &mfi))
return -1;
free(prev_path_desc);
@@ -1686,7 +1699,7 @@ static char *find_path_for_conflict(struct merge_options *opt,
const char *branch2)
{
char *new_path = NULL;
- if (dir_in_way(opt->repo->index, path, !opt->call_depth, 0)) {
+ if (dir_in_way(opt->repo->index, path, !opt->priv->call_depth, 0)) {
new_path = unique_path(opt, path, branch1);
output(opt, 1, _("%s is a directory in %s adding "
"as %s instead"),
@@ -1717,17 +1730,17 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
"rename \"%s\"->\"%s\" in \"%s\"%s"),
o->path, a->path, ci->ren1->branch,
o->path, b->path, ci->ren2->branch,
- opt->call_depth ? _(" (left unresolved)") : "");
+ opt->priv->call_depth ? _(" (left unresolved)") : "");
path_desc = xstrfmt("%s and %s, both renamed from %s",
a->path, b->path, o->path);
if (merge_mode_and_contents(opt, o, a, b, path_desc,
ci->ren1->branch, ci->ren2->branch,
- opt->call_depth * 2, &mfi))
+ opt->priv->call_depth * 2, &mfi))
return -1;
free(path_desc);
- if (opt->call_depth) {
+ if (opt->priv->call_depth) {
/*
* FIXME: For rename/add-source conflicts (if we could detect
* such), this is wrong. We should instead find a unique
@@ -1842,12 +1855,12 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
&ci->ren1->src_entry->stages[ostage1],
path_side_1_desc,
opt->branch1, opt->branch2,
- 1 + opt->call_depth * 2, &mfi_c1) ||
+ 1 + opt->priv->call_depth * 2, &mfi_c1) ||
merge_mode_and_contents(opt, b,
&ci->ren2->src_entry->stages[ostage2