restore support for D_NORMAL diffs of regular files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/lib/diffreg.c b/lib/diffreg.c
index 54ebb2f..8cb618f 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -174,6 +174,7 @@ struct line {
static void diff_output(FILE *, const char *, ...);
static int output(FILE *, struct got_diff_changes *, struct got_diff_state *, struct got_diff_args *, const char *, FILE *, const char *, FILE *, int);
static void check(struct got_diff_state *, FILE *, FILE *, int);
+static void range(FILE *, int, int, char *);
static void uni_range(FILE *, int, int);
static void dump_unified_vec(FILE *, struct got_diff_changes *, struct got_diff_state *, struct got_diff_args *, FILE *, FILE *, int);
static int prepare(struct got_diff_state *, int, FILE *, off_t, int);
@@ -874,13 +875,21 @@ output(FILE *outfile, struct got_diff_changes *changes,
if (error)
return (error);
}
- if (ds->anychange != 0)
+ if (ds->anychange != 0 && args->diff_format == D_UNIFIED)
dump_unified_vec(outfile, changes, ds, args, f1, f2, flags);
return (0);
}
static void
+range(FILE *outfile, int a, int b, char *separator)
+{
+ diff_output(outfile, "%d", a > b ? b : a);
+ if (a < b)
+ diff_output(outfile, "%s%d", separator, b);
+}
+
+static void
uni_range(FILE *outfile, int a, int b)
{
if (a < b)
@@ -960,7 +969,17 @@ change(FILE *outfile, struct got_diff_changes *changes,
ds->anychange = 1;
if (args->diff_format == D_BRIEF)
return (0);
- i = fetch(outfile, ds, args, ds->ixnew, c, d, f2, '\0', 0, *pflags);
+ if (args->diff_format == D_NORMAL) {
+ range(outfile, a, b, ",");
+ diff_output(outfile, "%c", a > b ? 'a' : c > d ? 'd' : 'c');
+ range(outfile, c, d, ",");
+ diff_output(outfile, "\n");
+ fetch(outfile, ds, args, ds->ixold, a, b, f1, '<', 1, *pflags);
+ if (a <= b && c <= d)
+ diff_output(outfile, "---\n");
+ }
+ i = fetch(outfile, ds, args, ds->ixnew, c, d, f2,
+ args->diff_format == D_NORMAL ? '>' : '\0', 0, *pflags);
return (0);
}
@@ -977,7 +996,8 @@ fetch(FILE *outfile, struct got_diff_state *ds, struct got_diff_args *args,
nc = f[i] - f[i - 1];
if (ch != '\0') {
diff_output(outfile, "%c", ch);
- if (args->Tflag && args->diff_format == D_UNIFIED)
+ if (args->Tflag && (args->diff_format == D_UNIFIED ||
+ args->diff_format == D_NORMAL))
diff_output(outfile, "\t");
else if (args->diff_format != D_UNIFIED)
diff_output(outfile, " ");
diff --git a/lib/got_lib_diff.h b/lib/got_lib_diff.h
index 93a2f44..edd8672 100644
--- a/lib/got_lib_diff.h
+++ b/lib/got_lib_diff.h
@@ -37,6 +37,7 @@
/*
* Output format options
*/
+#define D_NORMAL 0 /* Normal output */
#define D_UNIFIED 3 /* Unified context diff */
#define D_BRIEF 6 /* Say if the files differ */