diff: exclude D_EMPTY code if there is no support for -r

function                                             old     new   delta
diffreg                                             1808    1825     +17
files_differ                                         189     166     -23
This commit is contained in:
Denis Vlasenko 2008-03-24 16:55:13 +00:00
parent e9d67a81c8
commit c4c2cd44d2

View File

@ -22,9 +22,13 @@
/* /*
* Output flags * Output flags
*/ */
#define D_HEADER 1 /* Print a header/footer between files */ enum {
#define D_EMPTY1 2 /* Treat first file as empty (/dev/null) */ /* Print a header/footer between files */
#define D_EMPTY2 4 /* Treat second file as empty (/dev/null) */ /* D_HEADER = 1, - unused */
/* Treat file as empty (/dev/null) */
D_EMPTY1 = 2 * ENABLE_FEATURE_DIFF_DIR,
D_EMPTY2 = 4 * ENABLE_FEATURE_DIFF_DIR,
};
/* /*
* Status values for print_status() and diffreg() return values * Status values for print_status() and diffreg() return values
@ -308,15 +312,11 @@ static char *make_temp(FILE *f, struct stat *sb)
* Check to see if the given files differ. * Check to see if the given files differ.
* Returns 0 if they are the same, 1 if different, and -1 on error. * Returns 0 if they are the same, 1 if different, and -1 on error.
*/ */
static NOINLINE int files_differ(FILE *f1, FILE *f2, int flags) static NOINLINE int files_differ(FILE *f1, FILE *f2)
{ {
size_t i, j; size_t i, j;
/* Prevent making copies for "/dev/null" (too common) */ /* Prevent making copies for "/dev/null" (too common) */
tempname1 = tempname2 = NULL;
if (flags & (D_EMPTY1 | D_EMPTY2)) {
return 1;
}
/* Deal with input from pipes etc */ /* Deal with input from pipes etc */
tempname1 = make_temp(f1, &stb1); tempname1 = make_temp(f1, &stb1);
tempname2 = make_temp(f2, &stb2); tempname2 = make_temp(f2, &stb2);
@ -1008,6 +1008,7 @@ static unsigned diffreg(char *file1, char *file2, int flags)
anychange = 0; anychange = 0;
context_vec_ptr = context_vec_start - 1; context_vec_ptr = context_vec_start - 1;
tempname1 = tempname2 = NULL;
/* Is any of them a directory? Then it's simple */ /* Is any of them a directory? Then it's simple */
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
@ -1025,13 +1026,18 @@ static unsigned diffreg(char *file1, char *file2, int flags)
else else
f2 = xfopen_stdin(file2); f2 = xfopen_stdin(file2);
/* Quick check whether they are different */ /* NB: if D_EMPTY1/2 is set, other file is always a regular file,
/* NB: copies non-REG files to tempfiles and fills tempname1/2 */ * not pipe/fifo/chardev/etc - D_EMPTY is used by "diff -r" only,
i = files_differ(f1, f2, flags); * and it never diffs non-ordinary files in subdirs. */
if (i != 1) { /* not different? */ if (!(flags & (D_EMPTY1 | D_EMPTY2))) {
if (i != 0) /* error? */ /* Quick check whether they are different */
exit_status |= 2; /* NB: copies non-REG files to tempfiles and fills tempname1/2 */
goto closem; i = files_differ(f1, f2);
if (i != 1) { /* not different? */
if (i != 0) /* error? */
exit_status |= 2;
goto closem;
}
} }
if (!asciifile(f1) || !asciifile(f2)) { if (!asciifile(f1) || !asciifile(f2)) {
@ -1098,7 +1104,7 @@ static unsigned diffreg(char *file1, char *file2, int flags)
#if ENABLE_FEATURE_DIFF_DIR #if ENABLE_FEATURE_DIFF_DIR
static void do_diff(char *dir1, char *path1, char *dir2, char *path2) static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
{ {
int flags = D_HEADER; int flags = 0; /*D_HEADER;*/
int val; int val;
char *fullpath1 = NULL; /* if -N */ char *fullpath1 = NULL; /* if -N */
char *fullpath2 = NULL; char *fullpath2 = NULL;