diff-* --with-raw
PATCH 1/1 diff-* --with-raw
Pasky wanted to have an option to get both diff-raw output and diff-patch output. This implements "git-diff-* --with-raw" (which obviously implies -p as well) to do so.
Because all the necessary information is already on extended header lines such as "index xxxxxx..yyyyyy" and "rename from" lines, this is not strictly necessary, but if it helps Porcelains...
--
diff.c +8 -0
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *const char *arg = av[0 ];if (!strcmp (arg,"-p" ) || !strcmp (arg,"-u" )) options->output_format =DIFF_FORMAT_PATCH ; +else if (!strcmp (arg,"--with-raw" )) { + options->output_format =DIFF_FORMAT_PATCH ; + options->with_raw =1 ; + }else if (!strcmp (arg,"-z" )) options->line_termination =0 ;else if (!strncmp (arg,"-l" ,2 ))
@@ -1293,6 +1297,10 @@ void diff_flush(struct diff_options *optdefault :switch (diff_output_format) {case DIFF_FORMAT_PATCH : +if (options->with_raw) +diff_flush_raw (p, line_termination, + inter_name_termination, + options);diff_flush_patch (p, options);break ;case DIFF_FORMAT_RAW :
diff.h +1 -0
@@ -24,6 +24,7 @@ struct diff_options {const char *orderfile;const char *pickaxe; unsigned recursive:1, + with_raw:1, tree_in_recursive:1, full_index:1;int break_opt;
Quoted 8 lines · Junio C Hamano
Pasky wanted to have an option to get both diff-raw output and diff-patch output. This implements "git-diff-* --with-raw" (which obviously implies -p as well) to do so.
Because all the necessary information is already on extended header lines such as "index xxxxxx..yyyyyy" and "rename from" lines, this is not strictly necessary, but if it helps Porcelains...
And this alternative gives raw upfront followed by patch. It was unclear which one Pasky wanted, so...
--
diff.c +47 -31
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *const char *arg = av[0 ];if (!strcmp (arg,"-p" ) || !strcmp (arg,"-u" )) options->output_format =DIFF_FORMAT_PATCH ; +else if (!strcmp (arg,"--with-raw" )) { + options->output_format =DIFF_FORMAT_PATCH ; + options->with_raw =1 ; + }else if (!strcmp (arg,"-z" )) options->line_termination =0 ;else if (!strncmp (arg,"-l" ,2 ))
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(voidiff_debug_queue ("resolve-rename-copy done" , q); } -void diff_flush (struct diff_options *options) +static void flush_one_pair (struct diff_filepair *p, +int diff_output_format, +struct diff_options *options) { -struct diff_queue_struct *q = &diff_queued_diff; -int i;int inter_name_termination ='\t' ; -int diff_output_format = options->output_format;int line_termination = options->line_termination; -if (!line_termination) inter_name_termination =0 ; -for (i =0 ; i < q->nr; i++) { -struct diff_filepair *p = q->queue[i]; - -switch (p->status) { -case DIFF_STATUS_UNKNOWN : +switch (p->status) { +case DIFF_STATUS_UNKNOWN : +break ; +case 0 : +die ("internal error in diff-resolve-rename-copy" ); +break ; +default : +switch (diff_output_format) { +case DIFF_FORMAT_PATCH : +diff_flush_patch (p, options);break ; -case 0 : -die ("internal error in diff-resolve-rename-copy" ); +case DIFF_FORMAT_RAW : +case DIFF_FORMAT_NAME_STATUS : +diff_flush_raw (p, line_termination, + inter_name_termination, + options);break ; -default : -switch (diff_output_format) { -case DIFF_FORMAT_PATCH : -diff_flush_patch (p, options); -break ; -case DIFF_FORMAT_RAW : -case DIFF_FORMAT_NAME_STATUS : -diff_flush_raw (p, line_termination, - inter_name_termination, - options); -break ; -case DIFF_FORMAT_NAME : -diff_flush_name (p, - inter_name_termination, - line_termination); -break ; -case DIFF_FORMAT_NO_OUTPUT : -break ; - } +case DIFF_FORMAT_NAME : +diff_flush_name (p, + inter_name_termination, + line_termination); +break ; +case DIFF_FORMAT_NO_OUTPUT : +break ; } + } +} + +void diff_flush (struct diff_options *options) +{ +struct diff_queue_struct *q = &diff_queued_diff; +int i; +int diff_output_format = options->output_format; + +if (options->with_raw) { +for (i =0 ; i < q->nr; i++) { +struct diff_filepair *p = q->queue[i]; +flush_one_pair (p,DIFF_FORMAT_RAW , options); + } + } +for (i =0 ; i < q->nr; i++) { +struct diff_filepair *p = q->queue[i]; +flush_one_pair (p, diff_output_format, options);diff_free_filepair (p); }free (q->queue);
diff.h +1 -0
@@ -24,6 +24,7 @@ struct diff_options {const char *orderfile;const char *pickaxe; unsigned recursive:1, + with_raw:1, tree_in_recursive:1, full_index:1;int break_opt;
Dear diary, on Tue, Apr 11, 2006 at 02:06:07AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 6 lines
Quoted 4 lines · Junio C Hamano
Pasky wanted to have an option to get both diff-raw output and diff-patch output. This implements "git-diff-* --with-raw" (which obviously implies -p as well) to do so.
Quoted 7 lines
Quoted 4 lines
Because all the necessary information is already on extended header lines such as "index xxxxxx..yyyyyy" and "rename from" lines, this is not strictly necessary, but if it helps Porcelains...
And this alternative gives raw upfront followed by patch. It was unclear which one Pasky wanted, so...
Technically, I don't really care, I can parse both. :-) But I prefer this format since then people can use it even when visually inspecting the diff output, as a kind of quick patch summary followed with the patch itself. It might be nice to separate the patch by another newline, like my patch does (but again, I can parse both).
Your patch is nicer, but the --with-raw option name is strange - git-diff-* output is by default the raw format, and with the --with-raw option you tell it to furthermore include the raw format... sounds wrong, doesn't it? ;-) I'd call it --patch-with-raw or -P.
Also, it would be nice to handle the -c case as well. Not strictly necessary for cg-log right now, but other cg-Xfollowrenames users might want to have that for merges... (Potentially, this might break renames detection but the case is really obscure.)
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Right now I am having amnesia and deja-vu at the same time. I think I have forgotten this before.
Quoted 3 lines · Petr Baudis
git-diff-* output is by default the raw format, and with the --with-raw option you tell it to furthermore include the raw format... sounds wrong, doesn't it? ;-) I'd call it --patch-with-raw or -P.
Since --raw-with-raw would be oximoron, I would say --with-raw would naturally mean --patch-with-raw, but that's fine.
Quoted 4 lines
Also, it would be nice to handle the -c case as well. Not strictly necessary for cg-log right now, but other cg-Xfollowrenames users might want to have that for merges... (Potentially, this might break renames detection but the case is really obscure.)
This would cover that request, comes on top of the previous one.
--
combine-diff.c +10 -0
@@ -832,6 +832,7 @@ const char *diff_tree_combined_merge(con diffopts = *opt; diffopts.output_format =DIFF_FORMAT_NO_OUTPUT ; + diffopts.with_raw =0 ; diffopts.recursive =1 ;/* count parents */
@@ -858,6 +859,15 @@ const char *diff_tree_combined_merge(con num_paths++; }if (num_paths) { +if (opt->with_raw) { + opt->output_format =DIFF_FORMAT_RAW ; +for (p = paths; p; p = p->next) { +if (show_combined_diff (p, num_parent, dense, + header, opt)) + header =NULL ; + } + opt->output_format =DIFF_FORMAT_PATCH ; + }for (p = paths; p; p = p->next) {if (show_combined_diff (p, num_parent, dense, header, opt))
PATCH 1/1 Rename --with-raw to --patch-with-raw and document it
---
Documentation/diff-options.txt | 3 +++ diff.c | 2 +- diff.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletions(-)
Documentation/diff-options.txt +3 -0
@@ -4,6 +4,9 @@ -u:: Synonym for "-p". +--patch-with-raw:: + Generate patch but keep also the default raw diff output. + -z:: \0 line termination on output
diff.c +1 -1
@@ -862,7 +862,7 @@ int diff_opt_parse(struct diff_options *const char *arg = av[0 ];if (!strcmp (arg,"-p" ) || !strcmp (arg,"-u" )) options->output_format =DIFF_FORMAT_PATCH ; -else if (!strcmp (arg,"--with-raw" )) { +else if (!strcmp (arg,"--patch-with-raw" )) { options->output_format =DIFF_FORMAT_PATCH ; options->with_raw =1 ; }
diff.h +2 -0
@@ -113,6 +113,8 @@ #define COMMON_DIFF_OPTIONS_HELP \" -z output diff-raw with lines terminated with NUL.\n" \" -p output patch format.\n" \" -u synonym for -p.\n" \ +" --patch-with-raw\n" \ +" output both a patch and the diff-raw format.\n" \" --name-only show only names of changed files.\n" \" --name-status show names and status of changed files.\n" \" --full-index show full object name on index lines.\n" \
PATCH 1/1 Separate the raw diff and patch with a newline
In reply to Junio C HamanoMore friendly for human reading I believe, and possibly friendlier to some parsers (although only by an epsilon).
---
combine-diff.c | 1 + diff.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
combine-diff.c +1 -0
@@ -867,6 +867,7 @@ const char *diff_tree_combined_merge(con header =NULL ; } opt->output_format =DIFF_FORMAT_PATCH ; +putchar (opt->line_termination); }for (p = paths; p; p = p->next) { if (show_combined_diff(p, num_parent, dense,
diff.c +1 -0
@@ -1322,6 +1322,7 @@ void diff_flush(struct diff_options *optstruct diff_filepair *p = q->queue[i];flush_one_pair (p,DIFF_FORMAT_RAW , options); } +putchar (options->line_termination); }for (i =0 ; i < q->nr; i++) {struct diff_filepair *p = q->queue[i];