Split up "diff_format" into "format" and "line_termination".

This removes the separate "formats" for name and name-with-zero-
termination.

It also removes the difference between HUMAN and MACHINE formats, and
they both become DIFF_FORMAT_RAW, with the difference being just in the
line and inter-filename termination.

It also makes the code easier to understand.
This commit is contained in:
Linus Torvalds 2005-07-14 17:59:17 -07:00
parent c0fd1f517e
commit e68b6f1525
7 changed files with 25 additions and 39 deletions

View File

@ -2,7 +2,8 @@
#include "diff.h" #include "diff.h"
static int cached_only = 0; static int cached_only = 0;
static int diff_output_format = DIFF_FORMAT_HUMAN; static int diff_output_format = DIFF_FORMAT_RAW;
static int diff_line_termination = '\n';
static int match_nonexisting = 0; static int match_nonexisting = 0;
static int detect_rename = 0; static int detect_rename = 0;
static int find_copies_harder = 0; static int find_copies_harder = 0;
@ -226,17 +227,13 @@ int main(int argc, const char **argv)
continue; continue;
} }
if (!strcmp(arg, "-z")) { if (!strcmp(arg, "-z")) {
diff_output_format = DIFF_FORMAT_MACHINE; diff_line_termination = 0;
continue; continue;
} }
if (!strcmp(arg, "--name-only")) { if (!strcmp(arg, "--name-only")) {
diff_output_format = DIFF_FORMAT_NAME; diff_output_format = DIFF_FORMAT_NAME;
continue; continue;
} }
if (!strcmp(arg, "--name-only-z")) {
diff_output_format = DIFF_FORMAT_NAME_Z;
continue;
}
if (!strcmp(arg, "-R")) { if (!strcmp(arg, "-R")) {
diff_setup_opt |= DIFF_SETUP_REVERSE; diff_setup_opt |= DIFF_SETUP_REVERSE;
continue; continue;
@ -292,6 +289,6 @@ int main(int argc, const char **argv)
pickaxe, pickaxe_opts, pickaxe, pickaxe_opts,
diff_break_opt, diff_break_opt,
orderfile, diff_filter); orderfile, diff_filter);
diff_flush(diff_output_format); diff_flush(diff_output_format, diff_line_termination);
return ret; return ret;
} }

View File

@ -11,7 +11,8 @@ static const char *diff_files_usage =
"[<common diff options>] [<path>...]" "[<common diff options>] [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;
static int diff_output_format = DIFF_FORMAT_HUMAN; static int diff_output_format = DIFF_FORMAT_RAW;
static int diff_line_termination = '\n';
static int detect_rename = 0; static int detect_rename = 0;
static int find_copies_harder = 0; static int find_copies_harder = 0;
static int diff_setup_opt = 0; static int diff_setup_opt = 0;
@ -57,11 +58,9 @@ int main(int argc, const char **argv)
else if (!strcmp(argv[1], "-s")) else if (!strcmp(argv[1], "-s"))
; /* no-op */ ; /* no-op */
else if (!strcmp(argv[1], "-z")) else if (!strcmp(argv[1], "-z"))
diff_output_format = DIFF_FORMAT_MACHINE; diff_line_termination = 0;
else if (!strcmp(argv[1], "--name-only")) else if (!strcmp(argv[1], "--name-only"))
diff_output_format = DIFF_FORMAT_NAME; diff_output_format = DIFF_FORMAT_NAME;
else if (!strcmp(argv[1], "--name-only-z"))
diff_output_format = DIFF_FORMAT_NAME_Z;
else if (!strcmp(argv[1], "-R")) else if (!strcmp(argv[1], "-R"))
diff_setup_opt |= DIFF_SETUP_REVERSE; diff_setup_opt |= DIFF_SETUP_REVERSE;
else if (!strncmp(argv[1], "-S", 2)) else if (!strncmp(argv[1], "-S", 2))
@ -153,6 +152,6 @@ int main(int argc, const char **argv)
pickaxe, pickaxe_opts, pickaxe, pickaxe_opts,
diff_break_opt, diff_break_opt,
orderfile, diff_filter); orderfile, diff_filter);
diff_flush(diff_output_format); diff_flush(diff_output_format, diff_line_termination);
return 0; return 0;
} }

View File

@ -17,7 +17,7 @@ static void flush_them(int ac, const char **av)
diffcore_std_no_resolve(av + 1, diffcore_std_no_resolve(av + 1,
pickaxe, pickaxe_opts, pickaxe, pickaxe_opts,
orderfile, diff_filter); orderfile, diff_filter);
diff_flush(DIFF_FORMAT_PATCH); diff_flush(DIFF_FORMAT_PATCH, '\n');
} }
static const char *diff_helper_usage = static const char *diff_helper_usage =

View File

