Skip to content

Commit e68b6f1

Browse files
author
Linus Torvalds
committed
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.
1 parent c0fd1f5 commit e68b6f1

File tree

7 files changed

+25
-39
lines changed

7 files changed

+25
-39
lines changed

diff-cache.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include "diff.h"
33

44
static int cached_only = 0;
5-
static int diff_output_format = DIFF_FORMAT_HUMAN;
5+
static int diff_output_format = DIFF_FORMAT_RAW;
6+
static int diff_line_termination = '\n';
67
static int match_nonexisting = 0;
78
static int detect_rename = 0;
89
static int find_copies_harder = 0;
@@ -226,17 +227,13 @@ int main(int argc, const char **argv)
226227
continue;
227228
}
228229
if (!strcmp(arg, "-z")) {
229-
diff_output_format = DIFF_FORMAT_MACHINE;
230+
diff_line_termination = 0;
230231
continue;
231232
}
232233
if (!strcmp(arg, "--name-only")) {
233234
diff_output_format = DIFF_FORMAT_NAME;
234235
continue;
235236
}
236-
if (!strcmp(arg, "--name-only-z")) {
237-
diff_output_format = DIFF_FORMAT_NAME_Z;
238-
continue;
239-
}
240237
if (!strcmp(arg, "-R")) {
241238
diff_setup_opt |= DIFF_SETUP_REVERSE;
242239
continue;
@@ -292,6 +289,6 @@ int main(int argc, const char **argv)
292289
pickaxe, pickaxe_opts,
293290
diff_break_opt,
294291
orderfile, diff_filter);
295-
diff_flush(diff_output_format);
292+
diff_flush(diff_output_format, diff_line_termination);
296293
return ret;
297294
}

diff-files.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ static const char *diff_files_usage =
1111
"[<common diff options>] [<path>...]"
1212
COMMON_DIFF_OPTIONS_HELP;
1313

14-
static int diff_output_format = DIFF_FORMAT_HUMAN;
14+
static int diff_output_format = DIFF_FORMAT_RAW;
15+
static int diff_line_termination = '\n';
1516
static int detect_rename = 0;
1617
static int find_copies_harder = 0;
1718
static int diff_setup_opt = 0;
@@ -57,11 +58,9 @@ int main(int argc, const char **argv)
5758
else if (!strcmp(argv[1], "-s"))
5859
; /* no-op */
5960
else if (!strcmp(argv[1], "-z"))
60-
diff_output_format = DIFF_FORMAT_MACHINE;
61+
diff_line_termination = 0;
6162
else if (!strcmp(argv[1], "--name-only"))
6263
diff_output_format = DIFF_FORMAT_NAME;
63-
else if (!strcmp(argv[1], "--name-only-z"))
64-
diff_output_format = DIFF_FORMAT_NAME_Z;
6564
else if (!strcmp(argv[1], "-R"))
6665
diff_setup_opt |= DIFF_SETUP_REVERSE;
6766
else if (!strncmp(argv[1], "-S", 2))
@@ -153,6 +152,6 @@ int main(int argc, const char **argv)
153152
pickaxe, pickaxe_opts,
154153
diff_break_opt,
155154
orderfile, diff_filter);
156-
diff_flush(diff_output_format);
155+
diff_flush(diff_output_format, diff_line_termination);
157156
return 0;
158157
}

diff-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void flush_them(int ac, const char **av)
1717
diffcore_std_no_resolve(av + 1,
1818
pickaxe, pickaxe_opts,
1919
orderfile, diff_filter);
20-
diff_flush(DIFF_FORMAT_PATCH);
20+
diff_flush(DIFF_FORMAT_PATCH, '\n');
2121
}
2222

2323
static const char *diff_helper_usage =

diff-stages.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "cache.h"
66
#include "diff.h"
77

8-
static int diff_output_format = DIFF_FORMAT_HUMAN;
8+
static int diff_output_format = DIFF_FORMAT_RAW;
9+
static int diff_line_termination = '\n';
910
static int detect_rename = 0;
1011
static int find_copies_harder = 0;
1112
static int diff_setup_opt = 0;
@@ -87,11 +88,9 @@ int main(int ac, const char **av)
8788
else if (!strcmp(arg, "--find-copies-harder"))
8889
find_copies_harder = 1;
8990
else if (!strcmp(arg, "-z"))
90-
diff_output_format = DIFF_FORMAT_MACHINE;
91+
diff_line_termination = 0;
9192
else if (!strcmp(arg, "--name-only"))
9293
diff_output_format = DIFF_FORMAT_NAME;
93-
else if (!strcmp(arg, "--name-only-z"))
94-
diff_output_format = DIFF_FORMAT_NAME_Z;
9594
else if (!strcmp(arg, "-R"))
9695
diff_setup_opt |= DIFF_SETUP_REVERSE;
9796
else if (!strncmp(arg, "-S", 2))
@@ -126,6 +125,6 @@ int main(int ac, const char **av)
126125
diff_break_opt,
127126
orderfile,
128127
diff_filter);
129-
diff_flush(diff_output_format);
128+
diff_flush(diff_output_format, diff_line_termination);
130129
return 0;
131130
}

diff-tree.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ static int ignore_merges = 1;
99
static int recursive = 0;
1010
static int show_tree_entry_in_recursive = 0;
1111
static int read_stdin = 0;
12-
static int diff_output_format = DIFF_FORMAT_HUMAN;
12+
static int diff_output_format = DIFF_FORMAT_RAW;
13+
static int diff_line_termination = '\n';
1314
static int detect_rename = 0;
1415
static int find_copies_harder = 0;
1516
static int diff_setup_opt = 0;
@@ -276,14 +277,14 @@ static int call_diff_flush(void)
276277
orderfile,
277278
diff_filter);
278279
if (diff_queue_is_empty()) {
279-
diff_flush(DIFF_FORMAT_NO_OUTPUT);
280+
diff_flush(DIFF_FORMAT_NO_OUTPUT, diff_line_termination);
280281
return 0;
281282
}
282283
if (header) {
283-
printf("%s%c", header, diff_output_format == DIFF_FORMAT_MACHINE ? 0 : '\n');
284+
printf("%s%c", header, diff_line_termination);
284285
header = NULL;
285286
}
286-
diff_flush(diff_output_format);
287+
diff_flush(diff_output_format, diff_line_termination);
287288
return 1;
288289
}
289290

@@ -486,12 +487,8 @@ int main(int argc, const char **argv)
486487
diff_output_format = DIFF_FORMAT_NAME;
487488
continue;
488489
}
489-
if (!strcmp(arg, "--name-only-z")) {
490-
diff_output_format = DIFF_FORMAT_NAME_Z;
491-
continue;
492-
}
493490
if (!strcmp(arg, "-z")) {
494-
diff_output_format = DIFF_FORMAT_MACHINE;
491+
diff_line_termination = 0;
495492
continue;
496493
}
497494
if (!strcmp(arg, "-m")) {

diff.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -977,16 +977,14 @@ static void diff_resolve_rename_copy(void)
977977
diff_debug_queue("resolve-rename-copy done", q);
978978
}
979979

980-
void diff_flush(int diff_output_style)
980+
void diff_flush(int diff_output_style, int line_termination)
981981
{
982982
struct diff_queue_struct *q = &diff_queued_diff;
983983
int i;
984-
int line_termination = '\n';
985984
int inter_name_termination = '\t';
986985

987-
if (diff_output_style == DIFF_FORMAT_MACHINE ||
988-
diff_output_style == DIFF_FORMAT_NAME_Z)
989-
line_termination = inter_name_termination = 0;
986+
if (!line_termination)
987+
inter_name_termination = 0;
990988

991989
for (i = 0; i < q->nr; i++) {
992990
struct diff_filepair *p = q->queue[i];
@@ -999,13 +997,11 @@ void diff_flush(int diff_output_style)
999997
case DIFF_FORMAT_PATCH:
1000998
diff_flush_patch(p);
1001999
break;
1002-
case DIFF_FORMAT_HUMAN:
1003-
case DIFF_FORMAT_MACHINE:
1000+
case DIFF_FORMAT_RAW:
10041001
diff_flush_raw(p, line_termination,
10051002
inter_name_termination);
10061003
break;
10071004
case DIFF_FORMAT_NAME:
1008-
case DIFF_FORMAT_NAME_Z:
10091005
diff_flush_name(p, line_termination);
10101006
break;
10111007
}

diff.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ extern void diffcore_std_no_resolve(const char **paths,
7575

7676
extern int diff_queue_is_empty(void);
7777

78-
#define DIFF_FORMAT_HUMAN 0
79-
#define DIFF_FORMAT_MACHINE 1
78+
#define DIFF_FORMAT_RAW 1
8079
#define DIFF_FORMAT_PATCH 2
8180
#define DIFF_FORMAT_NO_OUTPUT 3
8281
#define DIFF_FORMAT_NAME 4
83-
#define DIFF_FORMAT_NAME_Z 5
8482

85-
extern void diff_flush(int output_style);
83+
extern void diff_flush(int output_style, int line_terminator);
8684

8785
#endif /* DIFF_H */

0 commit comments

Comments
 (0)