Merge with_raw, with_stat and summary variables to output_format
DIFF_FORMAT_* are now bit-flags instead of enumerated values. Signed-off-by: Timo Hirvonen <tihirvon@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Timo Hirvonen committed
Jun 24, 2006 at 20:21 UTC
c6744349df5089133b7662e67aba28282b6a963f
6 files changed
+136
-144
builtin-diff.c
+1
-1
@@ -56,7 +56,7 @@ static int builtin_diff_files(struct rev_info *revs,
56
3 < revs->max_count)
57
usage(builtin_diff_usage);
58
if (revs->max_count < 0 &&
59
- (revs->diffopt.output_format == DIFF_FORMAT_PATCH))
59
+ (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
60
revs->combine_merges = revs->dense_combined_merges = 1;
61
/*
62
* Backward compatibility wart - "diff-files -s" used to
builtin-log.c
+1
-3
@@ -176,11 +176,9 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
176
rev.commit_format = CMIT_FMT_EMAIL;
177
rev.verbose_header = 1;
178
rev.diff = 1;
179
- rev.diffopt.with_raw = 0;
180
- rev.diffopt.with_stat = 1;
179
rev.combine_merges = 0;
180
rev.ignore_merges = 1;
183
- rev.diffopt.output_format = DIFF_FORMAT_PATCH;
181
+ rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
182
183
git_config(git_format_config);
184
rev.extra_headers = extra_headers;
combine-diff.c
+24
-31
@@ -771,7 +771,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
771
if (rev->loginfo)
772
show_log(rev, rev->loginfo, "\n");
773
774
- if (opt->output_format == DIFF_FORMAT_RAW) {
774
+ if (opt->output_format & DIFF_FORMAT_RAW) {
775
offset = strlen(COLONS) - num_parent;
776
if (offset < 0)
777
offset = 0;
@@ -791,8 +791,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
791
printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
792
}
793
794
- if (opt->output_format == DIFF_FORMAT_RAW ||
795
- opt->output_format == DIFF_FORMAT_NAME_STATUS) {
794
+ if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {
795
for (i = 0; i < num_parent; i++)
796
putchar(p->parent[i].status);
797
putchar(inter_name_termination);
@@ -818,17 +817,12 @@ void show_combined_diff(struct combine_diff_path *p,
817
struct diff_options *opt = &rev->diffopt;
818
if (!p->len)
819
return;
821
- switch (opt->output_format) {
822
- case DIFF_FORMAT_RAW:
823
- case DIFF_FORMAT_NAME_STATUS:
824
- case DIFF_FORMAT_NAME:
820
+ if (opt->output_format & (DIFF_FORMAT_RAW |
821
+ DIFF_FORMAT_NAME |
822
+ DIFF_FORMAT_NAME_STATUS)) {
823
show_raw_diff(p, num_parent, rev);
826
- return;
827
- case DIFF_FORMAT_PATCH:
824
+ } else if (opt->output_format & DIFF_FORMAT_PATCH) {
825
show_patch_diff(p, num_parent, dense, rev);
829
- return;
830
- default:
831
- return;
826
}
827
}
828
@@ -842,13 +836,9 @@ void diff_tree_combined(const unsigned char *sha1,
836
struct diff_options diffopts;
837
struct combine_diff_path *p, *paths = NULL;
838
int i, num_paths;
845
- int do_diffstat;
839
847
- do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
848
- opt->with_stat);
840
diffopts = *opt;
850
- diffopts.with_raw = 0;
851
- diffopts.with_stat = 0;
841
+ diffopts.output_format &= ~(DIFF_FORMAT_RAW | DIFF_FORMAT_DIFFSTAT);
842
diffopts.recursive = 1;
843
844
/* find set of paths that everybody touches */
@@ -856,19 +846,18 @@ void diff_tree_combined(const unsigned char *sha1,
846
/* show stat against the first parent even
847
* when doing combined diff.
848
*/
859
- if (i == 0 && do_diffstat)
860
- diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
849
+ if (i == 0 && opt->output_format & DIFF_FORMAT_DIFFSTAT)
850
+ diffopts.output_format |= DIFF_FORMAT_DIFFSTAT;
851
else
862
- diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
852
+ diffopts.output_format |= DIFF_FORMAT_NO_OUTPUT;
853
diff_tree_sha1(parent[i], sha1, "", &diffopts);
854
diffcore_std(&diffopts);
855
paths = intersect_paths(paths, i, num_parent);
856
867
- if (do_diffstat && rev->loginfo)
868
- show_log(rev, rev->loginfo,
869
- opt->with_stat ? "---\n" : "\n");
857
+ if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
858
+ show_log(rev, rev->loginfo, "---\n");
859
diff_flush(&diffopts);
871
- if (opt->with_stat)
860
+ if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
861
putchar('\n');
862
}
863
@@ -878,17 +867,21 @@ void diff_tree_combined(const unsigned char *sha1,
867
num_paths++;
868
}
869
if (num_paths) {
881
- if (opt->with_raw) {
882
- int saved_format = opt->output_format;
883
- opt->output_format = DIFF_FORMAT_RAW;
870
+ if (opt->output_format & (DIFF_FORMAT_RAW |
871
+ DIFF_FORMAT_NAME |
872
+ DIFF_FORMAT_NAME_STATUS)) {
873
for (p = paths; p; p = p->next) {
885
- show_combined_diff(p, num_parent, dense, rev);
874
+ if (p->len)
875
+ show_raw_diff(p, num_parent, rev);
876
}
887
- opt->output_format = saved_format;
877
putchar(opt->line_termination);
878
}
890
- for (p = paths; p; p = p->next) {
891
- show_combined_diff(p, num_parent, dense, rev);
879
+ if (opt->output_format & DIFF_FORMAT_PATCH) {
880
+ for (p = paths; p; p = p->next) {
881
+ if (p->len)
882
+ show_patch_diff(p, num_parent, dense,
883
+ rev);
884
+ }
885
}
886
}
887
diff.c
+88
-95
@@ -1438,23 +1438,27 @@ int diff_setup_done(struct diff_options *options)
1438
(0 <= options->rename_limit && !options->detect_rename))
1439
return -1;
1440
1441
+ if (options->output_format & DIFF_FORMAT_NO_OUTPUT)
1442
+ options->output_format = 0;
1443
+
1444
+ if (options->output_format & (DIFF_FORMAT_NAME |
1445
+ DIFF_FORMAT_NAME_STATUS |
1446
+ DIFF_FORMAT_CHECKDIFF |
1447
+ DIFF_FORMAT_NO_OUTPUT))
1448
+ options->output_format &= ~(DIFF_FORMAT_RAW |
1449
+ DIFF_FORMAT_DIFFSTAT |
1450
+ DIFF_FORMAT_SUMMARY |
1451
+ DIFF_FORMAT_PATCH);
1452
+
1453
/*
1454
* These cases always need recursive; we do not drop caller-supplied
1455
* recursive bits for other formats here.
1456
*/
1445
- if ((options->output_format == DIFF_FORMAT_PATCH) ||
1446
- (options->output_format == DIFF_FORMAT_DIFFSTAT) ||
1447
- (options->output_format == DIFF_FORMAT_CHECKDIFF))
1457
+ if (options->output_format & (DIFF_FORMAT_PATCH |
1458
+ DIFF_FORMAT_DIFFSTAT |
1459
+ DIFF_FORMAT_CHECKDIFF))
1460
options->recursive = 1;
1461
1450
- /*
1451
- * These combinations do not make sense.
1452
- */
1453
- if (options->output_format == DIFF_FORMAT_RAW)
1454
- options->with_raw = 0;
1455
- if (options->output_format == DIFF_FORMAT_DIFFSTAT)
1456
- options->with_stat = 0;
1457
-
1462
if (options->detect_rename && options->rename_limit < 0)
1463
options->rename_limit = diff_rename_limit_default;
1464
if (options->setup & DIFF_SETUP_USE_CACHE) {
@@ -1526,22 +1530,20 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1530
{
1531
const char *arg = av[0];
1532
if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
1529
- options->output_format = DIFF_FORMAT_PATCH;
1533
+ options->output_format |= DIFF_FORMAT_PATCH;
1534
else if (opt_arg(arg, 'U', "unified", &options->context))
1531
- options->output_format = DIFF_FORMAT_PATCH;
1535
+ options->output_format |= DIFF_FORMAT_PATCH;
1536
else if (!strcmp(arg, "--patch-with-raw")) {
1533
- options->output_format = DIFF_FORMAT_PATCH;
1534
- options->with_raw = 1;
1537
+ options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
1538
}
1539
else if (!strcmp(arg, "--stat"))
1537
- options->output_format = DIFF_FORMAT_DIFFSTAT;
1540
+ options->output_format |= DIFF_FORMAT_DIFFSTAT;
1541
else if (!strcmp(arg, "--check"))
1539
- options->output_format = DIFF_FORMAT_CHECKDIFF;
1542
+ options->output_format |= DIFF_FORMAT_CHECKDIFF;
1543
else if (!strcmp(arg, "--summary"))
1541
- options->summary = 1;
1544
+ options->output_format |= DIFF_FORMAT_SUMMARY;
1545
else if (!strcmp(arg, "--patch-with-stat")) {
1543
- options->output_format = DIFF_FORMAT_PATCH;
1544
- options->with_stat = 1;
1546
+ options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT;
1547
}
1548
else if (!strcmp(arg, "-z"))
1549
options->line_termination = 0;
@@ -1550,19 +1552,20 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1552
else if (!strcmp(arg, "--full-index"))
1553
options->full_index = 1;
1554
else if (!strcmp(arg, "--binary")) {
1553
- options->output_format = DIFF_FORMAT_PATCH;
1555
+ options->output_format |= DIFF_FORMAT_PATCH;
1556
options->full_index = options->binary = 1;
1557
}
1558
else if (!strcmp(arg, "--name-only"))
1557
- options->output_format = DIFF_FORMAT_NAME;
1559
+ options->output_format |= DIFF_FORMAT_NAME;
1560
else if (!strcmp(arg, "--name-status"))
1559
- options->output_format = DIFF_FORMAT_NAME_STATUS;
1561
+ options->output_format |= DIFF_FORMAT_NAME_STATUS;
1562
else if (!strcmp(arg, "-R"))
1563
options->reverse_diff = 1;
1564
else if (!strncmp(arg, "-S", 2))
1565
options->pickaxe = arg + 2;
1564
- else if (!strcmp(arg, "-s"))
1565
- options->output_format = DIFF_FORMAT_NO_OUTPUT;
1566
+ else if (!strcmp(arg, "-s")) {
1567
+ options->output_format |= DIFF_FORMAT_NO_OUTPUT;
1568
+ }
1569
else if (!strncmp(arg, "-O", 2))
1570
options->orderfile = arg + 2;
1571
else if (!strncmp(arg, "--diff-filter=", 14))
@@ -1737,15 +1740,17 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
1740
}
1741
1742
static void diff_flush_raw(struct diff_filepair *p,
1740
- int line_termination,
1741
- int inter_name_termination,
1742
- struct diff_options *options,
1743
- int output_format)
1743
+ struct diff_options *options)
1744
{
1745
int two_paths;
1746
char status[10];
1747
int abbrev = options->abbrev;
1748
const char *path_one, *path_two;
1749
+ int inter_name_termination = '\t';
1750
+ int line_termination = options->line_termination;
1751
+
1752
+ if (!line_termination)
1753
+ inter_name_termination = 0;
1754
1755
path_one = p->one->path;
1756
path_two = p->two->path;
@@ -1774,7 +1779,7 @@ static void diff_flush_raw(struct diff_filepair *p,
1779
two_paths = 0;
1780
break;
1781
}
1777
- if (output_format != DIFF_FORMAT_NAME_STATUS) {
1782
+ if (!(options->output_format & DIFF_FORMAT_NAME_STATUS)) {
1783
printf(":%06o %06o %s ",
1784
p->one->mode, p->two->mode,
1785
diff_unique_abbrev(p->one->sha1, abbrev));
@@ -1983,48 +1988,30 @@ static void diff_resolve_rename_copy(void)
1988
diff_debug_queue("resolve-rename-copy done", q);
1989
}
1990
1986
-static void flush_one_pair(struct diff_filepair *p,
1987
- int diff_output_format,
1988
- struct diff_options *options,
1989
- struct diffstat_t *diffstat)
1991
+static int check_pair_status(struct diff_filepair *p)
1992
{
1991
- int inter_name_termination = '\t';
1992
- int line_termination = options->line_termination;
1993
- if (!line_termination)
1994
- inter_name_termination = 0;
1995
-
1993
switch (p->status) {
1994
case DIFF_STATUS_UNKNOWN:
1998
- break;
1995
+ return 0;
1996
case 0:
1997
die("internal error in diff-resolve-rename-copy");
2001
- break;
1998
default:
2003
- switch (diff_output_format) {
2004
- case DIFF_FORMAT_DIFFSTAT:
2005
- diff_flush_stat(p, options, diffstat);
2006
- break;
2007
- case DIFF_FORMAT_CHECKDIFF:
2008
- diff_flush_checkdiff(p, options);
2009
- break;
2010
- case DIFF_FORMAT_PATCH:
2011
- diff_flush_patch(p, options);
2012
- break;
2013
- case DIFF_FORMAT_RAW:
2014
- case DIFF_FORMAT_NAME_STATUS:
2015
- diff_flush_raw(p, line_termination,
2016
- inter_name_termination,
2017
- options, diff_output_format);
2018
- break;
2019
- case DIFF_FORMAT_NAME:
2020
- diff_flush_name(p, line_termination);
2021
- break;
2022
- case DIFF_FORMAT_NO_OUTPUT:
2023
- break;
2024
- }
1999
+ return 1;
2000
}
2001
}
2002
2003
+static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
2004
+{
2005
+ int fmt = opt->output_format;
2006
+
2007
+ if (fmt & DIFF_FORMAT_CHECKDIFF)
2008
+ diff_flush_checkdiff(p, opt);
2009
+ else if (fmt & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS))
2010
+ diff_flush_raw(p, opt);
2011
+ else if (fmt & DIFF_FORMAT_NAME)
2012
+ diff_flush_name(p, opt->line_termination);
2013
+}
2014
+
2015
static void show_file_mode_name(const char *newdelete, struct diff_filespec *fs)
2016
{
2017
if (fs->mode)
@@ -2107,55 +2094,61 @@ static void diff_summary(struct diff_filepair *p)
2094
void diff_flush(struct diff_options *options)
2095
{
2096
struct diff_queue_struct *q = &diff_queued_diff;
2110
- int i;
2111
- int diff_output_format = options->output_format;
2112
- struct diffstat_t *diffstat = NULL;
2097
+ int i, output_format = options->output_format;
2098
2114
- if (diff_output_format == DIFF_FORMAT_DIFFSTAT || options->with_stat) {
2115
- diffstat = xcalloc(sizeof (struct diffstat_t), 1);
2116
- diffstat->xm.consume = diffstat_consume;
2117
- }
2099
+ /*
2100
+ * Order: raw, stat, summary, patch
2101
+ * or: name/name-status/checkdiff (other bits clear)
2102
+ */
2103
2119
- if (options->with_raw) {
2104
+ if (output_format & (DIFF_FORMAT_RAW |
2105
+ DIFF_FORMAT_NAME |
2106
+ DIFF_FORMAT_NAME_STATUS |
2107
+ DIFF_FORMAT_CHECKDIFF)) {
2108
for (i = 0; i < q->nr; i++) {
2109
struct diff_filepair *p = q->queue[i];
2122
- flush_one_pair(p, DIFF_FORMAT_RAW, options, NULL);
2110
+ if (check_pair_status(p))
2111
+ flush_one_pair(p, options);
2112
}
2124
- putchar(options->line_termination);
2113
}
2126
- if (options->with_stat) {
2114
+
2115
+ if (output_format & DIFF_FORMAT_DIFFSTAT) {
2116
+ struct diffstat_t *diffstat;
2117
+
2118
+ diffstat = xcalloc(sizeof (struct diffstat_t), 1);
2119
+ diffstat->xm.consume = diffstat_consume;
2120
for (i = 0; i < q->nr; i++) {
2121
struct diff_filepair *p = q->queue[i];
2129
- flush_one_pair(p, DIFF_FORMAT_DIFFSTAT, options,
2130
- diffstat);
2122
+ if (check_pair_status(p))
2123
+ diff_flush_stat(p, options, diffstat);
2124
}
2125
show_stats(diffstat);
2126
free(diffstat);
2134
- diffstat = NULL;
2135
- if (options->summary)
2136
- for (i = 0; i < q->nr; i++)
2137
- diff_summary(q->queue[i]);
2138
- if (options->stat_sep)
2139
- fputs(options->stat_sep, stdout);
2140
- else
2141
- putchar(options->line_termination);
2142
- }
2143
- for (i = 0; i < q->nr; i++) {
2144
- struct diff_filepair *p = q->queue[i];
2145
- flush_one_pair(p, diff_output_format, options, diffstat);
2127
}
2128
2148
- if (diffstat) {
2149
- show_stats(diffstat);
2150
- free(diffstat);
2129
+ if (output_format & DIFF_FORMAT_SUMMARY) {
2130
+ for (i = 0; i < q->nr; i++)
2131
+ diff_summary(q->queue[i]);
2132
}
2133
2153
- for (i = 0; i < q->nr; i++) {
2154
- if (diffstat && options->summary)
2155
- diff_summary(q->queue[i]);
2156
- diff_free_filepair(q->queue[i]);
2134
+ if (output_format & DIFF_FORMAT_PATCH) {
2135
+ if (output_format & (DIFF_FORMAT_DIFFSTAT |
2136
+ DIFF_FORMAT_SUMMARY)) {
2137
+ if (options->stat_sep)
2138
+ fputs(options->stat_sep, stdout);
2139
+ else
2140
+ putchar(options->line_termination);
2141
+ }
2142
+
2143
+ for (i = 0; i < q->nr; i++) {
2144
+ struct diff_filepair *p = q->queue[i];
2145
+ if (check_pair_status(p))
2146
+ diff_flush_patch(p, options);
2147
+ }
2148
}
2149
2150
+ for (i = 0; i < q->nr; i++)
2151
+ diff_free_filepair(q->queue[i]);
2152
free(q->queue);
2153
q->queue = NULL;
2154
q->nr = q->alloc = 0;
diff.h
+15
-12
@@ -20,19 +20,31 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
20
const unsigned char *sha1,
21
const char *base, const char *path);
22
23
+#define DIFF_FORMAT_RAW 0x0001
24
+#define DIFF_FORMAT_DIFFSTAT 0x0002
25
+#define DIFF_FORMAT_SUMMARY 0x0004
26
+#define DIFF_FORMAT_PATCH 0x0008
27
+
28
+/* These override all above */
29
+#define DIFF_FORMAT_NAME 0x0010
30
+#define DIFF_FORMAT_NAME_STATUS 0x0020
31
+#define DIFF_FORMAT_CHECKDIFF 0x0040
32
+
33
+/* Same as output_format = 0 but we know that -s flag was given
34
+ * and we should not give default value to output_format.
35
+ */
36
+#define DIFF_FORMAT_NO_OUTPUT 0x0080
37
+
38
struct diff_options {
39
const char *filter;
40
const char *orderfile;
41
const char *pickaxe;
42
unsigned recursive:1,
28
- with_raw:1,
29
- with_stat:1,
43
tree_in_recursive:1,
44
binary:1,
45
full_index:1,
46
silent_on_remove:1,
47
find_copies_harder:1,
35
- summary:1,
48
color_diff:1;
49
int context;
50
int break_opt;
@@ -151,15 +163,6 @@ extern void diffcore_std_no_resolve(struct diff_options *);
163
" show all files diff when -S is used and hit is found.\n"
164
165
extern int diff_queue_is_empty(void);
154
-
155
-#define DIFF_FORMAT_RAW 1
156
-#define DIFF_FORMAT_PATCH 2
157
-#define DIFF_FORMAT_NO_OUTPUT 3
158
-#define DIFF_FORMAT_NAME 4
159
-#define DIFF_FORMAT_NAME_STATUS 5
160
-#define DIFF_FORMAT_DIFFSTAT 6
161
-#define DIFF_FORMAT_CHECKDIFF 7
162
-
166
extern void diff_flush(struct diff_options*);
167
168
/* diff-raw status letters */
log-tree.c
+7
-2
@@ -163,8 +163,13 @@ int log_tree_diff_flush(struct rev_info *opt)
163
return 0;
164
}
165
166
- if (opt->loginfo && !opt->no_commit_id)
167
- show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
166
+ if (opt->loginfo && !opt->no_commit_id) {
167
+ if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) {
168
+ show_log(opt, opt->loginfo, "---\n");
169
+ } else {
170
+ show_log(opt, opt->loginfo, "\n");
171
+ }
172
+ }
173
diff_flush(&opt->diffopt);
174
return 1;
175
}