Skip to content

Commit 86ff1d2

Browse files
author
Junio C Hamano
committed
diff-* --patch-with-raw
This new flag outputs the diff-raw output and diff-patch output at the same time. Requested by Cogito. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 944e3a8 commit 86ff1d2

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

combine-diff.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
832832

833833
diffopts = *opt;
834834
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
835+
diffopts.with_raw = 0;
835836
diffopts.recursive = 1;
836837

837838
/* count parents */
@@ -858,6 +859,16 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
858859
num_paths++;
859860
}
860861
if (num_paths) {
862+
if (opt->with_raw) {
863+
int saved_format = opt->output_format;
864+
opt->output_format = DIFF_FORMAT_RAW;
865+
for (p = paths; p; p = p->next) {
866+
if (show_combined_diff(p, num_parent, dense,
867+
header, opt))
868+
header = NULL;
869+
}
870+
opt->output_format = saved_format;
871+
}
861872
for (p = paths; p; p = p->next) {
862873
if (show_combined_diff(p, num_parent, dense,
863874
header, opt))

diff.c

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
862862
const char *arg = av[0];
863863
if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
864864
options->output_format = DIFF_FORMAT_PATCH;
865+
else if (!strcmp(arg, "--patch-with-raw")) {
866+
options->output_format = DIFF_FORMAT_PATCH;
867+
options->with_raw = 1;
868+
}
865869
else if (!strcmp(arg, "-z"))
866870
options->line_termination = 0;
867871
else if (!strncmp(arg, "-l", 2))
@@ -1048,13 +1052,13 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
10481052
static void diff_flush_raw(struct diff_filepair *p,
10491053
int line_termination,
10501054
int inter_name_termination,
1051-
struct diff_options *options)
1055+
struct diff_options *options,
1056+
int output_format)
10521057
{
10531058
int two_paths;
10541059
char status[10];
10551060
int abbrev = options->abbrev;
10561061
const char *path_one, *path_two;
1057-
int output_format = options->output_format;
10581062

10591063
path_one = p->one->path;
10601064
path_two = p->two->path;
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(void)
12701274
diff_debug_queue("resolve-rename-copy done", q);
12711275
}
12721276

1273-
void diff_flush(struct diff_options *options)
1277+
static void flush_one_pair(struct diff_filepair *p,
1278+
int diff_output_format,
1279+
struct diff_options *options)
12741280
{
1275-
struct diff_queue_struct *q = &diff_queued_diff;
1276-
int i;
12771281
int inter_name_termination = '\t';
1278-
int diff_output_format = options->output_format;
12791282
int line_termination = options->line_termination;
1280-
12811283
if (!line_termination)
12821284
inter_name_termination = 0;
12831285

1284-
for (i = 0; i < q->nr; i++) {
1285-
struct diff_filepair *p = q->queue[i];
1286-
1287-
switch (p->status) {
1288-
case DIFF_STATUS_UNKNOWN:
1286+
switch (p->status) {
1287+
case DIFF_STATUS_UNKNOWN:
1288+
break;
1289+
case 0:
1290+
die("internal error in diff-resolve-rename-copy");
1291+
break;
1292+
default:
1293+
switch (diff_output_format) {
1294+
case DIFF_FORMAT_PATCH:
1295+
diff_flush_patch(p, options);
12891296
break;
1290-
case 0:
1291-
die("internal error in diff-resolve-rename-copy");
1297+
case DIFF_FORMAT_RAW:
1298+
case DIFF_FORMAT_NAME_STATUS:
1299+
diff_flush_raw(p, line_termination,
1300+
inter_name_termination,
1301+
options, diff_output_format);
1302+
break;
1303+
case DIFF_FORMAT_NAME:
1304+
diff_flush_name(p,
1305+
inter_name_termination,
1306+
line_termination);
1307+
break;
1308+
case DIFF_FORMAT_NO_OUTPUT:
12921309
break;
1293-
default:
1294-
switch (diff_output_format) {
1295-
case DIFF_FORMAT_PATCH:
1296-
diff_flush_patch(p, options);
1297-
break;
1298-
case DIFF_FORMAT_RAW:
1299-
case DIFF_FORMAT_NAME_STATUS:
1300-
diff_flush_raw(p, line_termination,
1301-
inter_name_termination,
1302-
options);
1303-
break;
1304-
case DIFF_FORMAT_NAME:
1305-
diff_flush_name(p,
1306-
inter_name_termination,
1307-
line_termination);
1308-
break;
1309-
case DIFF_FORMAT_NO_OUTPUT:
1310-
break;
1311-
}
13121310
}
1311+
}
1312+
}
1313+
1314+
void diff_flush(struct diff_options *options)
1315+
{
1316+
struct diff_queue_struct *q = &diff_queued_diff;
1317+
int i;
1318+
int diff_output_format = options->output_format;
1319+
1320+
if (options->with_raw) {
1321+
for (i = 0; i < q->nr; i++) {
1322+
struct diff_filepair *p = q->queue[i];
1323+
flush_one_pair(p, DIFF_FORMAT_RAW, options);
1324+
}
1325+
}
1326+
for (i = 0; i < q->nr; i++) {
1327+
struct diff_filepair *p = q->queue[i];
1328+
flush_one_pair(p, diff_output_format, options);
13131329
diff_free_filepair(p);
13141330
}
13151331
free(q->queue);

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct diff_options {
2424
const char *orderfile;
2525
const char *pickaxe;
2626
unsigned recursive:1,
27+
with_raw:1,
2728
tree_in_recursive:1,
2829
full_index:1;
2930
int break_opt;

0 commit comments

Comments
 (0)