diff: implement flag -B (Ignore changes whose lines are all blank)
>>From 7c3ce93213590bd0592435dc27d1272d0fd3309b Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizvekov@gmail.com> Date: Mon, 18 Jan 2010 15:52:31 -0200 Subject: [PATCH] diff: implement flag -B (Ignore changes whose lines are all blank) function old new delta diffreg 1196 1240 +44 .rodata 6538 6561 +23 packed_usage 457 478 +21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 88/0) Total: 88 bytes text data bss dec hex filename 70123 733 8576 79432 13648 busybox_old 70190 733 8576 79499 1368b busybox_unstripped Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b7a044043c
commit
fe1ce2e43e
@ -95,16 +95,20 @@ enum { /* Commandline flags */
|
|||||||
FLAG_b,
|
FLAG_b,
|
||||||
FLAG_d,
|
FLAG_d,
|
||||||
FLAG_i,
|
FLAG_i,
|
||||||
FLAG_L, /* unused */
|
FLAG_L, /* never used, handled by getopt32 */
|
||||||
FLAG_N,
|
FLAG_N,
|
||||||
FLAG_q,
|
FLAG_q,
|
||||||
FLAG_r,
|
FLAG_r,
|
||||||
FLAG_s,
|
FLAG_s,
|
||||||
FLAG_S, /* unused */
|
FLAG_S, /* never used, handled by getopt32 */
|
||||||
FLAG_t,
|
FLAG_t,
|
||||||
FLAG_T,
|
FLAG_T,
|
||||||
FLAG_U, /* unused */
|
FLAG_U, /* never used, handled by getopt32 */
|
||||||
FLAG_w,
|
FLAG_w,
|
||||||
|
FLAG_u, /* ignored, this is the default */
|
||||||
|
FLAG_p, /* not implemented */
|
||||||
|
FLAG_B,
|
||||||
|
FLAG_E, /* not implemented */
|
||||||
};
|
};
|
||||||
#define FLAG(x) (1 << FLAG_##x)
|
#define FLAG(x) (1 << FLAG_##x)
|
||||||
|
|
||||||
@ -578,6 +582,8 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
|
|||||||
int idx = -1, i = 1;
|
int idx = -1, i = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
bool nonempty = false;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct context_vec v;
|
struct context_vec v;
|
||||||
|
|
||||||
@ -606,6 +612,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
|
|||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
nonempty |= (v.a >= v.b) && (v.c >= v.d);
|
||||||
vec = xrealloc_vector(vec, 6, ++idx);
|
vec = xrealloc_vector(vec, 6, ++idx);
|
||||||
vec[idx] = v;
|
vec[idx] = v;
|
||||||
}
|
}
|
||||||
@ -617,7 +624,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
|
|||||||
}
|
}
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
continue;
|
continue;
|
||||||
if (!(option_mask32 & FLAG(q))) {
|
if (!(option_mask32 & FLAG(q)) && !((option_mask32 & FLAG(B)) && !nonempty)) {
|
||||||
struct context_vec *cvp = vec;
|
struct context_vec *cvp = vec;
|
||||||
int lowa = MAX(1, cvp->a - opt_U_context);
|
int lowa = MAX(1, cvp->a - opt_U_context);
|
||||||
int upb = MIN(nlen[0], vec[idx].b + opt_U_context);
|
int upb = MIN(nlen[0], vec[idx].b + opt_U_context);
|
||||||
@ -880,8 +887,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
/* exactly 2 params; collect multiple -L <label>; -U N */
|
/* exactly 2 params; collect multiple -L <label>; -U N */
|
||||||
opt_complementary = "=2:L::U+";
|
opt_complementary = "=2:L::U+";
|
||||||
getopt32(argv, "abdiL:NqrsS:tTU:wu"
|
getopt32(argv, "abdiL:NqrsS:tTU:wupBE",
|
||||||
"p" /* ignored (for compatibility) */,
|
|
||||||
&L_arg, &s_start, &opt_U_context);
|
&L_arg, &s_start, &opt_U_context);
|
||||||
argv += optind;
|
argv += optind;
|
||||||
while (L_arg) {
|
while (L_arg) {
|
||||||
|
@ -852,13 +852,14 @@
|
|||||||
"Relay DHCP requests between clients and server" \
|
"Relay DHCP requests between clients and server" \
|
||||||
|
|
||||||
#define diff_trivial_usage \
|
#define diff_trivial_usage \
|
||||||
"[-abdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
|
"[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
|
||||||
#define diff_full_usage "\n\n" \
|
#define diff_full_usage "\n\n" \
|
||||||
"Compare files line by line and output the differences between them.\n" \
|
"Compare files line by line and output the differences between them.\n" \
|
||||||
"This implementation supports unified diffs only.\n" \
|
"This implementation supports unified diffs only.\n" \
|
||||||
"\nOptions:" \
|
"\nOptions:" \
|
||||||
"\n -a Treat all files as text" \
|
"\n -a Treat all files as text" \
|
||||||
"\n -b Ignore changes in the amount of whitespace" \
|
"\n -b Ignore changes in the amount of whitespace" \
|
||||||
|
"\n -B Ignore changes whose lines are all blank" \
|
||||||
"\n -d Try hard to find a smaller set of changes" \
|
"\n -d Try hard to find a smaller set of changes" \
|
||||||
"\n -i Ignore case differences" \
|
"\n -i Ignore case differences" \
|
||||||
"\n -L Use LABEL instead of the filename in the unified header" \
|
"\n -L Use LABEL instead of the filename in the unified header" \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user