merge-recursive: Move process_entry's content merging into a function
This move is in preparation for merge_content growing and being called from multiple places in order to handle D/F conflicts. I also snuck in a small change to the output in the case that the merged content for the file matches the current file contents, to make it better match (and thus more able to take over) how other merge_file() calls in process_renames() are handled. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Sep 20, 2010 at 02:28 UTC
0c4918d1c1722c1faaa909f3f8486d5a0d816538
1 file changed
+43
-28
merge-recursive.c
+43
-28
@@ -1138,6 +1138,47 @@ static void handle_delete_modify(struct merge_options *o,
1138
}
1139
}
1140
1141
+
1142
+static int merge_content(struct merge_options *o,
1143
+ const char *path,
1144
+ unsigned char *o_sha, int o_mode,
1145
+ unsigned char *a_sha, int a_mode,
1146
+ unsigned char *b_sha, int b_mode)
1147
+{
1148
+ const char *reason = "content";
1149
+ struct merge_file_info mfi;
1150
+ struct diff_filespec one, a, b;
1151
+
1152
+ if (!o_sha) {
1153
+ reason = "add/add";
1154
+ o_sha = (unsigned char *)null_sha1;
1155
+ }
1156
+ one.path = a.path = b.path = (char *)path;
1157
+ hashcpy(one.sha1, o_sha);
1158
+ one.mode = o_mode;
1159
+ hashcpy(a.sha1, a_sha);
1160
+ a.mode = a_mode;
1161
+ hashcpy(b.sha1, b_sha);
1162
+ b.mode = b_mode;
1163
+
1164
+ mfi = merge_file(o, &one, &a, &b, o->branch1, o->branch2);
1165
+ if (mfi.clean && sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
1166
+ output(o, 3, "Skipped %s (merged same as existing)", path);
1167
+ else
1168
+ output(o, 2, "Auto-merging %s", path);
1169
+
1170
+ if (!mfi.clean) {
1171
+ if (S_ISGITLINK(mfi.mode))
1172
+ reason = "submodule";
1173
+ output(o, 1, "CONFLICT (%s): Merge conflict in %s",
1174
+ reason, path);
1175
+ }
1176
+
1177
+ update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1178
+ return mfi.clean;
1179
+
1180
+}
1181
+
1182
/* Per entry merge function */
1183
static int process_entry(struct merge_options *o,
1184
const char *path, struct stage_data *entry)
@@ -1206,34 +1247,8 @@ static int process_entry(struct merge_options *o,
1247
} else if (a_sha && b_sha) {
1248
/* Case C: Added in both (check for same permissions) and */
1249
/* case D: Modified in both, but differently. */
1209
- const char *reason = "content";
1210
- struct merge_file_info mfi;
1211
- struct diff_filespec one, a, b;
1212
-
1213
- if (!o_sha) {
1214
- reason = "add/add";
1215
- o_sha = (unsigned char *)null_sha1;
1216
- }
1217
- output(o, 2, "Auto-merging %s", path);
1218
- one.path = a.path = b.path = (char *)path;
1219
- hashcpy(one.sha1, o_sha);
1220
- one.mode = o_mode;
1221
- hashcpy(a.sha1, a_sha);
1222
- a.mode = a_mode;
1223
- hashcpy(b.sha1, b_sha);
1224
- b.mode = b_mode;
1225
-
1226
- mfi = merge_file(o, &one, &a, &b,
1227
- o->branch1, o->branch2);
1228
-
1229
- clean_merge = mfi.clean;
1230
- if (!mfi.clean) {
1231
- if (S_ISGITLINK(mfi.mode))
1232
- reason = "submodule";
1233
- output(o, 1, "CONFLICT (%s): Merge conflict in %s",
1234
- reason, path);
1235
- }
1236
- update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1250
+ clean_merge = merge_content(o, path,
1251
+ o_sha, o_mode, a_sha, a_mode, b_sha, b_mode);
1252
} else if (!o_sha && !a_sha && !b_sha) {
1253
/*
1254
* this entry was deleted altogether. a_mode == 0 means