]> git.neil.brown.name Git - edlib.git/commitdiff
wiggle: include merge number in attached attributes.
authorNeilBrown <neil@brown.name>
Mon, 12 Jun 2023 11:53:37 +0000 (21:53 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
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 <neil@brown.name>
lib-wiggle.c
python/lib-mergeview.py

index 0133dce7cd769c3c69277f1bd05a89327ad66f39..50a1e25637cd56cfc08c930d519f95509b90bcf5 100644 (file)
@@ -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);
                        }
index 75ab6f358eb7d7fccae28ff4d871046f4b071529..96cfa9ce21e79c16752c48f89ad634fa8ae66c35 100644 (file)
@@ -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)