Skip to content

Commit 18b037a

Browse files
jrngitster
authored andcommitted
ll-merge: let caller decide whether to renormalize
Add a “renormalize” bit to the ll-merge options word so callers can decide on a case-by-case basis whether the merge is likely to have overlapped with a change in smudge/clean rules. This reveals a few commands that have not been taking that situation into account, though it does not fix them. No functional change intended. Cc: Eyvind Bernhardsen <[email protected]> Improved-by: Junio C Hamano <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73cf7f7 commit 18b037a

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

builtin/checkout.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ static int checkout_merged(int pos, struct checkout *state)
150150
read_mmblob(&ours, active_cache[pos+1]->sha1);
151151
read_mmblob(&theirs, active_cache[pos+2]->sha1);
152152

153+
/*
154+
* NEEDSWORK: re-create conflicts from merges with
155+
* merge.renormalize set, too
156+
*/
153157
status = ll_merge(&result_buf, path, &ancestor, "base",
154158
&ours, "ours", &theirs, "theirs", 0);
155159
free(ancestor.ptr);

ll-merge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
9999
int flag, int marker_size)
100100
{
101101
/* Use union favor */
102-
flag = (flag & LL_OPT_VIRTUAL_ANCESTOR) |
103-
create_ll_flag(XDL_MERGE_FAVOR_UNION);
102+
flag &= ~LL_OPT_FAVOR_MASK;
103+
flag |= create_ll_flag(XDL_MERGE_FAVOR_UNION);
104104
return ll_xdl_merge(drv_unused, result, path_unused,
105105
orig, NULL, src1, NULL, src2, NULL,
106106
flag, marker_size);
@@ -345,7 +345,7 @@ int ll_merge(mmbuffer_t *result_buf,
345345
const struct ll_merge_driver *driver;
346346
int virtual_ancestor = flag & LL_OPT_VIRTUAL_ANCESTOR;
347347

348-
if (merge_renormalize) {
348+
if (flag & LL_OPT_RENORMALIZE) {
349349
normalize_file(ancestor, path);
350350
normalize_file(ours, path);
351351
normalize_file(theirs, path);

ll-merge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define LL_OPT_VIRTUAL_ANCESTOR (1 << 0)
99
#define LL_OPT_FAVOR_MASK ((1 << 1) | (1 << 2))
1010
#define LL_OPT_FAVOR_SHIFT 1
11+
#define LL_OPT_RENORMALIZE (1 << 3)
1112

1213
static inline int ll_opt_favor(int flag)
1314
{

merge-recursive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ static int merge_3way(struct merge_options *o,
648648
merge_status = ll_merge(result_buf, a->path, &orig, base_name,
649649
&src1, name1, &src2, name2,
650650
((o->call_depth ? LL_OPT_VIRTUAL_ANCESTOR : 0) |
651+
(o->renormalize ? LL_OPT_RENORMALIZE : 0) |
651652
create_ll_flag(favor)));
652653

653654
free(name1);

rerere.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
319319
if (!mmfile[i].ptr && !mmfile[i].size)
320320
mmfile[i].ptr = xstrdup("");
321321
}
322+
/*
323+
* NEEDSWORK: handle conflicts from merges with
324+
* merge.renormalize set, too
325+
*/
322326
ll_merge(&result, path, &mmfile[0], NULL,
323327
&mmfile[1], "ours",
324328
&mmfile[2], "theirs", 0);
@@ -361,7 +365,7 @@ static int find_conflict(struct string_list *conflict)
361365
return 0;
362366
}
363367

364-
static int merge(const char *name, const char *path)
368+
static int merge(const char *name, int renormalize, const char *path)
365369
{
366370
int ret;
367371
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
@@ -376,7 +380,8 @@ static int merge(const char *name, const char *path)
376380
ret = 1;
377381
goto out;
378382
}
379-
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", 0);
383+
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "",
384+
renormalize ? LL_OPT_RENORMALIZE : 0);
380385
if (!ret) {
381386
FILE *f = fopen(path, "w");
382387
if (!f)
@@ -424,7 +429,7 @@ static int update_paths(struct string_list *update)
424429
return status;
425430
}
426431

427-
static int do_plain_rerere(struct string_list *rr, int fd)
432+
static int do_plain_rerere(struct string_list *rr, int fd, int renormalize)
428433
{
429434
struct string_list conflict = { NULL, 0, 0, 1 };
430435
struct string_list update = { NULL, 0, 0, 1 };
@@ -469,7 +474,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
469474
const char *name = (const char *)rr->items[i].util;
470475

471476
if (has_rerere_resolution(name)) {
472-
if (!merge(name, path)) {
477+
if (!merge(name, renormalize, path)) {
473478
if (rerere_autoupdate)
474479
string_list_insert(path, &update);
475480
fprintf(stderr,
@@ -553,7 +558,7 @@ int rerere(int flags)
553558
fd = setup_rerere(&merge_rr, flags);
554559
if (fd < 0)
555560
return 0;
556-
return do_plain_rerere(&merge_rr, fd);
561+
return do_plain_rerere(&merge_rr, fd, merge_renormalize);
557562
}
558563

559564
static int rerere_forget_one_path(const char *path, struct string_list *rr)

0 commit comments

Comments
 (0)