summaryrefslogtreecommitdiffstats
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2018-11-07 20:40:31 -0800
committerJunio C Hamano <gitster@pobox.com>2018-11-08 14:23:54 +0900
commit80cee6e3210120a8a45fc4818e0049f482247b0f (patch)
tree4ee78d79433a13358a90704610eaf740f11c64f6 /merge-recursive.c
parentb8cd1bb71306e489d73e5cf4ef75a6cdb4c223b7 (diff)
downloadgit-80cee6e3210120a8a45fc4818e0049f482247b0f.tar.gz
git-80cee6e3210120a8a45fc4818e0049f482247b0f.tar.xz
merge-recursive: combine error handling
In handle_rename_rename_1to2(), we have duplicated error handling around colliding paths. Specifically, when we want to write out the file and there is a directory or untracked file in the way, we need to create a temporary file to hold the contents. This has some special output to alert the user, and this output is duplicated for each side of the conflict. Simplify the call by generating this new path in a helper function. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 59811116b..5e36bef16 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1709,6 +1709,27 @@ static int handle_rename_add(struct merge_options *o,
ci->dst_entry1->stages[other_stage].mode);
}
+static char *find_path_for_conflict(struct merge_options *o,
+ const char *path,
+ const char *branch1,
+ const char *branch2)
+{
+ char *new_path = NULL;
+ if (dir_in_way(path, !o->call_depth, 0)) {
+ new_path = unique_path(o, path, branch1);
+ output(o, 1, _("%s is a directory in %s adding "
+ "as %s instead"),
+ path, branch2, new_path);
+ } else if (would_lose_untracked(path)) {
+ new_path = unique_path(o, path, branch1);
+ output(o, 1, _("Refusing to lose untracked file"
+ " at %s; adding as %s instead"),
+ path, new_path);
+ }
+
+ return new_path;
+}
+
static int handle_rename_rename_1to2(struct merge_options *o,
struct rename_conflict_info *ci)
{
@@ -1783,19 +1804,9 @@ static int handle_rename_rename_1to2(struct merge_options *o,
&add->oid, add->mode) < 0)
return -1;
} else {
- char *new_path = NULL;
- if (dir_in_way(a->path, !o->call_depth, 0)) {
- new_path = unique_path(o, a->path, ci->branch1);
- output(o, 1, _("%s is a directory in %s adding "
- "as %s instead"),
- a->path, ci->branch2, new_path);
- } else if (would_lose_untracked(a->path)) {
- new_path = unique_path(o, a->path, ci->branch1);
- output(o, 1, _("Refusing to lose untracked file"
- " at %s; adding as %s instead"),
- a->path, new_path);
- }
-
+ char *new_path = find_path_for_conflict(o, a->path,
+ ci->branch1,
+ ci->branch2);
if (update_file(o, 0, &mfi.oid, mfi.mode, new_path ? new_path : a->path))
return -1;
free(new_path);
@@ -1812,19 +1823,9 @@ static int handle_rename_rename_1to2(struct merge_options *o,
&mfi.oid, mfi.mode) < 0)
return -1;
} else {
- char *new_path = NULL;
- if (dir_in_way(b->path, !o->call_depth, 0)) {
- new_path = unique_path(o, b->path, ci->branch2);
- output(o, 1, _("%s is a directory in %s adding "
- "as %s instead"),
- b->path, ci->branch1, new_path);
- } else if (would_lose_untracked(b->path)) {
- new_path = unique_path(o, b->path, ci->branch2);
- output(o, 1, _("Refusing to lose untracked file"
- " at %s; adding as %s instead"),
- b->path, new_path);
- }
-
+ char *new_path = find_path_for_conflict(o, b->path,
+ ci->branch2,
+ ci->branch1);
if (update_file(o, 0, &mfi.oid, mfi.mode, new_path ? new_path : b->path))
return -1;
free(new_path);