ll-merge.c: remove implicit dependency on the_index
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 21, 2018 at 17:57 UTC
32eaa4688387d37398f0bc498335355a28efb0c7
9 files changed
+34
-21
apply.c
+6
-3
@@ -3467,7 +3467,8 @@ static int load_preimage(struct apply_state *state,
3467
return 0;
3468
}
3469
3470
-static int three_way_merge(struct image *image,
3470
+static int three_way_merge(struct apply_state *state,
3471
+ struct image *image,
3472
char *path,
3473
const struct object_id *base,
3474
const struct object_id *ours,
@@ -3483,7 +3484,9 @@ static int three_way_merge(struct image *image,
3484
status = ll_merge(&result, path,
3485
&base_file, "base",
3486
&our_file, "ours",
3486
- &their_file, "theirs", NULL);
3487
+ &their_file, "theirs",
3488
+ state->repo->index,
3489
+ NULL);
3490
free(base_file.ptr);
3491
free(our_file.ptr);
3492
free(their_file.ptr);
@@ -3595,7 +3598,7 @@ static int try_threeway(struct apply_state *state,
3598
clear_image(&tmp_image);
3599
3600
/* 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,
3602
&pre_oid, &our_oid, &post_oid);
3603
if (status < 0) {
3604
if (state->apply_verbosity > verbosity_silent)
builtin/checkout.c
+2
-1
@@ -208,7 +208,8 @@ static int checkout_merged(int pos, const struct checkout *state)
208
* merge.renormalize set, too
209
*/
210
status = ll_merge(&result_buf, path, &ancestor, "base",
211
- &ours, "ours", &theirs, "theirs", NULL);
211
+ &ours, "ours", &theirs, "theirs",
212
+ state->istate, NULL);
213
free(ancestor.ptr);
214
free(ours.ptr);
215
free(theirs.ptr);
diff.c
+1
-1
@@ -3637,7 +3637,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
3637
data.lineno = 0;
3638
data.o = o;
3639
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);
3641
3642
if (fill_mmfile(o->repo, &mf1, one) < 0 ||
3643
fill_mmfile(o->repo, &mf2, two) < 0)
ll-merge.c
+9
-8
@@ -336,10 +336,10 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
336
return &ll_merge_drv[LL_TEXT_MERGE];
337
}
338
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)
340
{
341
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)) {
343
free(mm->ptr);
344
mm->size = strbuf.len;
345
mm->ptr = strbuf_detach(&strbuf, NULL);
@@ -351,6 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
351
mmfile_t *ancestor, const char *ancestor_label,
352
mmfile_t *ours, const char *our_label,
353
mmfile_t *theirs, const char *their_label,
354
+ struct index_state *istate,
355
const struct ll_merge_options *opts)
356
{
357
static struct attr_check *check;
@@ -363,15 +364,15 @@ int ll_merge(mmbuffer_t *result_buf,
364
opts = &default_opts;
365
366
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);
370
}
371
372
if (!check)
373
check = attr_check_initl("merge", "conflict-marker-size", NULL);
374
374
- if (!git_check_attr(&the_index, path, check)) {
375
+ if (!git_check_attr(istate, path, check)) {
376
ll_driver_name = check->items[0].value;
377
if (check->items[1].value) {
378
marker_size = atoi(check->items[1].value);
@@ -391,14 +392,14 @@ int ll_merge(mmbuffer_t *result_buf,
392
opts, marker_size);
393
}
394
394
-int ll_merge_marker_size(const char *path)
395
+int ll_merge_marker_size(struct index_state *istate, const char *path)
396
{
397
static struct attr_check *check;
398
int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
399
400
if (!check)
401
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) {
403
marker_size = atoi(check->items[0].value);
404
if (marker_size <= 0)
405
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
ll-merge.h
+4
-1
@@ -7,6 +7,8 @@
7
8
#include "xdiff/xdiff.h"
9
10
+struct index_state;
11
+
12
struct ll_merge_options {
13
unsigned virtual_ancestor : 1;
14
unsigned variant : 2; /* favor ours, favor theirs, or union merge */
@@ -19,8 +21,9 @@ int ll_merge(mmbuffer_t *result_buf,
21
mmfile_t *ancestor, const char *ancestor_label,
22
mmfile_t *ours, const char *our_label,
23
mmfile_t *theirs, const char *their_label,
24
+ struct index_state *istate,
25
const struct ll_merge_options *opts);
26
24
-int ll_merge_marker_size(const char *path);
27
+int ll_merge_marker_size(struct index_state *istate, const char *path);
28
29
#endif
merge-blobs.c
+2
-1
@@ -41,7 +41,8 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
41
* common ancestor.
42
*/
43
merge_status = ll_merge(&res, path, base, NULL,
44
- our, ".our", their, ".their", NULL);
44
+ our, ".our", their, ".their",
45
+ &the_index, NULL);
46
if (merge_status < 0)
47
return NULL;
48
merge-recursive.c
+2
-1
@@ -1083,7 +1083,8 @@ static int merge_3way(struct merge_options *o,
1083
read_mmblob(&src2, &b->oid);
1084
1085
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);
1088
1089
free(base_name);
1090
free(name1);
notes-merge.c
+2
-1
@@ -348,7 +348,8 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
348
read_mmblob(&remote, &p->remote);
349
350
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);
353
354
free(base.ptr);
355
free(local.ptr);
rerere.c
+6
-4
@@ -478,7 +478,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
478
{
479
int hunk_no = 0;
480
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);
482
483
memset(&io, 0, sizeof(io));
484
io.io.getline = rerere_file_getline;
@@ -641,7 +641,8 @@ static int try_merge(const struct rerere_id *id, const char *path,
641
* A three-way merge. Note that this honors user-customizable
642
* low-level merge driver settings.
643
*/
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);
646
647
free(base.ptr);
648
free(other.ptr);
@@ -960,7 +961,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
961
const struct cache_entry *ce;
962
int pos, len, i, hunk_no;
963
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);
965
966
/*
967
* Reproduce the conflicted merge in-core
@@ -995,7 +996,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
996
*/
997
ll_merge(&result, path, &mmfile[0], NULL,
998
&mmfile[1], "ours",
998
- &mmfile[2], "theirs", NULL);
999
+ &mmfile[2], "theirs",
1000
+ &the_index, NULL);
1001
for (i = 0; i < 3; i++)
1002
free(mmfile[i].ptr);
1003