Commit d458eb8d authored by Tom Jones's avatar Tom Jones
Browse files

diff3: make the eflag logic easier to follow

Discussed with:	dim
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D35324
parent d80d7349
......@@ -112,6 +112,11 @@ struct diff {
struct range new;
};
#define EFLAG_NONE 0
#define EFLAG_OVERLAP 1
#define EFLAG_NOOVERLAP 2
#define EFLAG_UNMERGED 3
static size_t szchanges;
static struct diff *d13;
......@@ -313,7 +318,7 @@ merge(int m1, int m2)
/* first file is different from the others */
if (!t2 || (t1 && d1->new.to < d2->new.from)) {
/* stuff peculiar to 1st file */
if (eflag == 0) {
if (eflag == EFLAG_NONE) {
printf("====1\n");
change(1, &d1->old, false);
keep(2, &d1->new);
......@@ -324,7 +329,7 @@ merge(int m1, int m2)
}
/* second file is different from others */
if (!t1 || (t2 && d2->new.to < d1->new.from)) {
if (eflag == 0) {
if (eflag == EFLAG_NONE) {
printf("====2\n");
keep(1, &d2->new);
change(3, &d2->new, false);
......@@ -361,7 +366,7 @@ merge(int m1, int m2)
* dup = 0 means all files differ
* dup = 1 means files 1 and 2 identical
*/
if (eflag == 0) {
if (eflag == EFLAG_NONE) {
printf("====%s\n", dup ? "3" : "");
change(1, &d1->old, dup);
change(2, &d2->old, false);
......@@ -530,9 +535,11 @@ repos(int nchar)
static int
edit(struct diff *diff, bool dup, int j, int difftype)
{
if (((dup + 1) & eflag) == 0)
if (!(eflag == EFLAG_UNMERGED ||
(!dup && eflag == EFLAG_OVERLAP ) ||
(dup && eflag == EFLAG_NOOVERLAP))) {
return (j);
}
j++;
overlap[j] = !dup;
if (!dup)
......@@ -607,7 +614,7 @@ edscript(int n)
if (iflag)
printf("w\nq\n");
exit(eflag == 0 ? overlapcnt : 0);
exit(eflag == EFLAG_NONE ? overlapcnt : 0);
}
/*
......@@ -825,13 +832,13 @@ main(int argc, char **argv)
struct kevent *e;
nblabels = 0;
eflag = 0;
eflag = EFLAG_NONE;
oflag = 0;
diffargv[diffargc++] = __DECONST(char *, diffprog);
while ((ch = getopt_long(argc, argv, OPTIONS, longopts, NULL)) != -1) {
switch (ch) {
case '3':
eflag = 2;
eflag = EFLAG_NOOVERLAP;
break;
case 'a':
diffargv[diffargc++] = __DECONST(char *, "-a");
......@@ -840,10 +847,10 @@ main(int argc, char **argv)
Aflag = 1;
break;
case 'e':
eflag = 3;
eflag = EFLAG_UNMERGED;
break;
case 'E':
eflag = 3;
eflag = EFLAG_UNMERGED;
oflag = 1;
break;
case 'i':
......@@ -864,11 +871,11 @@ main(int argc, char **argv)
Tflag = 1;
break;
case 'x':
eflag = 1;
eflag = EFLAG_OVERLAP;
break;
case 'X':
oflag = 1;
eflag = 1;
eflag = EFLAG_OVERLAP;
break;
case DIFFPROG_OPT:
diffprog = optarg;
......@@ -889,7 +896,7 @@ main(int argc, char **argv)
argv += optind;
if (Aflag) {
eflag = 3;
eflag = EFLAG_UNMERGED;
oflag = 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment