git: c0e6ccb12ab9 - main - diff3: Use ranges for the old and new diffedits in A scripts
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 02 Aug 2022 13:39:11 UTC
The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=c0e6ccb12ab930b122dc18b6079b563bd347155f commit c0e6ccb12ab930b122dc18b6079b563bd347155f Author: Tom Jones <thj@FreeBSD.org> AuthorDate: 2022-08-02 13:29:38 +0000 Commit: Tom Jones <thj@FreeBSD.org> CommitDate: 2022-08-02 13:37:05 +0000 diff3: Use ranges for the old and new diffedits in A scripts This makes the output logic easier to read. No functional change intended. Sponsored by: Klara, Inc. --- usr.bin/diff3/diff3.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 37a98a635742..fa0aeb11d008 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -714,51 +714,54 @@ Ascript(int n) static void mergescript(int i) { - struct range r; + struct range r, *new, *old; int n; r.from = 1; r.to = 1; for (n = 1; n < i+1; n++) { + new = &de[n].new; + old = &de[n].old; + /* print any lines leading up to here */ - r.to = de[n].old.from; + r.to = old->from; printrange(fp[0], &r); if (de[n].type == DIFF_TYPE2) { printf("%s %s\n", oldmark, f2mark); - printrange(fp[1], &de[n].old); + printrange(fp[1], old); printf("%s\n", divider); - printrange(fp[2], &de[n].new); + printrange(fp[2], new); printf("%s %s\n", newmark, f3mark); } else if (de[n].type == DIFF_TYPE3) { if (!oflag || !overlap[n]) { - printrange(fp[2], &de[n].new); + printrange(fp[2], new); } else { printf("%s %s\n", oldmark, f1mark); - printrange(fp[0], &de[n].old); + printrange(fp[0], old); printf("%s %s\n", orgmark, f2mark); - if (de[n].old.from == de[n].old.to) { + if (old->from == old->to) { struct range or; - or.from = de[n].old.from -1; - or.to = de[n].new.to; + or.from = old->from - 1; + or.to = new->to; printrange(fp[1], &or); } else - printrange(fp[1], &de[n].old); + printrange(fp[1], old); printf("%s\n", divider); - printrange(fp[2], &de[n].new); + printrange(fp[2], new); printf("%s %s\n", newmark, f3mark); } } - if (de[n].old.from == de[n].old.to) - r.from = de[n].new.to; + if (old->from == old->to) + r.from = new->to; else - r.from = de[n].old.to; + r.from = old->to; } /* * Print from the final range to the end of 'myfile'. Any deletions or @@ -768,11 +771,13 @@ mergescript(int i) * If the new range is 0 length (from == to), we need to use the old * range. */ - if ((de[n-1].old.from == de[n-1].new.from) && - (de[n-1].old.to == de[n-1].new.to)) + new = &de[n-1].new; + old = &de[n-1].old; + if ((old->from == new->from) && + (old->to == new->to)) r.from--; - else if (de[n-1].new.from == de[n-1].new.to) - r.from = de[n-1].old.from; + else if (new->from == new->to) + r.from = old->from; /* * If the range is a 3 way merge then we need to skip a line in the