@ -5,7 +5,8 @@
#include "cache.h" #include "cache.h"
#include "diff.h" #include "diff.h"
static int diff_output_format = DIFF_FORMAT_HUMAN; static int diff_output_format = DIFF_FORMAT_RAW;
static int diff_line_termination = '\n';
static int detect_rename = 0; static int detect_rename = 0;
static int find_copies_harder = 0; static int find_copies_harder = 0;
static int diff_setup_opt = 0; static int diff_setup_opt = 0;
@ -87,11 +88,9 @@ int main(int ac, const char **av)
else if (!strcmp(arg, "--find-copies-harder")) else if (!strcmp(arg, "--find-copies-harder"))
find_copies_harder = 1; find_copies_harder = 1;
else if (!strcmp(arg, "-z")) else if (!strcmp(arg, "-z"))
diff_output_format = DIFF_FORMAT_MACHINE; diff_line_termination = 0;
else if (!strcmp(arg, "--name-only")) else if (!strcmp(arg, "--name-only"))
diff_output_format = DIFF_FORMAT_NAME; diff_output_format = DIFF_FORMAT_NAME;
else if (!strcmp(arg, "--name-only-z"))
diff_output_format = DIFF_FORMAT_NAME_Z;
else if (!strcmp(arg, "-R")) else if (!strcmp(arg, "-R"))
diff_setup_opt |= DIFF_SETUP_REVERSE; diff_setup_opt |= DIFF_SETUP_REVERSE;
else if (!strncmp(arg, "-S", 2)) else if (!strncmp(arg, "-S", 2))
@ -126,6 +125,6 @@ int main(int ac, const char **av)
diff_break_opt, diff_break_opt,
orderfile, orderfile,
diff_filter); diff_filter);
diff_flush(diff_output_format); diff_flush(diff_output_format, diff_line_termination);
return 0; return 0;
} }

View File

@ -9,7 +9,8 @@ static int ignore_merges = 1;
static int recursive = 0; static int recursive = 0;
static int show_tree_entry_in_recursive = 0; static int show_tree_entry_in_recursive = 0;
static int read_stdin = 0; static int read_stdin = 0;
static int diff_output_format = DIFF_FORMAT_HUMAN; static int diff_output_format = DIFF_FORMAT_RAW;
static int diff_line_termination = '\n';
static int detect_rename = 0; static int detect_rename = 0;
static int find_copies_harder = 0; static int find_copies_harder = 0;
static int diff_setup_opt = 0; static int diff_setup_opt = 0;
@ -276,14 +277,14 @@ static int call_diff_flush(void)
orderfile, orderfile,
diff_filter); diff_filter);
if (diff_queue_is_empty()) { if (diff_queue_is_empty()) {
diff_flush(DIFF_FORMAT_NO_OUTPUT); diff_flush(DIFF_FORMAT_NO_OUTPUT, diff_line_termination);
return 0; return 0;
} }
if (header) { if (header) {
printf("%s%c", header, diff_output_format == DIFF_FORMAT_MACHINE ? 0 : '\n'); printf("%s%c", header, diff_line_termination);
header = NULL; header = NULL;
} }
diff_flush(diff_output_format); diff_flush(diff_output_format, diff_line_termination);
return 1; return 1;
} }
@ -486,12 +487,8 @@ int main(int argc, const char **argv)
diff_output_format = DIFF_FORMAT_NAME; diff_output_format = DIFF_FORMAT_NAME;
continue; continue;
} }
if (!strcmp(arg, "--name-only-z")) {
diff_output_format = DIFF_FORMAT_NAME_Z;
continue;
}
if (!strcmp(arg, "-z")) { if (!strcmp(arg, "-z")) {
diff_output_format = DIFF_FORMAT_MACHINE; diff_line_termination = 0;
continue; continue;
} }
if (!strcmp(arg, "-m")) { if (!strcmp(arg, "-m")) {

12
diff.c
View File

@ -977,16 +977,14 @@ static void diff_resolve_rename_copy(void)
diff_debug_queue("resolve-rename-copy done", q); diff_debug_queue("resolve-rename-copy done", q);
} }
void diff_flush(int diff_output_style) void diff_flush(int diff_output_style, int line_termination)
{ {
struct diff_queue_struct *q = &diff_queued_diff; struct diff_queue_struct *q = &diff_queued_diff;
int i; int i;
int line_termination = '\n';
int inter_name_termination = '\t'; int inter_name_termination = '\t';
if (diff_output_style == DIFF_FORMAT_MACHINE || if (!line_termination)
diff_output_style == DIFF_FORMAT_NAME_Z) inter_name_termination = 0;
line_termination = inter_name_termination = 0;
for (i = 0; i < q->nr; i++) { for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i]; struct diff_filepair *p = q->queue[i];
@ -999,13 +997,11 @@ void diff_flush(int diff_output_style)
case DIFF_FORMAT_PATCH: case DIFF_FORMAT_PATCH:
diff_flush_patch(p); diff_flush_patch(p);
break; break;
case DIFF_FORMAT_HUMAN: case DIFF_FORMAT_RAW:
case DIFF_FORMAT_MACHINE:
diff_flush_raw(p, line_termination, diff_flush_raw(p, line_termination,
inter_name_termination); inter_name_termination);
break; break;
case DIFF_FORMAT_NAME: case DIFF_FORMAT_NAME:
case DIFF_FORMAT_NAME_Z:
diff_flush_name(p, line_termination); diff_flush_name(p, line_termination);
break; break;
} }

6
diff.h
View File

@ -75,13 +75,11 @@ extern void diffcore_std_no_resolve(const char **paths,
extern int diff_queue_is_empty(void); extern int diff_queue_is_empty(void);
#define DIFF_FORMAT_HUMAN 0 #define DIFF_FORMAT_RAW 1
#define DIFF_FORMAT_MACHINE 1
#define DIFF_FORMAT_PATCH 2 #define DIFF_FORMAT_PATCH 2
#define DIFF_FORMAT_NO_OUTPUT 3 #define DIFF_FORMAT_NO_OUTPUT 3
#define DIFF_FORMAT_NAME 4 #define DIFF_FORMAT_NAME 4
#define DIFF_FORMAT_NAME_Z 5
extern void diff_flush(int output_style); extern void diff_flush(int output_style, int line_terminator);
#endif /* DIFF_H */ #endif /* DIFF_H */