Skip to content

Commit b2c8c0a

Browse files
newrengitster
authored andcommitted
merge-recursive: When we detect we can skip an update, actually skip it
In 882fd11 (merge-recursive: Delay content merging for renames 2010-09-20), there was code that checked for whether we could skip updating a file in the working directory, based on whether the merged version matched the current working copy. Due to the desire to handle directory/file conflicts that were resolvable, that commit deferred content merging by first updating the index with the unmerged entries and then moving the actual merging (along with the skip-the-content-update check) to another function that ran later in the merge process. As part moving the content merging code, a bug was introduced such that although the message about skipping the update would be printed (whenever GIT_MERGE_VERBOSITY was sufficiently high), the file would be unconditionally updated in the working copy anyway. When we detect that the file does not need to be updated in the working copy, update the index appropriately and then return early before updating the working copy. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eeba0d1 commit b2c8c0a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

merge-recursive.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,11 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
354354
* make room for the corresponding directory. Such paths will
355355
* later be processed in process_df_entry() at the end. If
356356
* the corresponding directory ends up being removed by the
357-
* merge, then the file will be reinstated at that time;
358-
* otherwise, if the file is not supposed to be removed by the
359-
* merge, the contents of the file will be placed in another
360-
* unique filename.
357+
* merge, then the file will be reinstated at that time
358+
* (albeit with a different timestamp!); otherwise, if the
359+
* file is not supposed to be removed by the merge, the
360+
* contents of the file will be placed in another unique
361+
* filename.
361362
*
362363
* NOTE: This function relies on the fact that entries for a
363364
* D/F conflict will appear adjacent in the index, with the
@@ -1272,9 +1273,13 @@ static int merge_content(struct merge_options *o,
12721273
}
12731274

12741275
if (mfi.clean && !df_conflict_remains &&
1275-
sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
1276+
sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode &&
1277+
lstat(path, &st) == 0) {
12761278
output(o, 3, "Skipped %s (merged same as existing)", path);
1277-
else
1279+
add_cacheinfo(mfi.mode, mfi.sha, path,
1280+
0 /*stage*/, 1 /*refresh*/, 0 /*options*/);
1281+
return mfi.clean;
1282+
} else
12781283
output(o, 2, "Auto-merging %s", path);
12791284

12801285
if (!mfi.clean) {

t/t6022-merge-rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ test_expect_success 'setup avoid unnecessary update, normal rename' '
728728
git commit -m "Random, unrelated changes"
729729
'
730730

731-
test_expect_failure 'avoid unnecessary update, normal rename' '
731+
test_expect_success 'avoid unnecessary update, normal rename' '
732732
git checkout -q avoid-unnecessary-update-1^0 &&
733733
test-chmtime =1000000000 rename &&
734734
test-chmtime -v +0 rename >expect &&

0 commit comments

Comments
 (0)