{"thread":{"id":"3847","subject":"[PATCH] diff-* --with-raw","startedAt":"2006-04-11T00:00:40Z","lastAt":"2006-04-11T11:30:46Z","messageCount":6,"participants":["Junio C Hamano","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18551","messageId":"7v7j5x7zh3.fsf@assigned-by-dhcp.cox.net","threadId":"3847","inReplyTo":null,"subject":"[PATCH] diff-* --with-raw","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-11T00:00:40Z","receivedAt":"2006-04-11T00:00:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pasky wanted to have an option to get both diff-raw output and\ndiff-patch output.  This implements \"git-diff-* --with-raw\"\n(which obviously implies -p as well) to do so.\n\nBecause all the necessary information is already on extended\nheader lines such as \"index xxxxxx..yyyyyy\" and \"rename from\"\nlines, this is not strictly necessary, but if it helps\nPorcelains...\n\n--\ndiff --git a/diff.c b/diff.c\nindex 2fa285a..1a9fdab 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *\n \tconst char *arg = av[0];\n \tif (!strcmp(arg, \"-p\") || !strcmp(arg, \"-u\"))\n \t\toptions->output_format = DIFF_FORMAT_PATCH;\n+\telse if (!strcmp(arg, \"--with-raw\")) {\n+\t\toptions->output_format = DIFF_FORMAT_PATCH;\n+\t\toptions->with_raw = 1;\n+\t}\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\n \telse if (!strncmp(arg, \"-l\", 2))\n@@ -1293,6 +1297,10 @@ void diff_flush(struct diff_options *opt\n \t\tdefault:\n \t\t\tswitch (diff_output_format) {\n \t\t\tcase DIFF_FORMAT_PATCH:\n+\t\t\t\tif (options->with_raw)\n+\t\t\t\t\tdiff_flush_raw(p, line_termination,\n+\t\t\t\t\t\t       inter_name_termination,\n+\t\t\t\t\t\t       options);\n \t\t\t\tdiff_flush_patch(p, options);\n \t\t\t\tbreak;\n \t\t\tcase DIFF_FORMAT_RAW:\ndiff --git a/diff.h b/diff.h\nindex a02ef28..07b153b 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -24,6 +24,7 @@ struct diff_options {\n \tconst char *orderfile;\n \tconst char *pickaxe;\n \tunsigned recursive:1,\n+\t\t with_raw:1,\n \t\t tree_in_recursive:1,\n \t\t full_index:1;\n \tint break_opt;\n"},{"id":"18553","messageId":"7v3bgl7z80.fsf@assigned-by-dhcp.cox.net","threadId":"3847","inReplyTo":"7v7j5x7zh3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] diff-* --with-raw","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-11T00:06:07Z","receivedAt":"2006-04-11T00:06:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Pasky wanted to have an option to get both diff-raw output and\n> diff-patch output.  This implements \"git-diff-* --with-raw\"\n> (which obviously implies -p as well) to do so.\n>\n> Because all the necessary information is already on extended\n> header lines such as \"index xxxxxx..yyyyyy\" and \"rename from\"\n> lines, this is not strictly necessary, but if it helps\n> Porcelains...\n\nAnd this alternative gives raw upfront followed by patch.  It\nwas unclear which one Pasky wanted, so...\n\n--\ndiff --git a/diff.c b/diff.c\nindex 2fa285a..12924f2 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *\n \tconst char *arg = av[0];\n \tif (!strcmp(arg, \"-p\") || !strcmp(arg, \"-u\"))\n \t\toptions->output_format = DIFF_FORMAT_PATCH;\n+\telse if (!strcmp(arg, \"--with-raw\")) {\n+\t\toptions->output_format = DIFF_FORMAT_PATCH;\n+\t\toptions->with_raw = 1;\n+\t}\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\n \telse if (!strncmp(arg, \"-l\", 2))\n@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(voi\n \tdiff_debug_queue(\"resolve-rename-copy done\", q);\n }\n \n-void diff_flush(struct diff_options *options)\n+static void flush_one_pair(struct diff_filepair *p,\n+\t\t\t   int diff_output_format,\n+\t\t\t   struct diff_options *options)\n {\n-\tstruct diff_queue_struct *q = &diff_queued_diff;\n-\tint i;\n \tint inter_name_termination = '\\t';\n-\tint diff_output_format = options->output_format;\n \tint line_termination = options->line_termination;\n-\n \tif (!line_termination)\n \t\tinter_name_termination = 0;\n \n-\tfor (i = 0; i < q->nr; i++) {\n-\t\tstruct diff_filepair *p = q->queue[i];\n-\n-\t\tswitch (p->status) {\n-\t\tcase DIFF_STATUS_UNKNOWN:\n+\tswitch (p->status) {\n+\tcase DIFF_STATUS_UNKNOWN:\n+\t\tbreak;\n+\tcase 0:\n+\t\tdie(\"internal error in diff-resolve-rename-copy\");\n+\t\tbreak;\n+\tdefault:\n+\t\tswitch (diff_output_format) {\n+\t\tcase DIFF_FORMAT_PATCH:\n+\t\t\tdiff_flush_patch(p, options);\n \t\t\tbreak;\n-\t\tcase 0:\n-\t\t\tdie(\"internal error in diff-resolve-rename-copy\");\n+\t\tcase DIFF_FORMAT_RAW:\n+\t\tcase DIFF_FORMAT_NAME_STATUS:\n+\t\t\tdiff_flush_raw(p, line_termination,\n+\t\t\t\t       inter_name_termination,\n+\t\t\t\t       options);\n \t\t\tbreak;\n-\t\tdefault:\n-\t\t\tswitch (diff_output_format) {\n-\t\t\tcase DIFF_FORMAT_PATCH:\n-\t\t\t\tdiff_flush_patch(p, options);\n-\t\t\t\tbreak;\n-\t\t\tcase DIFF_FORMAT_RAW:\n-\t\t\tcase DIFF_FORMAT_NAME_STATUS:\n-\t\t\t\tdiff_flush_raw(p, line_termination,\n-\t\t\t\t\t       inter_name_termination,\n-\t\t\t\t\t       options);\n-\t\t\t\tbreak;\n-\t\t\tcase DIFF_FORMAT_NAME:\n-\t\t\t\tdiff_flush_name(p,\n-\t\t\t\t\t\tinter_name_termination,\n-\t\t\t\t\t\tline_termination);\n-\t\t\t\tbreak;\n-\t\t\tcase DIFF_FORMAT_NO_OUTPUT:\n-\t\t\t\tbreak;\n-\t\t\t}\n+\t\tcase DIFF_FORMAT_NAME:\n+\t\t\tdiff_flush_name(p,\n+\t\t\t\t\tinter_name_termination,\n+\t\t\t\t\tline_termination);\n+\t\t\tbreak;\n+\t\tcase DIFF_FORMAT_NO_OUTPUT:\n+\t\t\tbreak;\n \t\t}\n+\t}\n+}\n+\n+void diff_flush(struct diff_options *options)\n+{\n+\tstruct diff_queue_struct *q = &diff_queued_diff;\n+\tint i;\n+\tint diff_output_format = options->output_format;\n+\n+\tif (options->with_raw) {\n+\t\tfor (i = 0; i < q->nr; i++) {\n+\t\t\tstruct diff_filepair *p = q->queue[i];\n+\t\t\tflush_one_pair(p, DIFF_FORMAT_RAW, options);\n+\t\t}\n+\t}\n+\tfor (i = 0; i < q->nr; i++) {\n+\t\tstruct diff_filepair *p = q->queue[i];\n+\t\tflush_one_pair(p, diff_output_format, options);\n \t\tdiff_free_filepair(p);\n \t}\n \tfree(q->queue);\ndiff --git a/diff.h b/diff.h\nindex a02ef28..07b153b 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -24,6 +24,7 @@ struct diff_options {\n \tconst char *orderfile;\n \tconst char *pickaxe;\n \tunsigned recursive:1,\n+\t\t with_raw:1,\n \t\t tree_in_recursive:1,\n \t\t full_index:1;\n \tint break_opt;\n"},{"id":"18555","messageId":"20060411002311.GW27689@pasky.or.cz","threadId":"3847","inReplyTo":"7v3bgl7z80.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] diff-* --with-raw","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-04-11T00:23:11Z","receivedAt":"2006-04-11T00:23:11Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, Apr 11, 2006 at 02:06:07AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> Junio C Hamano <junkio@cox.net> writes:\n> \n> > Pasky wanted to have an option to get both diff-raw output and\n> > diff-patch output.  This implements \"git-diff-* --with-raw\"\n> > (which obviously implies -p as well) to do so.\n> >\n> > Because all the necessary information is already on extended\n> > header lines such as \"index xxxxxx..yyyyyy\" and \"rename from\"\n> > lines, this is not strictly necessary, but if it helps\n> > Porcelains...\n> \n> And this alternative gives raw upfront followed by patch.  It\n> was unclear which one Pasky wanted, so...\n\nTechnically, I don't really care, I can parse both. :-) But I prefer\nthis format since then people can use it even when visually inspecting\nthe diff output, as a kind of quick patch summary followed with the\npatch itself. It might be nice to separate the patch by another newline,\nlike my patch does (but again, I can parse both).\n\nYour patch is nicer, but the --with-raw option name is strange -\ngit-diff-* output is by default the raw format, and with the --with-raw\noption you tell it to furthermore include the raw format... sounds\nwrong, doesn't it? ;-) I'd call it --patch-with-raw or -P.\n\nAlso, it would be nice to handle the -c case as well. Not strictly\nnecessary for cg-log right now, but other cg-Xfollowrenames users might\nwant to have that for merges... (Potentially, this might break renames\ndetection but the case is really obscure.)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nRight now I am having amnesia and deja-vu at the same time.  I think\nI have forgotten this before.\n"},{"id":"18557","messageId":"7vr7456jb4.fsf@assigned-by-dhcp.cox.net","threadId":"3847","inReplyTo":"20060411002311.GW27689@pasky.or.cz","subject":"Re: [PATCH] diff-* --with-raw","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-11T00:35:11Z","receivedAt":"2006-04-11T00:35:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> git-diff-* output is by default the raw format, and with the --with-raw\n> option you tell it to furthermore include the raw format... sounds\n> wrong, doesn't it? ;-) I'd call it --patch-with-raw or -P.\n\nSince --raw-with-raw would be oximoron, I would say --with-raw\nwould naturally mean --patch-with-raw, but that's fine.\n\n> Also, it would be nice to handle the -c case as well. Not strictly\n> necessary for cg-log right now, but other cg-Xfollowrenames users might\n> want to have that for merges... (Potentially, this might break renames\n> detection but the case is really obscure.)\n\nThis would cover that request, comes on top of the previous one.\n\n--\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex eb0d757..748dc30 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -832,6 +832,7 @@ const char *diff_tree_combined_merge(con\n \n \tdiffopts = *opt;\n \tdiffopts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiffopts.with_raw = 0;\n \tdiffopts.recursive = 1;\n \n \t/* count parents */\n@@ -858,6 +859,15 @@ const char *diff_tree_combined_merge(con\n \t\t\tnum_paths++;\n \t}\n \tif (num_paths) {\n+\t\tif (opt->with_raw) {\n+\t\t\topt->output_format = DIFF_FORMAT_RAW;\n+\t\t\tfor (p = paths; p; p = p->next) {\n+\t\t\t\tif (show_combined_diff(p, num_parent, dense,\n+\t\t\t\t\t\t       header, opt))\n+\t\t\t\t\theader = NULL;\n+\t\t\t}\n+\t\t\topt->output_format = DIFF_FORMAT_PATCH;\n+\t\t}\n \t\tfor (p = paths; p; p = p->next) {\n \t\t\tif (show_combined_diff(p, num_parent, dense,\n \t\t\t\t\t       header, opt))\n"},{"id":"18560","messageId":"20060411112217.10363.66165.stgit@machine.or.cz","threadId":"3847","inReplyTo":"7vr7456jb4.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Rename --with-raw to --patch-with-raw and document it","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-04-11T11:22:17Z","receivedAt":"2006-04-11T11:22:17Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Signed-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Documentation/diff-options.txt |    3 +++\n diff.c                         |    2 +-\n diff.h                         |    2 ++\n 3 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex ec6811c..338014c 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -4,6 +4,9 @@\n -u::\n \tSynonym for \"-p\".\n \n+--patch-with-raw::\n+\tGenerate patch but keep also the default raw diff output.\n+\n -z::\n \t\\0 line termination on output\n \ndiff --git a/diff.c b/diff.c\nindex 12924f2..00c79aa 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -862,7 +862,7 @@ int diff_opt_parse(struct diff_options *\n \tconst char *arg = av[0];\n \tif (!strcmp(arg, \"-p\") || !strcmp(arg, \"-u\"))\n \t\toptions->output_format = DIFF_FORMAT_PATCH;\n-\telse if (!strcmp(arg, \"--with-raw\")) {\n+\telse if (!strcmp(arg, \"--patch-with-raw\")) {\n \t\toptions->output_format = DIFF_FORMAT_PATCH;\n \t\toptions->with_raw = 1;\n \t}\ndiff --git a/diff.h b/diff.h\nindex 07b153b..c5372b9 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -113,6 +113,8 @@ #define COMMON_DIFF_OPTIONS_HELP \\\n \"  -z            output diff-raw with lines terminated with NUL.\\n\" \\\n \"  -p            output patch format.\\n\" \\\n \"  -u            synonym for -p.\\n\" \\\n+\"  --patch-with-raw\\n\" \\\n+\"                output both a patch and the diff-raw format.\\n\" \\\n \"  --name-only   show only names of changed files.\\n\" \\\n \"  --name-status show names and status of changed files.\\n\" \\\n \"  --full-index  show full object name on index lines.\\n\" \\\n"},{"id":"18561","messageId":"20060411113045.12117.10948.stgit@machine.or.cz","threadId":"3847","inReplyTo":"7vr7456jb4.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Separate the raw diff and patch with a newline","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-04-11T11:30:46Z","receivedAt":"2006-04-11T11:30:46Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"More friendly for human reading I believe, and possibly friendlier to some\nparsers (although only by an epsilon).\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n combine-diff.c |    1 +\n diff.c         |    1 +\n 2 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 748dc30..0e25788 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -867,6 +867,7 @@ const char *diff_tree_combined_merge(con\n \t\t\t\t\theader = NULL;\n \t\t\t}\n \t\t\topt->output_format = DIFF_FORMAT_PATCH;\n+\t\t\tputchar(opt->line_termination);\n \t\t}\n \t\tfor (p = paths; p; p = p->next) {\n \t\t\tif (show_combined_diff(p, num_parent, dense,\ndiff --git a/diff.c b/diff.c\nindex 00c79aa..86e4251 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1322,6 +1322,7 @@ void diff_flush(struct diff_options *opt\n \t\t\tstruct diff_filepair *p = q->queue[i];\n \t\t\tflush_one_pair(p, DIFF_FORMAT_RAW, options);\n \t\t}\n+\t\tputchar(options->line_termination);\n \t}\n \tfor (i = 0; i < q->nr; i++) {\n \t\tstruct diff_filepair *p = q->queue[i];\n"}]}