Skip to content

Commit c336ab8

Browse files
newrengitster
authored andcommitted
merge-recursive: track branch where rename occurred in rename struct
We previously tracked the branch associated with a rename in a separate field in rename_conflict_info, but since it is directly associated with the rename it makes more sense to move it into the rename struct. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3f9c92e commit c336ab8

File tree

1 file changed

+42
-71
lines changed

1 file changed

+42
-71
lines changed

merge-recursive.c

Lines changed: 42 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ struct stage_data {
211211

212212
struct rename {
213213
struct diff_filepair *pair;
214+
const char *branch; /* branch that the rename occurred on */
214215
/*
215216
* Purpose of src_entry and dst_entry:
216217
*
@@ -240,16 +241,12 @@ struct rename_conflict_info {
240241
enum rename_type rename_type;
241242
struct rename *ren1;
242243
struct rename *ren2;
243-
const char *branch1;
244-
const char *branch2;
245244
};
246245

247246
static inline void setup_rename_conflict_info(enum rename_type rename_type,
248247
struct merge_options *opt,
249248
struct rename *ren1,
250-
struct rename *ren2,
251-
const char *branch1,
252-
const char *branch2)
249+
struct rename *ren2)
253250
{
254251
struct rename_conflict_info *ci;
255252

@@ -260,20 +257,15 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
260257
* ensure that branch1 == opt->branch1. So, simply flip arguments
261258
* around if we don't have that.
262259
*/
263-
if (ren2 && branch1 != opt->branch1) {
264-
setup_rename_conflict_info(rename_type,
265-
opt,
266-
ren2, ren1,
267-
branch2, branch1);
260+
if (ren2 && ren1->branch != opt->branch1) {
261+
setup_rename_conflict_info(rename_type, opt, ren2, ren1);
268262
return;
269263
}
270264

271265
ci = xcalloc(1, sizeof(struct rename_conflict_info));
272266
ci->rename_type = rename_type;
273267
ci->ren1 = ren1;
274268
ci->ren2 = ren2;
275-
ci->branch1 = branch1;
276-
ci->branch2 = branch2;
277269

278270
ci->ren1->dst_entry->processed = 0;
279271
ci->ren1->dst_entry->rename_conflict_info = ci;
@@ -1665,12 +1657,15 @@ static int handle_rename_add(struct merge_options *opt,
16651657
char *prev_path_desc;
16661658
struct merge_file_info mfi;
16671659

1668-
int other_stage = (ci->branch1 == opt->branch1 ? 3 : 2);
1660+
const char *rename_branch = ci->ren1->branch;
1661+
const char *add_branch = (opt->branch1 == rename_branch ?
1662+
opt->branch2 : opt->branch1);
1663+
int other_stage = (ci->ren1->branch == opt->branch1 ? 3 : 2);
16691664

16701665
output(opt, 1, _("CONFLICT (rename/add): "
16711666
"Rename %s->%s in %s. Added %s in %s"),
1672-
a->path, c->path, ci->branch1,
1673-
c->path, ci->branch2);
1667+
a->path, c->path, rename_branch,
1668+
c->path, add_branch);
16741669

16751670
filespec_from_entry(&tmp, ci->ren1->src_entry, other_stage);
16761671
tmp.path = a->path;
@@ -1685,7 +1680,7 @@ static int handle_rename_add(struct merge_options *opt,
16851680

16861681
return handle_file_collision(opt,
16871682
c->path, a->path, NULL,
1688-
ci->branch1, ci->branch2,
1683+
rename_branch, add_branch,
16891684
&mfi.oid, mfi.mode,
16901685
&ci->ren1->dst_entry->stages[other_stage].oid,
16911686
ci->ren1->dst_entry->stages[other_stage].mode);
@@ -1727,14 +1722,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17271722
output(opt, 1, _("CONFLICT (rename/rename): "
17281723
"Rename \"%s\"->\"%s\" in branch \"%s\" "
17291724
"rename \"%s\"->\"%s\" in \"%s\"%s"),
1730-
o->path, a->path, ci->branch1,
1731-
o->path, b->path, ci->branch2,
1725+
o->path, a->path, ci->ren1->branch,
1726+
o->path, b->path, ci->ren2->branch,
17321727
opt->call_depth ? _(" (left unresolved)") : "");
17331728

17341729
path_desc = xstrfmt("%s and %s, both renamed from %s",
17351730
a->path, b->path, o->path);
17361731
if (merge_mode_and_contents(opt, o, a, b, path_desc,
1737-
ci->branch1, ci->branch2,
1732+
ci->ren1->branch, ci->ren2->branch,
17381733
opt->call_depth * 2, &mfi))
17391734
return -1;
17401735
free(path_desc);
@@ -1781,14 +1776,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17811776
if (add) {
17821777
if (handle_file_collision(opt, a->path,
17831778
NULL, NULL,
1784-
ci->branch1, ci->branch2,
1779+
ci->ren1->branch,
1780+
ci->ren2->branch,
17851781
&mfi.oid, mfi.mode,
17861782
&add->oid, add->mode) < 0)
17871783
return -1;
17881784
} else {
17891785
char *new_path = find_path_for_conflict(opt, a->path,
1790-
ci->branch1,
1791-
ci->branch2);
1786+
ci->ren1->branch,
1787+
ci->ren2->branch);
17921788
if (update_file(opt, 0, &mfi.oid, mfi.mode, new_path ? new_path : a->path))
17931789
return -1;
17941790
free(new_path);
@@ -1800,14 +1796,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
18001796
if (add) {
18011797
if (handle_file_collision(opt, b->path,
18021798
NULL, NULL,
1803-
ci->branch1, ci->branch2,
1799+
ci->ren1->branch,
1800+
ci->ren2->branch,
18041801
&add->oid, add->mode,
18051802
&mfi.oid, mfi.mode) < 0)
18061803
return -1;
18071804
} else {
18081805
char *new_path = find_path_for_conflict(opt, b->path,
1809-
ci->branch2,
1810-
ci->branch1);
1806+
ci->ren2->branch,
1807+
ci->ren1->branch);
18111808
if (update_file(opt, 0, &mfi.oid, mfi.mode, new_path ? new_path : b->path))
18121809
return -1;
18131810
free(new_path);
@@ -1837,8 +1834,8 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
18371834
output(opt, 1, _("CONFLICT (rename/rename): "
18381835
"Rename %s->%s in %s. "
18391836
"Rename %s->%s in %s"),
1840-
a->path, c1->path, ci->branch1,
1841-
b->path, c2->path, ci->branch2);
1837+
a->path, c1->path, ci->ren1->branch,
1838+
b->path, c2->path, ci->ren2->branch);
18421839

18431840
filespec_from_entry(&tmp1, ci->ren1->src_entry, 3);
18441841
tmp1.path = a->path;
@@ -1858,7 +1855,7 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
18581855
free(path_side_2_desc);
18591856

18601857
return handle_file_collision(opt, path, a->path, b->path,
1861-
ci->branch1, ci->branch2,
1858+
ci->ren1->branch, ci->ren2->branch,
18621859
&mfi_c1.oid, mfi_c1.mode,
18631860
&mfi_c2.oid, mfi_c2.mode);
18641861
}
@@ -2542,6 +2539,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
25422539
* information; tree is always equal to either a_tree or b_tree.
25432540
*/
25442541
static struct string_list *get_renames(struct merge_options *opt,
2542+
const char *branch,
25452543
struct diff_queue_struct *pairs,
25462544
struct hashmap *dir_renames,
25472545
struct hashmap *dir_rename_exclusions,
@@ -2585,6 +2583,7 @@ static struct string_list *get_renames(struct merge_options *opt,
25852583
re->processed = 0;
25862584
re->add_turned_into_rename = 0;
25872585
re->pair = pair;
2586+
re->branch = branch;
25882587
item = string_list_lookup(entries, re->pair->one->path);
25892588
if (!item)
25902589
re->src_entry = insert_stage_data(re->pair->one->path,
@@ -2639,7 +2638,6 @@ static int process_renames(struct merge_options *opt,
26392638
for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
26402639
struct string_list *renames1, *renames2Dst;
26412640
struct rename *ren1 = NULL, *ren2 = NULL;
2642-
const char *branch1, *branch2;
26432641
const char *ren1_src, *ren1_dst;
26442642
struct string_list_item *lookup;
26452643

@@ -2660,13 +2658,9 @@ static int process_renames(struct merge_options *opt,
26602658
if (ren1) {
26612659
renames1 = a_renames;
26622660
renames2Dst = &b_by_dst;
2663-
branch1 = opt->branch1;
2664-
branch2 = opt->branch2;
26652661
} else {
26662662
renames1 = b_renames;
26672663
renames2Dst = &a_by_dst;
2668-
branch1 = opt->branch2;
2669-
branch2 = opt->branch1;
26702664
SWAP(ren2, ren1);
26712665
}
26722666

@@ -2706,12 +2700,7 @@ static int process_renames(struct merge_options *opt,
27062700
ren1->pair->two,
27072701
ren2->pair->two);
27082702
}
2709-
setup_rename_conflict_info(rename_type,
2710-
opt,
2711-
ren1,
2712-
ren2,
2713-
branch1,
2714-
branch2);
2703+
setup_rename_conflict_info(rename_type, opt, ren1, ren2);
27152704
} else if ((lookup = string_list_lookup(renames2Dst, ren1_dst))) {
27162705
/* Two different files renamed to the same thing */
27172706
char *ren2_dst;
@@ -2730,11 +2719,7 @@ static int process_renames(struct merge_options *opt,
27302719
ren2->src_entry->processed = 1;
27312720

27322721
setup_rename_conflict_info(RENAME_TWO_FILES_TO_ONE,
2733-
opt,
2734-
ren1,
2735-
ren2,
2736-
branch1,
2737-
branch2);
2722+
opt, ren1, ren2);
27382723

27392724
} else {
27402725
/* Renamed in 1, maybe changed in 2 */
@@ -2769,18 +2754,10 @@ static int process_renames(struct merge_options *opt,
27692754
if (oid_eq(&src_other.oid, &null_oid) &&
27702755
ren1->add_turned_into_rename) {
27712756
setup_rename_conflict_info(RENAME_VIA_DIR,
2772-
opt,
2773-
ren1,
2774-
NULL,
2775-
branch1,
2776-
branch2);
2757+
opt, ren1, NULL);
27772758
} else if (oid_eq(&src_other.oid, &null_oid)) {
27782759
setup_rename_conflict_info(RENAME_DELETE,
2779-
opt,
2780-
ren1,
2781-
NULL,
2782-
branch1,
2783-
branch2);
2760+
opt, ren1, NULL);
27842761
} else if ((dst_other.mode == ren1->pair->two->mode) &&
27852762
oid_eq(&dst_other.oid, &ren1->pair->two->oid)) {
27862763
/*
@@ -2807,11 +2784,7 @@ static int process_renames(struct merge_options *opt,
28072784
* file, then the merge will be clean.
28082785
*/
28092786
setup_rename_conflict_info(RENAME_ADD,
2810-
opt,
2811-
ren1,
2812-
NULL,
2813-
branch1,
2814-
branch2);
2787+
opt, ren1, NULL);
28152788
} else
28162789
try_merge = 1;
28172790

@@ -2831,11 +2804,7 @@ static int process_renames(struct merge_options *opt,
28312804
}
28322805
update_entry(ren1->dst_entry, o, a, b);
28332806
setup_rename_conflict_info(RENAME_NORMAL,
2834-
opt,
2835-
ren1,
2836-
NULL,
2837-
branch1,
2838-
NULL);
2807+
opt, ren1, NULL);
28392808
}
28402809
}
28412810
}
@@ -2904,13 +2873,13 @@ static int detect_and_process_renames(struct merge_options *opt,
29042873
dir_rename_init(dir_re_merge);
29052874
}
29062875

