{"thread":{"id":"3877","subject":"[PATCH] diff-options: add --patch-with-stat","startedAt":"2006-04-15T11:41:18Z","lastAt":"2006-04-15T13:01:43Z","messageCount":6,"participants":["Johannes Schindelin","Marco Costalba","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18687","messageId":"Pine.LNX.4.63.0604151340210.24303@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"3877","inReplyTo":null,"subject":"[PATCH] diff-options: add --patch-with-stat","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-04-15T11:41:18Z","receivedAt":"2006-04-15T11:41:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWith this option, git prepends a diffstat in front of the patch.\n\nSince I really, really do not know what a diffstat of a combined diff\n(\"merge diff\") should look like, the diffstat is not generated for these.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tBuggeth, and you shall be given.\n\n\tBTW I really would like to have a diffstat for combined diffs.\n\tAny ideas?\n\n Documentation/diff-options.txt |    3 +++\n diff.c                         |   17 ++++++++++++++++-\n diff.h                         |    3 +++\n 3 files changed, 22 insertions(+), 1 deletions(-)\n\nc06cf94fe5a2f0b004e7b46c0322554e7ec4ff99\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 447e522..c183dc9 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -10,6 +10,9 @@\n --stat::\n \tGenerate a diffstat instead of a patch.\n \n+--patch-with-stat::\n+\tGenerate patch and prepend its diffstat.\n+\n -z::\n \t\\0 line termination on output\n \ndiff --git a/diff.c b/diff.c\nindex f1b672d..1b33465 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1049,6 +1049,10 @@ int diff_opt_parse(struct diff_options *\n \t}\n \telse if (!strcmp(arg, \"--stat\"))\n \t\toptions->output_format = DIFF_FORMAT_DIFFSTAT;\n+\telse if (!strcmp(arg, \"--patch-with-stat\")) {\n+\t\toptions->output_format = DIFF_FORMAT_PATCH;\n+\t\toptions->with_stat = 1;\n+\t}\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\n \telse if (!strncmp(arg, \"-l\", 2))\n@@ -1518,7 +1522,7 @@ void diff_flush(struct diff_options *opt\n \tint diff_output_format = options->output_format;\n \tstruct diffstat_t *diffstat = NULL;\n \n-\tif (diff_output_format == DIFF_FORMAT_DIFFSTAT) {\n+\tif (diff_output_format == DIFF_FORMAT_DIFFSTAT || options->with_stat) {\n \t\tdiffstat = xcalloc(sizeof (struct diffstat_t), 1);\n \t\tdiffstat->xm.consume = diffstat_consume;\n \t}\n@@ -1530,6 +1534,17 @@ void diff_flush(struct diff_options *opt\n \t\t}\n \t\tputchar(options->line_termination);\n \t}\n+\tif (options->with_stat) {\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_DIFFSTAT, options,\n+\t\t\t\t\tdiffstat);\n+\t\t}\n+\t\tshow_stats(diffstat);\n+\t\tfree(diffstat);\n+\t\tdiffstat = NULL;\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 \t\tflush_one_pair(p, diff_output_format, options, diffstat);\ndiff --git a/diff.h b/diff.h\nindex 2f8aff2..f783bae 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -25,6 +25,7 @@ struct diff_options {\n \tconst char *pickaxe;\n \tunsigned recursive:1,\n \t\t with_raw:1,\n+\t\t with_stat:1,\n \t\t tree_in_recursive:1,\n \t\t full_index:1;\n \tint break_opt;\n@@ -120,6 +121,8 @@ #define COMMON_DIFF_OPTIONS_HELP \\\n \"  --patch-with-raw\\n\" \\\n \"                output both a patch and the diff-raw format.\\n\" \\\n \"  --stat        show diffstat instead of patch.\\n\" \\\n+\"  --patch-with-stat\\n\" \\\n+\"                output a patch and prepend its diffstat.\\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-- \n1.3.0.rc4.ga1167e-dirty\n"},{"id":"18690","messageId":"e5bfff550604150450u37ce1660u2db4f6e97c586e13@mail.gmail.com","threadId":"3877","inReplyTo":"Pine.LNX.4.63.0604151340210.24303@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] diff-options: add --patch-with-stat","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2006-04-15T11:50:21Z","receivedAt":"2006-04-15T11:50:21Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> With this option, git prepends a diffstat in front of the patch.\n>\n\nThanks!  qgit will set this as default!\n\n>\n>         Buggeth, and you shall be given.\n>\n>         BTW I really would like to have a diffstat for combined diffs.\n>         Any ideas?\n>\n\nWell..hem..why do not  count  the (shifted) + and - in the combined diffs ouput?\n\nI suspect this can be a total idiocy, but now I'm missing why.  :-)\n\nMarco\n"},{"id":"18692","messageId":"Pine.LNX.4.63.0604151353580.25324@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"3877","inReplyTo":"e5bfff550604150450u37ce1660u2db4f6e97c586e13@mail.gmail.com","subject":"Re: [PATCH] diff-options: add --patch-with-stat","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-04-15T11:56:23Z","receivedAt":"2006-04-15T11:56:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 15 Apr 2006, Marco Costalba wrote:\n\n> On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> >         BTW I really would like to have a diffstat for combined diffs.\n> >         Any ideas?\n> \n> Well..hem..why do not count the (shifted) + and - in the combined diffs \n> ouput?\n\nThis does not help. The combined diff is so useful, because it contains \nthe information as to which parent has this difference, and which parent \nhas not.\n\nBy just counting the plusses and minusses, this information is filtered \nout.\n\nCiao,\nDscho\n"},{"id":"18696","messageId":"7v64lbggrd.fsf@assigned-by-dhcp.cox.net","threadId":"3877","inReplyTo":"Pine.LNX.4.63.0604151340210.24303@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] diff-options: add --patch-with-stat","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-15T12:33:42Z","receivedAt":"2006-04-15T12:33:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tBTW I really would like to have a diffstat for combined diffs.\n> \tAny ideas?\n\nWhile I think combined diffs are somewhat overrated, I think\nwhat makes some sense would be to count --cc output for each\nparent's column, and show something like this:\n\n Makefile            | +-     +- \n debian/changelog    | ++++++ ++++++++++++++++++++\n 2 files changed, 7 and 91 insertions(+), 1 and 0 deletions(-)\n\nThis is for \"diff-tree --cc v1.0.0\"; the hand-merge (or evil\nmerge) changed from first parent 7(+),1(-) and from second\nparent 91(+),0(-) respectively.\n\nCount the maximum change per each parent (the above example the\nsecond file has the max for both parents but that may not always\nbe the case), add them up to determine how many columns to\nallocate for each parent (while taking one column gap between\neach parent into account) and draw normally.\n\nThe code that counted this (I did not write code to draw it) is\nlike this:\n\n-- >8 --\n#!/usr/bin/perl\n\nuse strict;\nmy $filename;\nmy $num_parents = -1;\nmy %stat;\n\nwhile (<>) {\n\tchomp;\n\tif (/^diff --cc (.*)$/) {\n\t\t$filename = $1;\n\t\t$stat{$filename} = undef;\n\t\tnext;\n\t}\n\tif (/^(\\@+) [-+0-9, ]* \\1$/) {\n\t\t$num_parents = length($1) - 1;\n\t\tnext;\n\t}\n\tnext unless (/^([- +]{$num_parents})/);\n\tmy @pfx = split('', $1);\n\tif (!defined $stat{$filename}) {\n\t\t$stat{$filename} = [];\n\t\tfor (my $i = 0; $i < $num_parents; $i++) {\n\t\t\tpush @{$stat{$filename}}, [0, 0];\n\t\t}\n\t}\n\tfor (my $i = 0; $i < $num_parents; $i++) {\n\t\tif ($pfx[$i] eq '+') {\n\t\t\t$stat{$filename}[$i][0]++;\n\t\t}\n\t\tif ($pfx[$i] eq '-') {\n\t\t\t$stat{$filename}[$i][1]++;\n\t\t}\n\t}\n}\n\nfor my $filename (sort keys %stat) {\n\tprint \"$filename\t\";\n\tfor (my $i = 0; $i < $num_parents; $i++) {\n\t\tprintf \" +%d/-%d\",\n\t\t$stat{$filename}[$i][0], $stat{$filename}[$i][1];\n\t}\n\tprint \"\\n\";\n}\n"},{"id":"18697","messageId":"Pine.LNX.4.63.0604151436280.6147@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"3877","inReplyTo":"7v64lbggrd.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] diff-options: add --patch-with-stat","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-04-15T12:37:22Z","receivedAt":"2006-04-15T12:37:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 15 Apr 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > \tBTW I really would like to have a diffstat for combined diffs.\n> > \tAny ideas?\n> \n> While I think combined diffs are somewhat overrated, I think\n> what makes some sense would be to count --cc output for each\n> parent's column, and show something like this:\n> \n>  Makefile            | +-     +- \n>  debian/changelog    | ++++++ ++++++++++++++++++++\n>  2 files changed, 7 and 91 insertions(+), 1 and 0 deletions(-)\n\nOkay. That is a start, altough it will look funny with 12 parents...\n\nI'll do some hacking while you're sleeping.\n\nCiao,\nDscho\n"},{"id":"18698","messageId":"e5bfff550604150601n335205actb0e1955884e76582@mail.gmail.com","threadId":"3877","inReplyTo":"Pine.LNX.4.63.0604151436280.6147@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] diff-options: add --patch-with-stat","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2006-04-15T13:01:43Z","receivedAt":"2006-04-15T13:01:43Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Sat, 15 Apr 2006, Junio C Hamano wrote:\n>\n> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> >\n> > >     BTW I really would like to have a diffstat for combined diffs.\n> > >     Any ideas?\n> >\n Just another idea, from current git:\n\n$ git-diff-tree -r -m --stat 4da8cbc23\n4da8cbc234177d6a8cf749d4ef60bd05ec843898\n---\n blame.c     |   20 ++++++++++++++------\n diff-tree.c |    2 +-\n diff.h      |    6 +++++-\n git.c       |   15 +++++++++++++--\n http-push.c |    1 +\n rev-list.c  |    1 +\n revision.c  |   26 ++++++++++++--------------\n revision.h  |    7 +++++--\n tree-diff.c |   46 +++++++++++++++++++++++++---------------------\n 9 files changed, 77 insertions(+), 47 deletions(-)\n4da8cbc234177d6a8cf749d4ef60bd05ec843898\n---\n Documentation/diff-options.txt |    3 +\n Documentation/git-apply.txt    |    8 ++-\n Makefile                       |   14 ++++-\n apply.c                        |  123 ++++++++++++++++++++++++++++++++++------\n combine-diff.c                 |   12 ++++\n diff.c                         |   83 ++++++++++++++++-----------\n diff.h                         |    3 +\n http-fetch.c                   |    8 +--\n http-push.c                    |    6 +-\n 9 files changed, 199 insertions(+), 61 deletions(-)\n\n$ git-diff-tree -r -c  4da8cbc23\n4da8cbc234177d6a8cf749d4ef60bd05ec843898\n::100644 100644 100644 c5372b984a457d0e5bddcf0b334a1a3cdc149cec\ncc7cc627c88d135c3f8d814449813e73c1ea3430\n236095fc9a1a6ffc056be8616c0f83e4e8c7ec2f MM        diff.h\n::100644 100644 100644 994ee90035c4ae5e055df79cea8621d294190a3f\naa0bc1f6f6a51fb39d54dc81b93805f86d19aa46\n19a0f772e7bf729755c66ab38f5dfb64ae784f00 MM        http-push.c\n\n\nPROPOSED OUTPUT:\n\n$ git-diff-tree -r -c --stat 4da8cbc23\n\n4da8cbc234177d6a8cf749d4ef60bd05ec843898\n---\n diff.h      |    6 +++++-\n http-push.c |    1 +\n 2 files changed, 6 insertions(+), 1 deletions(-)\n4da8cbc234177d6a8cf749d4ef60bd05ec843898\n---\n diff.h      |    3 +++\n http-push.c |    6 +++---\n 2 files changed, 6 insertions(+), 3 deletions(-)\n\n\nI agree Junio ouput is nicer, this one is perhaps more consistent with\ngit-diff-tree -m --stat output.\n\nMarco\n"}]}