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>
Junio C Hamano committed
Apr 10, 2006 at 17:36 UTC
86ff1d2012cc5e074d54c0823154019b99ca03f0
3 files changed
+61
-33
combine-diff.c
+11
@@ -832,6 +832,7 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
832
833
diffopts = *opt;
834
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
835
+ diffopts.with_raw = 0;
836
diffopts.recursive = 1;
837
838
/* count parents */
@@ -858,6 +859,16 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
859
num_paths++;
860
}
861
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
+ }
872
for (p = paths; p; p = p->next) {
873
if (show_combined_diff(p, num_parent, dense,
874
header, opt))
diff.c
+49
-33
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
862
const char *arg = av[0];
863
if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
864
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
+ }
869
else if (!strcmp(arg, "-z"))
870
options->line_termination = 0;
871
else if (!strncmp(arg, "-l", 2))
@@ -1048,13 +1052,13 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
1052
static void diff_flush_raw(struct diff_filepair *p,
1053
int line_termination,
1054
int inter_name_termination,
1051
- struct diff_options *options)
1055
+ struct diff_options *options,
1056
+ int output_format)
1057
{
1058
int two_paths;
1059
char status[10];
1060
int abbrev = options->abbrev;
1061
const char *path_one, *path_two;
1057
- int output_format = options->output_format;
1062
1063
path_one = p->one->path;
1064
path_two = p->two->path;
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(void)
1274
diff_debug_queue("resolve-rename-copy done", q);
1275
}
1276
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)
1280
{
1275
- struct diff_queue_struct *q = &diff_queued_diff;
1276
- int i;
1281
int inter_name_termination = '\t';
1278
- int diff_output_format = options->output_format;
1282
int line_termination = options->line_termination;
1280
-
1283
if (!line_termination)
1284
inter_name_termination = 0;
1285
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);
1296
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:
1309
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
- }
1310
}
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);
1329
diff_free_filepair(p);
1330
}
1331
free(q->queue);
diff.h
+1
@@ -24,6 +24,7 @@ struct diff_options {
24
const char *orderfile;
25
const char *pickaxe;
26
unsigned recursive:1,
27
+ with_raw:1,
28
tree_in_recursive:1,
29
full_index:1;
30
int break_opt;