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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-09-21 17:57:27 +02:00 committed by Junio C Hamano
parent 5adbb403c2
commit 32eaa46883
9 changed files with 34 additions and 21 deletions

View File

@ -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)

View 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);

2
diff.c
View File

@ -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)

View 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;

View 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

View 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;

View 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);

View 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);

View File

@ -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);