git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Heikki Orsila <heikki.orsila@iki.fi>, git@vger.kernel.org
Subject: Re: [PATCH] Add --dirstat-by-file diff option
Date: Fri, 05 Sep 2008 13:22:18 -0700	[thread overview]
Message-ID: <7viqtauyv9.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080905194158.GA31826@coredump.intra.peff.net> (Jeff King's message of "Fri, 5 Sep 2008 15:41:58 -0400")

Jeff King <peff@peff.net> writes:

> On Fri, Sep 05, 2008 at 10:27:35PM +0300, Heikki Orsila wrote:
>
>> --dirstat-by-file is the same as --dirstat, but it counts
>> "impacted files" instead of "impacted lines" (lines that
>> are added or removed).
>> 
>> The patch also cleans --cumulative option handling.
>> DIFF_OPT_CUMULATIVE_DIRSTAT is used instead of
>> DIFF_FORMAT_CUMULATIVE.
>
> I was going to suggest that this actually be split into two patches for
> readability, but lo and behold, Junio has already committed a fix for
> --cumulative to next. So you probably should rebase your other changes
> (which look reasonable to me) on top of that.

The fix was a maint material (the bug being "'diff --cumulative' is a
no-op"), so it is everywhere not just next.

Heikki, thanks for the patch, and no need to rebase nor resend.

"am -3" works wonders in cases like this, and I can just remove the part
that talk about cumulative from your proposed log message.

---

 Documentation/diff-options.txt |    3 +++
 diff.c                         |   10 +++++++++-
 diff.h                         |    1 +
 3 files changed, 13 insertions(+), 1 deletions(-)

diff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt
index 6e26832..7788d4f 100644
--- c/Documentation/diff-options.txt
+++ w/Documentation/diff-options.txt
@@ -65,6 +65,9 @@ endif::git-format-patch[]
 	can be set with "--dirstat=limit". Changes in a child directory is not
 	counted for the parent directory, unless "--cumulative" is used.
 
+--dirstat-by-file[=limit]::
+	Same as --dirstat, but counts changed files instead of lines.
+
 --summary::
 	Output a condensed summary of extended header information
 	such as creations, renames and mode changes.
diff --git c/diff.c w/diff.c
index cbd151b..2de86eb 100644
--- c/diff.c
+++ w/diff.c
@@ -1110,9 +1110,13 @@ static void show_dirstat(struct diff_options *options)
 		/*
 		 * Original minus copied is the removed material,
 		 * added is the new material.  They are both damages
-		 * made to the preimage.
+		 * made to the preimage. In --dirstat-by-file mode, count
+		 * damaged files, not damaged lines. This is done by
+		 * counting only a single damaged line per file.
 		 */
 		damage = (p->one->size - copied) + added;
+		if (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)
+			damage = 1;
 
 		ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
 		dir.files[dir.nr].name = name;
@@ -2476,6 +2480,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 	else if (!strcmp(arg, "--cumulative")) {
 		options->output_format |= DIFF_FORMAT_DIRSTAT;
 		DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
+	} else if (opt_arg(arg, 0, "dirstat-by-file",
+			   &options->dirstat_percent)) {
+		options->output_format |= DIFF_FORMAT_DIRSTAT;
+		DIFF_OPT_SET(options, DIRSTAT_BY_FILE);
 	}
 	else if (!strcmp(arg, "--check"))
 		options->output_format |= DIFF_FORMAT_CHECKDIFF;
diff --git c/diff.h w/diff.h
index 7f53beb..c346888 100644
--- c/diff.h
+++ w/diff.h
@@ -64,6 +64,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_OPT_RELATIVE_NAME       (1 << 17)
 #define DIFF_OPT_IGNORE_SUBMODULES   (1 << 18)
 #define DIFF_OPT_DIRSTAT_CUMULATIVE  (1 << 19)
+#define DIFF_OPT_DIRSTAT_BY_FILE     (1 << 20)
 #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)
 #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)
 #define DIFF_OPT_CLR(opts, flag)    ((opts)->flags &= ~DIFF_OPT_##flag)

      reply	other threads:[~2008-09-05 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-05 19:27 [PATCH] Add --dirstat-by-file diff option Heikki Orsila
2008-09-05 19:41 ` Jeff King
2008-09-05 20:22   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7viqtauyv9.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=heikki.orsila@iki.fi \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).