Skip to content

Commit bd42380

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd53b7f commit bd42380

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

merge-recursive.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ static int handle_modify_delete(struct merge_options *o,
27272727

27282728
static int merge_content(struct merge_options *o,
27292729
const char *path,
2730-
int file_in_way,
2730+
int is_dirty,
27312731
struct object_id *o_oid, int o_mode,
27322732
struct object_id *a_oid, int a_mode,
27332733
struct object_id *b_oid, int b_mode,
@@ -2803,7 +2803,7 @@ static int merge_content(struct merge_options *o,
28032803
return -1;
28042804
}
28052805

2806-
if (df_conflict_remains || file_in_way) {
2806+
if (df_conflict_remains || is_dirty) {
28072807
char *new_path;
28082808
if (o->call_depth) {
28092809
remove_file_from_cache(path);
@@ -2825,6 +2825,10 @@ static int merge_content(struct merge_options *o,
28252825

28262826
}
28272827
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+
}
28282832
output(o, 1, _("Adding as %s instead"), new_path);
28292833
if (update_file(o, 0, &mfi.oid, mfi.mode, new_path)) {
28302834
free(new_path);
@@ -2834,7 +2838,7 @@ static int merge_content(struct merge_options *o,
28342838
mfi.clean = 0;
28352839
} else if (update_file(o, mfi.clean, &mfi.oid, mfi.mode, path))
28362840
return -1;
2837-
return mfi.clean;
2841+
return !is_dirty && mfi.clean;
28382842
}
28392843

28402844
static int conflict_rename_normal(struct merge_options *o,
@@ -2844,21 +2848,10 @@ static int conflict_rename_normal(struct merge_options *o,
28442848
struct object_id *b_oid, unsigned int b_mode,
28452849
struct rename_conflict_info *ci)
28462850
{
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-
28552851
/* 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);
28622855
}
28632856

28642857
/* Per entry merge function */
@@ -2981,7 +2974,8 @@ static int process_entry(struct merge_options *o,
29812974
} else if (a_oid && b_oid) {
29822975
/* Case C: Added in both (check for same permissions) and */
29832976
/* 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,
29852979
o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
29862980
NULL);
29872981
} else if (!o_oid && !a_oid && !b_oid) {

0 commit comments

Comments
 (0)