merge-recursive: move more is_dirty handling to merge_content
conflict_rename_normal() was doing some handling for dirty files that more naturally belonged in merge_content. Move it, and rename a parameter for clarity while at it. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Apr 19, 2018 at 10:58 UTC
bd42380ef1ec773d1557b28ba6924f4020333143
1 file changed
+12
-18
merge-recursive.c
+12
-18
@@ -2727,7 +2727,7 @@ static int handle_modify_delete(struct merge_options *o,
2727
2728
static int merge_content(struct merge_options *o,
2729
const char *path,
2730
- int file_in_way,
2730
+ int is_dirty,
2731
struct object_id *o_oid, int o_mode,
2732
struct object_id *a_oid, int a_mode,
2733
struct object_id *b_oid, int b_mode,
@@ -2803,7 +2803,7 @@ static int merge_content(struct merge_options *o,
2803
return -1;
2804
}
2805
2806
- if (df_conflict_remains || file_in_way) {
2806
+ if (df_conflict_remains || is_dirty) {
2807
char *new_path;
2808
if (o->call_depth) {
2809
remove_file_from_cache(path);
@@ -2825,6 +2825,10 @@ static int merge_content(struct merge_options *o,
2825
2826
}
2827
new_path = unique_path(o, path, rename_conflict_info->branch1);
2828
+ if (is_dirty) {
2829
+ output(o, 1, _("Refusing to lose dirty file at %s"),
2830
+ path);
2831
+ }
2832
output(o, 1, _("Adding as %s instead"), new_path);
2833
if (update_file(o, 0, &mfi.oid, mfi.mode, new_path)) {
2834
free(new_path);
@@ -2834,7 +2838,7 @@ static int merge_content(struct merge_options *o,
2838
mfi.clean = 0;
2839
} else if (update_file(o, mfi.clean, &mfi.oid, mfi.mode, path))
2840
return -1;
2837
- return mfi.clean;
2841
+ return !is_dirty && mfi.clean;
2842
}
2843
2844
static int conflict_rename_normal(struct merge_options *o,
@@ -2844,21 +2848,10 @@ static int conflict_rename_normal(struct merge_options *o,
2848
struct object_id *b_oid, unsigned int b_mode,
2849
struct rename_conflict_info *ci)
2850
{
2847
- int clean_merge;
2848
- int file_in_the_way = 0;
2849
-
2850
- if (was_dirty(o, path)) {
2851
- file_in_the_way = 1;
2852
- output(o, 1, _("Refusing to lose dirty file at %s"), path);
2853
- }
2854
-
2851
/* Merge the content and write it out */
2856
- clean_merge = merge_content(o, path, file_in_the_way,
2857
- o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
2858
- ci);
2859
- if (clean_merge > 0 && file_in_the_way)
2860
- clean_merge = 0;
2861
- return clean_merge;
2852
+ return merge_content(o, path, was_dirty(o, path),
2853
+ o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
2854
+ ci);
2855
}
2856
2857
/* Per entry merge function */
@@ -2981,7 +2974,8 @@ static int process_entry(struct merge_options *o,
2974
} else if (a_oid && b_oid) {
2975
/* Case C: Added in both (check for same permissions) and */
2976
/* case D: Modified in both, but differently. */
2984
- clean_merge = merge_content(o, path, 0 /* file_in_way */,
2977
+ int is_dirty = 0; /* unpack_trees would have bailed if dirty */
2978
+ clean_merge = merge_content(o, path, is_dirty,
2979
o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
2980
NULL);
2981
} else if (!o_oid && !a_oid && !b_oid) {