* [PATCH] diff-* --with-raw @ 2006-04-11 0:00 Junio C Hamano 2006-04-11 0:06 ` Junio C Hamano 0 siblings, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2006-04-11 0:00 UTC (permalink / raw) To: git; +Cc: pasky 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 --git a/diff.c b/diff.c index 2fa285a..1a9fdab 100644 --- a/diff.c +++ b/diff.c @@ -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 *opt default: 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 --git a/diff.h b/diff.h index a02ef28..07b153b 100644 --- a/diff.h +++ b/diff.h @@ -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; ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] diff-* --with-raw 2006-04-11 0:00 [PATCH] diff-* --with-raw Junio C Hamano @ 2006-04-11 0:06 ` Junio C Hamano 2006-04-11 0:23 ` Petr Baudis 0 siblings, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2006-04-11 0:06 UTC (permalink / raw) To: git Junio C Hamano <junkio@cox.net> writes: > 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 --git a/diff.c b/diff.c index 2fa285a..12924f2 100644 --- a/diff.c +++ b/diff.c @@ -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(voi diff_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 --git a/diff.h b/diff.h index a02ef28..07b153b 100644 --- a/diff.h +++ b/diff.h @@ -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; ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] diff-* --with-raw 2006-04-11 0:06 ` Junio C Hamano @ 2006-04-11 0:23 ` Petr Baudis 2006-04-11 0:35 ` Junio C Hamano 0 siblings, 1 reply; 6+ messages in thread From: Petr Baudis @ 2006-04-11 0:23 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Dear diary, on Tue, Apr 11, 2006 at 02:06:07AM CEST, I got a letter where Junio C Hamano <junkio@cox.net> said that... > Junio C Hamano <junkio@cox.net> writes: > > > 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... 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.) -- 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] diff-* --with-raw 2006-04-11 0:23 ` Petr Baudis @ 2006-04-11 0:35 ` Junio C Hamano 2006-04-11 11:22 ` [PATCH] Rename --with-raw to --patch-with-raw and document it Petr Baudis 2006-04-11 11:30 ` [PATCH] Separate the raw diff and patch with a newline Petr Baudis 0 siblings, 2 replies; 6+ messages in thread From: Junio C Hamano @ 2006-04-11 0:35 UTC (permalink / raw) To: Petr Baudis; +Cc: git Petr Baudis <pasky@suse.cz> writes: > 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. > 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. -- diff --git a/combine-diff.c b/combine-diff.c index eb0d757..748dc30 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -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)) ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] Rename --with-raw to --patch-with-raw and document it 2006-04-11 0:35 ` Junio C Hamano @ 2006-04-11 11:22 ` Petr Baudis 2006-04-11 11:30 ` [PATCH] Separate the raw diff and patch with a newline Petr Baudis 1 sibling, 0 replies; 6+ messages in thread From: Petr Baudis @ 2006-04-11 11:22 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Signed-off-by: Petr Baudis <pasky@suse.cz> --- Documentation/diff-options.txt | 3 +++ diff.c | 2 +- diff.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index ec6811c..338014c 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -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 --git a/diff.c b/diff.c index 12924f2..00c79aa 100644 --- a/diff.c +++ b/diff.c @@ -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 --git a/diff.h b/diff.h index 07b153b..c5372b9 100644 --- a/diff.h +++ b/diff.h @@ -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" \ ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] Separate the raw diff and patch with a newline 2006-04-11 0:35 ` Junio C Hamano 2006-04-11 11:22 ` [PATCH] Rename --with-raw to --patch-with-raw and document it Petr Baudis @ 2006-04-11 11:30 ` Petr Baudis 1 sibling, 0 replies; 6+ messages in thread From: Petr Baudis @ 2006-04-11 11:30 UTC (permalink / raw) To: Junio C Hamano; +Cc: git More friendly for human reading I believe, and possibly friendlier to some parsers (although only by an epsilon). Signed-off-by: Petr Baudis <pasky@suse.cz> --- combine-diff.c | 1 + diff.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 748dc30..0e25788 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -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 --git a/diff.c b/diff.c index 00c79aa..86e4251 100644 --- a/diff.c +++ b/diff.c @@ -1322,6 +1322,7 @@ void diff_flush(struct diff_options *opt struct 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]; ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-04-11 11:31 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-04-11 0:00 [PATCH] diff-* --with-raw Junio C Hamano 2006-04-11 0:06 ` Junio C Hamano 2006-04-11 0:23 ` Petr Baudis 2006-04-11 0:35 ` Junio C Hamano 2006-04-11 11:22 ` [PATCH] Rename --with-raw to --patch-with-raw and document it Petr Baudis 2006-04-11 11:30 ` [PATCH] Separate the raw diff and patch with a newline Petr Baudis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).