merge-recursive: New function to assist resolving renames in-core only
process_renames() and process_entry() have nearly identical code for doing three-way file merging to resolve content changes. Since we are already deferring some of the current rename handling in order to better handle D/F conflicts, it seems to make sense to defer content merging as well and remove the (nearly) duplicated code sections for handling this merging. To facilitate this process, add a new update_stages_and_entry() function which will map the higher stage index entries from two files involved in a rename into the resulting rename destination's index entries, and update the associated stage_data structure. 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
2ff739f9d2fd2f34e7a7bfb9b5f2d1d2b2ec5326
1 file changed
+30
-3
merge-recursive.c
+30
-3
@@ -417,11 +417,10 @@ static struct string_list *get_renames(struct merge_options *o,
417
return renames;
418
}
419
420
-static int update_stages(const char *path, struct diff_filespec *o,
420
+static int update_stages_options(const char *path, struct diff_filespec *o,
421
struct diff_filespec *a, struct diff_filespec *b,
422
- int clear)
422
+ int clear, int options)
423
{
424
- int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE;
424
if (clear)
425
if (remove_file_from_cache(path))
426
return -1;
@@ -437,6 +436,34 @@ static int update_stages(const char *path, struct diff_filespec *o,
436
return 0;
437
}
438
439
+static int update_stages(const char *path, struct diff_filespec *o,
440
+ struct diff_filespec *a, struct diff_filespec *b,
441
+ int clear)
442
+{
443
+ int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE;
444
+ return update_stages_options(path, o, a, b, clear, options);
445
+}
446
+
447
+static int update_stages_and_entry(const char *path,
448
+ struct stage_data *entry,
449
+ struct diff_filespec *o,
450
+ struct diff_filespec *a,
451
+ struct diff_filespec *b,
452
+ int clear)
453
+{
454
+ int options;
455
+
456
+ entry->processed = 0;
457
+ entry->stages[1].mode = o->mode;
458
+ entry->stages[2].mode = a->mode;
459
+ entry->stages[3].mode = b->mode;
460
+ hashcpy(entry->stages[1].sha, o->sha1);
461
+ hashcpy(entry->stages[2].sha, a->sha1);
462
+ hashcpy(entry->stages[3].sha, b->sha1);
463
+ options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK;
464
+ return update_stages_options(path, o, a, b, clear, options);
465
+}
466
+
467
static int remove_file(struct merge_options *o, int clean,
468
const char *path, int no_wd)
469
{