Skip to content

Commit 32eaa46

Browse files
pcloudsgitster
authored andcommitted
ll-merge.c: remove implicit dependency on the_index
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5adbb40 commit 32eaa46

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

apply.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,8 @@ static int load_preimage(struct apply_state *state,
34673467
return 0;
34683468
}
34693469

3470-
static int three_way_merge(struct image *image,
3470+
static int three_way_merge(struct apply_state *state,
3471+
struct image *image,
34713472
char *path,
34723473
const struct object_id *base,
34733474
const struct object_id *ours,
@@ -3483,7 +3484,9 @@ static int three_way_merge(struct image *image,
34833484
status = ll_merge(&result, path,
34843485
&base_file, "base",
34853486
&our_file, "ours",
3486-
&their_file, "theirs", NULL);
3487+
&their_file, "theirs",
3488+
state->repo->index,
3489+
NULL);
34873490
free(base_file.ptr);
34883491
free(our_file.ptr);
34893492
free(their_file.ptr);
@@ -3595,7 +3598,7 @@ static int try_threeway(struct apply_state *state,
35953598
clear_image(&tmp_image);
35963599

35973600
/* in-core three-way merge between post and our using pre as base */
3598-
status = three_way_merge(image, patch->new_name,
3601+
status = three_way_merge(state, image, patch->new_name,
35993602
&pre_oid, &our_oid, &post_oid);
36003603
if (status < 0) {
36013604
if (state->apply_verbosity > verbosity_silent)

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ static int checkout_merged(int pos, const struct checkout *state)
208208
* merge.renormalize set, too
209209
*/
210210
status = ll_merge(&result_buf, path, &ancestor, "base",
211-
&ours, "ours", &theirs, "theirs", NULL);
211+
&ours, "ours", &theirs, "theirs",
212+
state->istate, NULL);
212213
free(ancestor.ptr);
213214
free(ours.ptr);
214215
free(theirs.ptr);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
36373637
data.lineno = 0;
36383638
data.o = o;
36393639
data.ws_rule = whitespace_rule(attr_path);
3640-
data.conflict_marker_size = ll_merge_marker_size(attr_path);
3640+
data.conflict_marker_size = ll_merge_marker_size(o->repo->index, attr_path);
36413641

36423642
if (fill_mmfile(o->repo, &mf1, one) < 0 ||
36433643
fill_mmfile(o->repo, &mf2, two) < 0)

ll-merge.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
336336
return &ll_merge_drv[LL_TEXT_MERGE];
337337
}
338338

339-
static void normalize_file(mmfile_t *mm, const char *path)
339+
static void normalize_file(mmfile_t *mm, const char *path, struct index_state *istate)
340340
{
341341
struct strbuf strbuf = STRBUF_INIT;
342-
if (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) {
342+
if (renormalize_buffer(istate, path, mm->ptr, mm->size, &strbuf)) {
343343
free(mm->ptr);
344344
mm->size = strbuf.len;
345345
mm->ptr = strbuf_detach(&strbuf, NULL);
@@ -351,6 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
351351
mmfile_t *ancestor, const char *ancestor_label,
352352
mmfile_t *ours, const char *our_label,
353353
mmfile_t *theirs, const char *their_label,
354+
struct index_state *istate,
354355
const struct ll_merge_options *opts)
355356
{
356357
static struct attr_check *check;
@@ -363,15 +364,15 @@ int ll_merge(mmbuffer_t *result_buf,
363364
opts = &default_opts;
364365

365366
if (opts->renormalize) {
366-
normalize_file(ancestor, path);
367-
normalize_file(ours, path);
368-
normalize_file(theirs, path);
367+
normalize_file(ancestor, path, istate);
368+
normalize_file(ours, path, istate);
369+
normalize_file(theirs, path, istate);
369370
}
370371

371372
if (!check)
372373
check = attr_check_initl("merge", "conflict-marker-size", NULL);
373374

374-
if (!git_check_attr(&the_index, path, check)) {
375+
if (!git_check_attr(istate, path, check)) {
375376
ll_driver_name = check->items[0].value;
376377
if (check->items[1].value) {
377378
marker_size = atoi(check->items[1].value);
@@ -391,14 +392,14 @@ int ll_merge(mmbuffer_t *result_buf,
391392
opts, marker_size);
392393
}
393394

394-
int ll_merge_marker_size(const char *path)
395+
int ll_merge_marker_size(struct index_state *istate, const char *path)
395396
{
396397
static struct attr_check *check;
397398
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
398399

399400
if (!check)
400401
check = attr_check_initl("conflict-marker-size", NULL);
401-
if (!git_check_attr(&the_index, path, check) && check->items[0].value) {
402+
if (!git_check_attr(istate, path, check) && check->items[0].value) {
402403
marker_size = atoi(check->items[0].value);
403404
if (marker_size <= 0)
404405
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;

ll-merge.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "xdiff/xdiff.h"
99

10+
struct index_state;
11+
1012
struct ll_merge_options {
1113
unsigned virtual_ancestor : 1;
1214
unsigned variant : 2; /* favor ours, favor theirs, or union merge */
@@ -19,8 +21,9 @@ int ll_merge(mmbuffer_t *result_buf,
1921
mmfile_t *ancestor, const char *ancestor_label,
2022
mmfile_t *ours, const char *our_label,
2123
mmfile_t *theirs, const char *their_label,
24+
struct index_state *istate,
2225
const struct ll_merge_options *opts);
2326

24-
int ll_merge_marker_size(const char *path);
27+
int ll_merge_marker_size(struct index_state *istate, const char *path);
2528

2629
#endif

merge-blobs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
4141
* common ancestor.
4242
*/
4343
merge_status = ll_merge(&res, path, base, NULL,
44-
our, ".our", their, ".their", NULL);
44+
our, ".our", their, ".their",
45+
&the_index, NULL);
4546
if (merge_status < 0)
4647
return NULL;
4748

merge-recursive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,8 @@ static int merge_3way(struct merge_options *o,
10831083
read_mmblob(&src2, &b->oid);
10841084

10851085
merge_status = ll_merge(result_buf, a->path, &orig, base_name,
1086-
&src1, name1, &src2, name2, &ll_opts);
1086+
&src1, name1, &src2, name2,
1087+
&the_index, &ll_opts);
10871088

10881089
free(base_name);
10891090
free(name1);

notes-merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
348348
read_mmblob(&remote, &p->remote);
349349

350350
status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
351-
&local, o->local_ref, &remote, o->remote_ref, NULL);
351+
&local, o->local_ref, &remote, o->remote_ref,
352+
&the_index, NULL);
352353

353354
free(base.ptr);
354355
free(local.ptr);

rerere.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
478478
{
479479
int hunk_no = 0;
480480
struct rerere_io_file io;
481-
int marker_size = ll_merge_marker_size(path);
481+
int marker_size = ll_merge_marker_size(&the_index, path);
482482

483483
memset(&io, 0, sizeof(io));
484484
io.io.getline = rerere_file_getline;
@@ -641,7 +641,8 @@ static int try_merge(const struct rerere_id *id, const char *path,
641641
* A three-way merge. Note that this honors user-customizable
642642
* low-level merge driver settings.
643643
*/
644-
ret = ll_merge(result, path, &base, NULL, cur, "", &other, "", NULL);
644+
ret = ll_merge(result, path, &base, NULL, cur, "", &other, "",
645+
&the_index, NULL);
645646

646647
free(base.ptr);
647648
free(other.ptr);
@@ -960,7 +961,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
960961
const struct cache_entry *ce;
961962
int pos, len, i, hunk_no;
962963
struct rerere_io_mem io;
963-
int marker_size = ll_merge_marker_size(path);
964+
int marker_size = ll_merge_marker_size(&the_index, path);
964965

965966
/*
966967
* Reproduce the conflicted merge in-core
@@ -995,7 +996,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
995996
*/
996997
ll_merge(&result, path, &mmfile[0], NULL,
997998
&mmfile[1], "ours",
998-
&mmfile[2], "theirs", NULL);
999+
&mmfile[2], "theirs",
1000+
&the_index, NULL);
9991001
for (i = 0; i < 3; i++)
10001002
free(mmfile[i].ptr);
10011003

0 commit comments

Comments
 (0)