From: NeilBrown Date: Mon, 12 Jun 2023 11:53:37 +0000 (+1000) Subject: wiggle: include merge number in attached attributes. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=814bd39b5abb6aba3997f4aec1ae82368160fd79;p=edlib.git wiggle: include merge number in attached attributes. By including the merge number, it is possible to find corresponding locations in the different branches. Also add a leading 'M' if this is the start of a merge, or 'L' if the start of a line within a merge. Signed-off-by: NeilBrown --- diff --git a/lib-wiggle.c b/lib-wiggle.c index 0133dce7..50a1e256 100644 --- a/lib-wiggle.c +++ b/lib-wiggle.c @@ -421,6 +421,7 @@ static void add_merge_markup(struct pane *p safe, const char *attr safe, int which) { struct merge *m; + int mergenum; int pos = 0; if (!f.list || !st) @@ -428,14 +429,14 @@ static void add_merge_markup(struct pane *p safe, st = mark_dup(st); doskip(p, st, NULL, skip, choose); - for (m = merge; m->type != End; m++) { + for (m = merge, mergenum=0; m->type != End; m++, mergenum++) { int len; const char *cp, *endcp; wint_t wch; bool non_space; int chars; char *suffix = ""; - char buf[30]; + char buf[128]; switch (which) { case 0: /* orig - no Extraneous */ @@ -473,8 +474,8 @@ static void add_merge_markup(struct pane *p safe, if (m->type == Conflict && !non_space) suffix = " spaces"; - snprintf(buf, sizeof(buf), "%d %s%s", - chars, typenames[m->type], suffix); + snprintf(buf, sizeof(buf), "M %d %s %d%s", + chars, typenames[m->type], mergenum, suffix); call("doc:set-attr", p, 0, st, attr, 0, NULL, buf); while (chars > 0) { wint_t ch = doc_next(p, st); @@ -485,8 +486,8 @@ static void add_merge_markup(struct pane *p safe, doskip(p, st, NULL, skip, choose); chars -= 1; if (is_eol(ch) && chars > 0) { - snprintf(buf, sizeof(buf), "%d %s%s", chars, - typenames[m->type], suffix); + snprintf(buf, sizeof(buf), "L %d %s %d%s", chars, + typenames[m->type], mergenum, suffix); call("doc:set-attr", p, 0, st, attr, 0, NULL, buf); } diff --git a/python/lib-mergeview.py b/python/lib-mergeview.py index 75ab6f35..96cfa9ce 100644 --- a/python/lib-mergeview.py +++ b/python/lib-mergeview.py @@ -335,23 +335,26 @@ class MergePane(edlib.Pane): return edlib.Efallthrough if str == "render:merge-same": + # [ML] len type num {spaces} w = str2.split() - alen = int(w[0]) - if w[1] == "Unmatched": + alen = int(w[1]) + type = w[2] + spaces = w[4] if len(w) >=5 else "" + if type == "Unmatched": comm2("attr:cb", focus, mark, "fg:blue-80,bg:cyan+20", alen, 103) - if w[1] == "Extraneous": + if type == "Extraneous": comm2("attr:cb", focus, mark, "fg:cyan-60,bg:yellow", alen, 103) - if w[1] == "Changed": + if type == "Changed": if mark < a: comm2("attr:cb", focus, mark, "fg:red-60", alen, 103) else: comm2("attr:cb", focus, mark, "fg:green-60", alen, 103) - if w[1] == "Conflict": - if len(w) >= 3 and w[2] == "spaces": + if type == "Conflict": + if spaces == "spaces": comm2("attr:cb", focus, mark, "fg:red-60,underline", alen, 103) else: comm2("attr:cb", focus, mark, "fg:red-60,inverse", alen, 103) - if w[1] == "AlreadyApplied": + if type == "AlreadyApplied": if mark > b and mark < a: # This part is 'before' - mosly irrelevant comm2("attr:cb", focus, mark, "fg:cyan-60", alen, 103)