Skip to content

Commit e9cd1b5

Browse files
newrengitster
authored andcommitted
merge-recursive: shrink rename_conflict_info
The rename_conflict_info struct used both a pair and a stage_data which were taken from a rename struct. Just use the original rename struct. This will also allow us to start making other simplifications to the code. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 967d6be commit e9cd1b5

File tree

1 file changed

+50
-70
lines changed

1 file changed

+50
-70
lines changed

merge-recursive.c

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,20 @@ struct rename {
238238

239239
struct rename_conflict_info {
240240
enum rename_type rename_type;
241-
struct diff_filepair *pair1;
242-
struct diff_filepair *pair2;
241+
struct rename *ren1;
242+
struct rename *ren2;
243243
const char *branch1;
244244
const char *branch2;
245-
struct stage_data *dst_entry1;
246-
struct stage_data *dst_entry2;
247245
struct diff_filespec ren1_other;
248246
struct diff_filespec ren2_other;
249247
};
250248

251249
static inline void setup_rename_conflict_info(enum rename_type rename_type,
252-
struct diff_filepair *pair1,
253-
struct diff_filepair *pair2,
250+
struct merge_options *opt,
251+
struct rename *ren1,
252+
struct rename *ren2,
254253
const char *branch1,
255254
const char *branch2,
256-
struct stage_data *dst_entry1,
257-
struct stage_data *dst_entry2,
258-
struct merge_options *opt,
259255
struct stage_data *src_entry1,
260256
struct stage_data *src_entry2)
261257
{
@@ -269,31 +265,27 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
269265
* ensure that branch1 == opt->branch1. So, simply flip arguments
270266
* around if we don't have that.
271267
*/
272-
if (dst_entry2 && branch1 != opt->branch1) {
268+
if (ren2 && branch1 != opt->branch1) {
273269
setup_rename_conflict_info(rename_type,
274-
pair2, pair1,
275-
branch2, branch1,
276-
dst_entry2, dst_entry1,
277270
opt,
271+
ren2, ren1,
272+
branch2, branch1,
278273
src_entry2, src_entry1);
279274
return;
280275
}
281276

282277
ci = xcalloc(1, sizeof(struct rename_conflict_info));
283278
ci->rename_type = rename_type;
284-
ci->pair1 = pair1;
279+
ci->ren1 = ren1;
280+
ci->ren2 = ren2;
285281
ci->branch1 = branch1;
286282
ci->branch2 = branch2;
287283

288-
ci->dst_entry1 = dst_entry1;
289-
dst_entry1->rename_conflict_info = ci;
290-
dst_entry1->processed = 0;
284+
ci->ren1->dst_entry->processed = 0;
285+
ci->ren1->dst_entry->rename_conflict_info = ci;
291286

292-
assert(!pair2 == !dst_entry2);
293-
if (dst_entry2) {
294-
ci->dst_entry2 = dst_entry2;
295-
ci->pair2 = pair2;
296-
dst_entry2->rename_conflict_info = ci;
287+
if (ren2) {
288+
ci->ren2->dst_entry->rename_conflict_info = ci;
297289
}
298290

299291
/*
@@ -305,15 +297,15 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
305297
rename_type == RENAME_TWO_FILES_TO_ONE) {
306298
ostage1 = opt->branch1 == branch1 ? 3 : 2;
307299

308-
ci->ren1_other.path = pair1->one->path;
300+
ci->ren1_other.path = ren1->pair->one->path;
309301
oidcpy(&ci->ren1_other.oid, &src_entry1->stages[ostage1].oid);
310302
ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
311303
}
312304

313305
if (rename_type == RENAME_TWO_FILES_TO_ONE) {
314306
ostage2 = ostage1 ^ 1;
315307

316-
ci->ren2_other.path = pair2->one->path;
308+
ci->ren2_other.path = ren2->pair->one->path;
317309
oidcpy(&ci->ren2_other.oid, &src_entry2->stages[ostage2].oid);
318310
ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
319311
}
@@ -1694,8 +1686,8 @@ static int handle_rename_add(struct merge_options *opt,
16941686
struct rename_conflict_info *ci)
16951687
{
16961688
/* a was renamed to c, and a separate c was added. */
1697-
struct diff_filespec *a = ci->pair1->one;
1698-
struct diff_filespec *c = ci->pair1->two;
1689+
struct diff_filespec *a = ci->ren1->pair->one;
1690+
struct diff_filespec *c = ci->ren1->pair->two;
16991691
char *path = c->path;
17001692
char *prev_path_desc;
17011693
struct merge_file_info mfi;
@@ -1718,8 +1710,8 @@ static int handle_rename_add(struct merge_options *opt,
17181710
c->path, a->path, NULL,
17191711
ci->branch1, ci->branch2,
17201712
&mfi.oid, mfi.mode,
1721-
&ci->dst_entry1->stages[other_stage].oid,
1722-
ci->dst_entry1->stages[other_stage].mode);
1713+
&ci->ren1->dst_entry->stages[other_stage].oid,
1714+
ci->ren1->dst_entry->stages[other_stage].mode);
17231715
}
17241716

17251717
static char *find_path_for_conflict(struct merge_options *opt,
@@ -1750,9 +1742,9 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17501742
struct merge_file_info mfi;
17511743
struct diff_filespec other;
17521744
struct diff_filespec *add;
1753-
struct diff_filespec *o = ci->pair1->one;
1754-
struct diff_filespec *a = ci->pair1->two;
1755-
struct diff_filespec *b = ci->pair2->two;
1745+
struct diff_filespec *o = ci->ren1->pair->one;
1746+
struct diff_filespec *a = ci->ren1->pair->two;
1747+
struct diff_filespec *b = ci->ren2->pair->two;
17561748
char *path_desc;
17571749

17581750
output(opt, 1, _("CONFLICT (rename/rename): "
@@ -1788,14 +1780,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17881780
* such cases, we should keep the added file around,
17891781
* resolving the conflict at that path in its favor.
17901782
*/
1791-
add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1783+
add = filespec_from_entry(&other, ci->ren1->dst_entry, 2 ^ 1);
17921784
if (add) {
17931785
if (update_file(opt, 0, &add->oid, add->mode, a->path))
17941786
return -1;
17951787
}
17961788
else
17971789
remove_file_from_index(opt->repo->index, a->path);
1798-
add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1790+
add = filespec_from_entry(&other, ci->ren2->dst_entry, 3 ^ 1);
17991791
if (add) {
18001792
if (update_file(opt, 0, &add->oid, add->mode, b->path))
18011793
return -1;
@@ -1808,7 +1800,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
18081800
* rename/add collision. If not, we can write the file out
18091801
* to the specified location.
18101802
*/
1811-
add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1803+
add = filespec_from_entry(&other, ci->ren1->dst_entry, 2 ^ 1);
18121804
if (add) {
18131805
if (handle_file_collision(opt, a->path,
18141806
NULL, NULL,
@@ -1827,7 +1819,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
18271819
return -1;
18281820
}
18291821

1830-
add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1822+
add = filespec_from_entry(&other, ci->ren2->dst_entry, 3 ^ 1);
18311823
if (add) {
18321824
if (handle_file_collision(opt, b->path,
18331825
NULL, NULL,
@@ -1854,10 +1846,10 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
18541846
struct rename_conflict_info *ci)
18551847
{
18561848
/* Two files, a & b, were renamed to the same thing, c. */
1857-
struct diff_filespec *a = ci->pair1->one;
1858-
struct diff_filespec *b = ci->pair2->one;
1859-
struct diff_filespec *c1 = ci->pair1->two;
1860-
struct diff_filespec *c2 = ci->pair2->two;
1849+
struct diff_filespec *a = ci->ren1->pair->one;
1850+
struct diff_filespec *b = ci->ren2->pair->one;
1851+
struct diff_filespec *c1 = ci->ren1->pair->two;
1852+
struct diff_filespec *c2 = ci->ren2->pair->two;
18611853
char *path = c1->path; /* == c2->path */
18621854
char *path_side_1_desc;
18631855
char *path_side_2_desc;
@@ -2732,13 +2724,11 @@ static int process_renames(struct merge_options *opt,
27322724
ren2->pair->two);
27332725
}
27342726
setup_rename_conflict_info(rename_type,
2735-
ren1->pair,
2736-
ren2->pair,
2727+
opt,
2728+
ren1,
2729+
ren2,
27372730
branch1,
27382731
branch2,
2739-
ren1->dst_entry,
2740-
ren2->dst_entry,
2741-
opt,
27422732
NULL,
27432733
NULL);
27442734
} else if ((lookup = string_list_lookup(renames2Dst, ren1_dst))) {
@@ -2759,13 +2749,11 @@ static int process_renames(struct merge_options *opt,
27592749
ren2->src_entry->processed = 1;
27602750

27612751
setup_rename_conflict_info(RENAME_TWO_FILES_TO_ONE,
2762-
ren1->pair,
2763-
ren2->pair,
2752+
opt,
2753+
ren1,
2754+
ren2,
27642755
branch1,
27652756
branch2,
2766-
ren1->dst_entry,
2767-
ren2->dst_entry,
2768-
opt,
27692757
ren1->src_entry,
27702758
ren2->src_entry);
27712759

@@ -2802,24 +2790,20 @@ static int process_renames(struct merge_options *opt,
28022790
if (oid_eq(&src_other.oid, &null_oid) &&
28032791
ren1->add_turned_into_rename) {
28042792
setup_rename_conflict_info(RENAME_VIA_DIR,
2805-
ren1->pair,
2793+
opt,
2794+
ren1,
28062795
NULL,
28072796
branch1,
28082797
branch2,
2809-
ren1->dst_entry,
2810-
NULL,
2811-
opt,
28122798
NULL,
28132799
NULL);
28142800
} else if (oid_eq(&src_other.oid, &null_oid)) {
28152801
setup_rename_conflict_info(RENAME_DELETE,
2816-
ren1->pair,
2802+
opt,
2803+
ren1,
28172804
NULL,
28182805
branch1,
28192806
branch2,
2820-
ren1->dst_entry,
2821-
NULL,
2822-
opt,
28232807
NULL,
28242808
NULL);
28252809
} else if ((dst_other.mode == ren1->pair->two->mode) &&
@@ -2848,13 +2832,11 @@ static int process_renames(struct merge_options *opt,
28482832
* file, then the merge will be clean.
28492833
*/
28502834
setup_rename_conflict_info(RENAME_ADD,
2851-
ren1->pair,
2835+
opt,
2836+
ren1,
28522837
NULL,
28532838
branch1,
28542839
branch2,
2855-
ren1->dst_entry,
2856-
NULL,
2857-
opt,
28582840
ren1->src_entry,
28592841
NULL);
28602842
} else
@@ -2876,13 +2858,11 @@ static int process_renames(struct merge_options *opt,
28762858
}
28772859
update_entry(ren1->dst_entry, o, a, b);
28782860
setup_rename_conflict_info(RENAME_NORMAL,
2879-
ren1->pair,
2861+
opt,
2862+
ren1,
28802863
NULL,
28812864
branch1,
28822865
NULL,
2883-
ren1->dst_entry,
2884-
NULL,
2885-
opt,
28862866
NULL,
28872867
NULL);
28882868
}
@@ -3119,15 +3099,15 @@ static int handle_content_merge(struct merge_options *opt,
31193099
b.mode = b_mode;
31203100

31213101
if (ci) {
3122-
struct diff_filepair *pair1 = ci->pair1;
3102+
struct diff_filepair *pair1 = ci->ren1->pair;
31233103

31243104
path1 = (opt->branch1 == ci->branch1) ?
31253105
pair1->two->path : pair1->one->path;
3126-
/* If ci->pair2 != NULL, we are in
3106+
/* If ci->ren2->pair != NULL, we are in
31273107
* RENAME_ONE_FILE_TO_ONE case. Otherwise, we have a
31283108
* normal rename.
31293109
*/
3130-
path2 = (ci->pair2 ||
3110+
path2 = ((ci->ren2 && ci->ren2->pair) ||
31313111
opt->branch2 == ci->branch1) ?
31323112
pair1->two->path : pair1->one->path;
31333113
one.path = pair1->one->path;
@@ -3264,7 +3244,7 @@ static int process_entry(struct merge_options *opt,
32643244
break;
32653245
case RENAME_VIA_DIR:
32663246
clean_merge = 1;
3267-
if (handle_rename_via_dir(opt, ci->pair1, ci->branch1))
3247+
if (handle_rename_via_dir(opt, ci->ren1->pair, ci->branch1))
32683248
clean_merge = -1;
32693249
break;
32703250
case RENAME_ADD:
@@ -3278,7 +3258,7 @@ static int process_entry(struct merge_options *opt,
32783258
break;
32793259
case RENAME_DELETE:
32803260
clean_merge = 0;
3281-
if (handle_rename_delete(opt, ci->pair1,
3261+
if (handle_rename_delete(opt, ci->ren1->pair,
32823262
ci->branch1, ci->branch2))
32833263
clean_merge = -1;
32843264
break;

0 commit comments

Comments
 (0)