2907-
ri->head_renames = get_renames(opt, head_pairs,
2876+
ri->head_renames = get_renames(opt, opt->branch1, head_pairs,
29082877
dir_re_merge, dir_re_head, head,
29092878
common, head, merge, entries,
29102879
&clean);
29112880
if (clean < 0)
29122881
goto cleanup;
2913-
ri->merge_renames = get_renames(opt, merge_pairs,
2882+
ri->merge_renames = get_renames(opt, opt->branch2, merge_pairs,
29142883
dir_re_head, dir_re_merge, merge,
29152884
common, head, merge, entries,
29162885
&clean);
@@ -3072,14 +3041,14 @@ static int handle_content_merge(struct merge_options *opt,
30723041
if (ci) {
30733042
struct diff_filepair *pair1 = ci->ren1->pair;
30743043

3075-
path1 = (opt->branch1 == ci->branch1) ?
3044+
path1 = (opt->branch1 == ci->ren1->branch) ?
30763045
pair1->two->path : pair1->one->path;
30773046
/* If ci->ren2->pair != NULL, we are in
30783047
* RENAME_ONE_FILE_TO_ONE case. Otherwise, we have a
30793048
* normal rename.
30803049
*/
30813050
path2 = ((ci->ren2 && ci->ren2->pair) ||
3082-
opt->branch2 == ci->branch1) ?
3051+
opt->branch2 == ci->ren1->branch) ?
30833052
pair1->two->path : pair1->one->path;
30843053
one.path = pair1->one->path;
30853054
a.path = (char *)path1;
@@ -3157,7 +3126,7 @@ static int handle_content_merge(struct merge_options *opt,
31573126
}
31583127

31593128
}
3160-
new_path = unique_path(opt, path, ci->branch1);
3129+
new_path = unique_path(opt, path, ci->ren1->branch);
31613130
if (is_dirty) {
31623131
output(opt, 1, _("Refusing to lose dirty file at %s"),
31633132
path);
@@ -3215,7 +3184,8 @@ static int process_entry(struct merge_options *opt,
32153184
break;
32163185
case RENAME_VIA_DIR:
32173186
clean_merge = 1;
3218-
if (handle_rename_via_dir(opt, ci->ren1->pair, ci->branch1))
3187+
if (handle_rename_via_dir(opt, ci->ren1->pair,
3188+
ci->ren1->branch))
32193189
clean_merge = -1;
32203190
break;
32213191
case RENAME_ADD:
@@ -3230,7 +3200,8 @@ static int process_entry(struct merge_options *opt,
32303200
case RENAME_DELETE:
32313201
clean_merge = 0;
32323202
if (handle_rename_delete(opt, ci->ren1->pair,
3233-
ci->branch1, ci->branch2))
3203+
ci->ren1->branch,
3204+
ci->ren1->branch == opt->branch1 ? opt->branch2 : opt->branch1))
32343205
clean_merge = -1;
32353206
break;
32363207
case RENAME_ONE_FILE_TO_TWO:

0 commit comments

Comments
 (0)