{"thread":{"id":"15388","subject":"[PATCH] Add --dirstat-by-file diff option","startedAt":"2008-09-05T19:27:35Z","lastAt":"2008-09-05T20:22:18Z","messageCount":3,"participants":["Heikki Orsila","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"89866","messageId":"20080905192735.GA12853@zakalwe.fi","threadId":"15388","inReplyTo":null,"subject":"[PATCH] Add --dirstat-by-file diff option","fromName":"Heikki Orsila","fromEmail":"heikki.orsila@iki.fi","sentAt":"2008-09-05T19:27:35Z","receivedAt":"2008-09-05T19:27:35Z","isPatch":true,"sender":{"key":"heikki.orsila@iki.fi","avatar":null},"body":"--dirstat-by-file is the same as --dirstat, but it counts\n\"impacted files\" instead of \"impacted lines\" (lines that\nare added or removed).\n\nThe patch also cleans --cumulative option handling.\nDIFF_OPT_CUMULATIVE_DIRSTAT is used instead of\nDIFF_FORMAT_CUMULATIVE.\n\nSigned-off-by: Heikki Orsila <heikki.orsila@iki.fi>\n---\nThis version takes notice of comments from Junio C Hamano and Jeff King.\n\nChanges to earlier version:\n\n* use --dirstat-by-file instead of --filedirstat\n\n* cleaner handling of --cumulative\n\n Documentation/diff-options.txt |    3 +++\n diff.c                         |   18 +++++++++++++-----\n diff.h                         |    3 ++-\n 3 files changed, 18 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 1759386..039452b 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -66,6 +66,9 @@ endif::git-format-patch[]\n \tthe \"--cumulative\" flag, which adds up percentages recursively\n \teven when they have been already reported for a sub-directory.\n \n+--dirstat-by-file[=limit]::\n+\tSame as --dirstat, but counts changed files instead of lines.\n+\n --summary::\n \tOutput a condensed summary of extended header information\n \tsuch as creations, renames and mode changes.\ndiff --git a/diff.c b/diff.c\nindex 135dec4..9b8010d 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1078,7 +1078,7 @@ static void show_dirstat(struct diff_options *options)\n \tdir.alloc = 0;\n \tdir.nr = 0;\n \tdir.percent = options->dirstat_percent;\n-\tdir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;\n+\tdir.cumulative = DIFF_OPT_TST(options, CUMULATIVE_DIRSTAT);\n \n \tchanged = 0;\n \tfor (i = 0; i < q->nr; i++) {\n@@ -1110,9 +1110,13 @@ static void show_dirstat(struct diff_options *options)\n \t\t/*\n \t\t * Original minus copied is the removed material,\n \t\t * added is the new material.  They are both damages\n-\t\t * made to the preimage.\n+\t\t * made to the preimage. In --dirstat-by-file mode, count\n+\t\t * damaged files, not damaged lines. This is done by\n+\t\t * counting only a single damaged line per file.\n \t\t */\n \t\tdamage = (p->one->size - copied) + added;\n+\t\tif (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)\n+\t\t\tdamage = 1;\n \n \t\tALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);\n \t\tdir.files[dir.nr].name = name;\n@@ -2472,9 +2476,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->output_format |= DIFF_FORMAT_SHORTSTAT;\n \telse if (opt_arg(arg, 'X', \"dirstat\", &options->dirstat_percent))\n \t\toptions->output_format |= DIFF_FORMAT_DIRSTAT;\n-\telse if (!strcmp(arg, \"--cumulative\"))\n-\t\toptions->output_format |= DIFF_FORMAT_CUMULATIVE;\n-\telse if (!strcmp(arg, \"--check\"))\n+\telse if (opt_arg(arg, 0, \"dirstat-by-file\", &options->dirstat_percent)) {\n+\t\toptions->output_format |= DIFF_FORMAT_DIRSTAT;\n+\t\tDIFF_OPT_SET(options, DIRSTAT_BY_FILE);\n+\t} else if (!strcmp(arg, \"--cumulative\")) {\n+\t\toptions->output_format |= DIFF_FORMAT_DIRSTAT;\n+\t\tDIFF_OPT_SET(options, CUMULATIVE_DIRSTAT);\n+\t} else if (!strcmp(arg, \"--check\"))\n \t\toptions->output_format |= DIFF_FORMAT_CHECKDIFF;\n \telse if (!strcmp(arg, \"--summary\"))\n \t\toptions->output_format |= DIFF_FORMAT_SUMMARY;\ndiff --git a/diff.h b/diff.h\nindex 50fb5dd..102c38c 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -31,7 +31,6 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,\n #define DIFF_FORMAT_PATCH\t0x0010\n #define DIFF_FORMAT_SHORTSTAT\t0x0020\n #define DIFF_FORMAT_DIRSTAT\t0x0040\n-#define DIFF_FORMAT_CUMULATIVE\t0x0080\n \n /* These override all above */\n #define DIFF_FORMAT_NAME\t0x0100\n@@ -64,6 +63,8 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,\n #define DIFF_OPT_CHECK_FAILED        (1 << 16)\n #define DIFF_OPT_RELATIVE_NAME       (1 << 17)\n #define DIFF_OPT_IGNORE_SUBMODULES   (1 << 18)\n+#define DIFF_OPT_CUMULATIVE_DIRSTAT  (1 << 19)\n+#define DIFF_OPT_DIRSTAT_BY_FILE     (1 << 20)\n #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)\n #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)\n #define DIFF_OPT_CLR(opts, flag)    ((opts)->flags &= ~DIFF_OPT_##flag)\n-- \n1.6.0.1\n"},{"id":"89867","messageId":"20080905194158.GA31826@coredump.intra.peff.net","threadId":"15388","inReplyTo":"20080905192735.GA12853@zakalwe.fi","subject":"Re: [PATCH] Add --dirstat-by-file diff option","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-09-05T19:41:58Z","receivedAt":"2008-09-05T19:41:58Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 05, 2008 at 10:27:35PM +0300, Heikki Orsila wrote:\n\n> --dirstat-by-file is the same as --dirstat, but it counts\n> \"impacted files\" instead of \"impacted lines\" (lines that\n> are added or removed).\n> \n> The patch also cleans --cumulative option handling.\n> DIFF_OPT_CUMULATIVE_DIRSTAT is used instead of\n> DIFF_FORMAT_CUMULATIVE.\n\nI was going to suggest that this actually be split into two patches for\nreadability, but lo and behold, Junio has already committed a fix for\n--cumulative to next. So you probably should rebase your other changes\n(which look reasonable to me) on top of that.\n\n-Peff\n"},{"id":"89869","messageId":"7viqtauyv9.fsf@gitster.siamese.dyndns.org","threadId":"15388","inReplyTo":"20080905194158.GA31826@coredump.intra.peff.net","subject":"Re: [PATCH] Add --dirstat-by-file diff option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-05T20:22:18Z","receivedAt":"2008-09-05T20:22:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Fri, Sep 05, 2008 at 10:27:35PM +0300, Heikki Orsila wrote:\n>\n>> --dirstat-by-file is the same as --dirstat, but it counts\n>> \"impacted files\" instead of \"impacted lines\" (lines that\n>> are added or removed).\n>> \n>> The patch also cleans --cumulative option handling.\n>> DIFF_OPT_CUMULATIVE_DIRSTAT is used instead of\n>> DIFF_FORMAT_CUMULATIVE.\n>\n> I was going to suggest that this actually be split into two patches for\n> readability, but lo and behold, Junio has already committed a fix for\n> --cumulative to next. So you probably should rebase your other changes\n> (which look reasonable to me) on top of that.\n\nThe fix was a maint material (the bug being \"'diff --cumulative' is a\nno-op\"), so it is everywhere not just next.\n\nHeikki, thanks for the patch, and no need to rebase nor resend.\n\n\"am -3\" works wonders in cases like this, and I can just remove the part\nthat talk about cumulative from your proposed log message.\n\n---\n\n Documentation/diff-options.txt |    3 +++\n diff.c                         |   10 +++++++++-\n diff.h                         |    1 +\n 3 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt\nindex 6e26832..7788d4f 100644\n--- c/Documentation/diff-options.txt\n+++ w/Documentation/diff-options.txt\n@@ -65,6 +65,9 @@ endif::git-format-patch[]\n \tcan be set with \"--dirstat=limit\". Changes in a child directory is not\n \tcounted for the parent directory, unless \"--cumulative\" is used.\n \n+--dirstat-by-file[=limit]::\n+\tSame as --dirstat, but counts changed files instead of lines.\n+\n --summary::\n \tOutput a condensed summary of extended header information\n \tsuch as creations, renames and mode changes.\ndiff --git c/diff.c w/diff.c\nindex cbd151b..2de86eb 100644\n--- c/diff.c\n+++ w/diff.c\n@@ -1110,9 +1110,13 @@ static void show_dirstat(struct diff_options *options)\n \t\t/*\n \t\t * Original minus copied is the removed material,\n \t\t * added is the new material.  They are both damages\n-\t\t * made to the preimage.\n+\t\t * made to the preimage. In --dirstat-by-file mode, count\n+\t\t * damaged files, not damaged lines. This is done by\n+\t\t * counting only a single damaged line per file.\n \t\t */\n \t\tdamage = (p->one->size - copied) + added;\n+\t\tif (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)\n+\t\t\tdamage = 1;\n \n \t\tALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);\n \t\tdir.files[dir.nr].name = name;\n@@ -2476,6 +2480,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (!strcmp(arg, \"--cumulative\")) {\n \t\toptions->output_format |= DIFF_FORMAT_DIRSTAT;\n \t\tDIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);\n+\t} else if (opt_arg(arg, 0, \"dirstat-by-file\",\n+\t\t\t   &options->dirstat_percent)) {\n+\t\toptions->output_format |= DIFF_FORMAT_DIRSTAT;\n+\t\tDIFF_OPT_SET(options, DIRSTAT_BY_FILE);\n \t}\n \telse if (!strcmp(arg, \"--check\"))\n \t\toptions->output_format |= DIFF_FORMAT_CHECKDIFF;\ndiff --git c/diff.h w/diff.h\nindex 7f53beb..c346888 100644\n--- c/diff.h\n+++ w/diff.h\n@@ -64,6 +64,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,\n #define DIFF_OPT_RELATIVE_NAME       (1 << 17)\n #define DIFF_OPT_IGNORE_SUBMODULES   (1 << 18)\n #define DIFF_OPT_DIRSTAT_CUMULATIVE  (1 << 19)\n+#define DIFF_OPT_DIRSTAT_BY_FILE     (1 << 20)\n #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)\n #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)\n #define DIFF_OPT_CLR(opts, flag)    ((opts)->flags &= ~DIFF_OPT_##flag)\n"}]}