ll-merge.c: remove implicit dependency on the_index
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 21 Sep 2018 15:57:27 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Sep 2018 16:48:10 +0000 (09:48 -0700)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c
builtin/checkout.c
diff.c
ll-merge.c
ll-merge.h
merge-blobs.c
merge-recursive.c
notes-merge.c
rerere.c
diff --git a/apply.c b/apply.c
index e485fbc6bc11efc6daefe78cbe949a65560ff4fa..ea111ab13f45f517bd0c6c9df86181982fd27895 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3467,7 +3467,8 @@ static int load_preimage(struct apply_state *state,
        return 0;
 }
 
-static int three_way_merge(struct image *image,
+static int three_way_merge(struct apply_state *state,
+                          struct image *image,
                           char *path,
                           const struct object_id *base,
                           const struct object_id *ours,
@@ -3483,7 +3484,9 @@ static int three_way_merge(struct image *image,
        status = ll_merge(&result, path,
                          &base_file, "base",
                          &our_file, "ours",
-                         &their_file, "theirs", NULL);
+                         &their_file, "theirs",
+                         state->repo->index,
+                         NULL);
        free(base_file.ptr);
        free(our_file.ptr);
        free(their_file.ptr);
@@ -3595,7 +3598,7 @@ static int try_threeway(struct apply_state *state,
        clear_image(&tmp_image);
 
        /* in-core three-way merge between post and our using pre as base */
-       status = three_way_merge(image, patch->new_name,
+       status = three_way_merge(state, image, patch->new_name,
                                 &pre_oid, &our_oid, &post_oid);
        if (status < 0) {
                if (state->apply_verbosity > verbosity_silent)
index 29ef50013dccbd118093af0b4dc08eb907953cc2..cd9be501611b4522ab7bdc80f9328e88426f3dd5 100644 (file)
@@ -208,7 +208,8 @@ static int checkout_merged(int pos, const struct checkout *state)
         * merge.renormalize set, too
         */
        status = ll_merge(&result_buf, path, &ancestor, "base",
-                         &ours, "ours", &theirs, "theirs", NULL);
+                         &ours, "ours", &theirs, "theirs",
+                         state->istate, NULL);
        free(ancestor.ptr);
        free(ours.ptr);
        free(theirs.ptr);
diff --git a/diff.c b/diff.c
index 1bcc0818df30a773c5661900e9e920915ddc28b8..a06c3b070c698f4b612124cd07f066461e17f123 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -3637,7 +3637,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
        data.lineno = 0;
        data.o = o;
        data.ws_rule = whitespace_rule(attr_path);
-       data.conflict_marker_size = ll_merge_marker_size(attr_path);
+       data.conflict_marker_size = ll_merge_marker_size(o->repo->index, attr_path);
 
        if (fill_mmfile(o->repo, &mf1, one) < 0 ||
            fill_mmfile(o->repo, &mf2, two) < 0)
index 0e2800f7bb46bdf9e1713d210a5dc1c02fbbaa26..c339ef8ae87b316f39ba25a47da42c38d965cabd 100644 (file)
@@ -336,10 +336,10 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
        return &ll_merge_drv[LL_TEXT_MERGE];
 }
 
-static void normalize_file(mmfile_t *mm, const char *path)
+static void normalize_file(mmfile_t *mm, const char *path, struct index_state *istate)
 {
        struct strbuf strbuf = STRBUF_INIT;
-       if (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) {
+       if (renormalize_buffer(istate, path, mm->ptr, mm->size, &strbuf)) {
                free(mm->ptr);
                mm->size = strbuf.len;
                mm->ptr = strbuf_detach(&strbuf, NULL);
@@ -351,6 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
             mmfile_t *ancestor, const char *ancestor_label,
             mmfile_t *ours, const char *our_label,
             mmfile_t *theirs, const char *their_label,
+            struct index_state *istate,
             const struct ll_merge_options *opts)
 {
        static struct attr_check *check;
@@ -363,15 +364,15 @@ int ll_merge(mmbuffer_t *result_buf,
                opts = &default_opts;
 
        if (opts->renormalize) {
-               normalize_file(ancestor, path);
-               normalize_file(ours, path);
-               normalize_file(theirs, path);
+               normalize_file(ancestor, path, istate);
+               normalize_file(ours, path, istate);
+               normalize_file(theirs, path, istate);
        }
 
        if (!check)
                check = attr_check_initl("merge", "conflict-marker-size", NULL);
 
-       if (!git_check_attr(&the_index, path, check)) {
+       if (!git_check_attr(istate, path, check)) {
                ll_driver_name = check->items[0].value;
                if (check->items[1].value) {
                        marker_size = atoi(check->items[1].value);
@@ -391,14 +392,14 @@ int ll_merge(mmbuffer_t *result_buf,
                          opts, marker_size);
 }
 
-int ll_merge_marker_size(const char *path)
+int ll_merge_marker_size(struct index_state *istate, const char *path)
 {
        static struct attr_check *check;
        int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
 
        if (!check)
                check = attr_check_initl("conflict-marker-size", NULL);
-       if (!git_check_attr(&the_index, path, check) && check->items[0].value) {
+       if (!git_check_attr(istate, path, check) && check->items[0].value) {
                marker_size = atoi(check->items[0].value);
                if (marker_size <= 0)
                        marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
index b72b19921e8f33ab23aa5bb6293b9b6841035df9..6c6e22e40d9bab4b5071319acd5356993e7888b4 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "xdiff/xdiff.h"
 
+struct index_state;
+
 struct ll_merge_options {
        unsigned virtual_ancestor : 1;
        unsigned variant : 2;   /* favor ours, favor theirs, or union merge */
@@ -19,8 +21,9 @@ int ll_merge(mmbuffer_t *result_buf,
             mmfile_t *ancestor, const char *ancestor_label,
             mmfile_t *ours, const char *our_label,
             mmfile_t *theirs, const char *their_label,
+            struct index_state *istate,
             const struct ll_merge_options *opts);
 
-int ll_merge_marker_size(const char *path);
+int ll_merge_marker_size(struct index_state *istate, const char *path);
 
 #endif
index fabb8c19ce983962b45c415f66c11236fa906bfe..668fb2e05dd39ecb45f7f78a86949b2d98c80ebf 100644 (file)
@@ -41,7 +41,8 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
         * common ancestor.
         */
        merge_status = ll_merge(&res, path, base, NULL,
-                               our, ".our", their, ".their", NULL);
+                               our, ".our", their, ".their",
+                               &the_index, NULL);
        if (merge_status < 0)
                return NULL;
 
index 939843e81555e151fea6c897e81538f4abb74713..7edcda4db05c7c4ba34a4ea2eb19f5df57a27e59 100644 (file)
@@ -1083,7 +1083,8 @@ static int merge_3way(struct merge_options *o,
        read_mmblob(&src2, &b->oid);
 
        merge_status = ll_merge(result_buf, a->path, &orig, base_name,
-                               &src1, name1, &src2, name2, &ll_opts);
+                               &src1, name1, &src2, name2,
+                               &the_index, &ll_opts);
 
        free(base_name);
        free(name1);
index 9b154a5da6b27ea9ad55b3404d5e3ad4f7c8d744..432edfb89afb29b992dbbd103a6eeecc52c5db8f 100644 (file)
@@ -348,7 +348,8 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
        read_mmblob(&remote, &p->remote);
 
        status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
-                         &local, o->local_ref, &remote, o->remote_ref, NULL);
+                         &local, o->local_ref, &remote, o->remote_ref,
+                         &the_index, NULL);
 
        free(base.ptr);
        free(local.ptr);
index c7787aa07f80f00589e3c4f4e4e3cc825c43044e..e65d8fc06f2ccf9907c7f7a9e72dc59963927353 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -478,7 +478,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
 {
        int hunk_no = 0;
        struct rerere_io_file io;
-       int marker_size = ll_merge_marker_size(path);
+       int marker_size = ll_merge_marker_size(&the_index, path);
 
        memset(&io, 0, sizeof(io));
        io.io.getline = rerere_file_getline;
@@ -641,7 +641,8 @@ static int try_merge(const struct rerere_id *id, const char *path,
                 * A three-way merge. Note that this honors user-customizable
                 * low-level merge driver settings.
                 */
-               ret = ll_merge(result, path, &base, NULL, cur, "", &other, "", NULL);
+               ret = ll_merge(result, path, &base, NULL, cur, "", &other, "",
+                              &the_index, NULL);
 
        free(base.ptr);
        free(other.ptr);
@@ -960,7 +961,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
        const struct cache_entry *ce;
        int pos, len, i, hunk_no;
        struct rerere_io_mem io;
-       int marker_size = ll_merge_marker_size(path);
+       int marker_size = ll_merge_marker_size(&the_index, path);
 
        /*
         * Reproduce the conflicted merge in-core
@@ -995,7 +996,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
         */
        ll_merge(&result, path, &mmfile[0], NULL,
                 &mmfile[1], "ours",
-                &mmfile[2], "theirs", NULL);
+                &mmfile[2], "theirs",
+                &the_index, NULL);
        for (i = 0; i < 3; i++)
                free(mmfile[i].ptr);