From: Linus Torvalds <torvalds@linux-foundation.org>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: Add "--dirstat" for some directory statistics
Date: Mon, 11 Feb 2008 14:25:26 -0800 (PST) [thread overview]
Message-ID: <alpine.LFD.1.00.0802111414590.2920@woody.linux-foundation.org> (raw)
In-Reply-To: <alpine.LFD.1.00.0802111349090.2920@woody.linux-foundation.org>
On Mon, 11 Feb 2008, Linus Torvalds wrote:
>
> Anyway, here's the patch to try out..
Ok, one more (final, I promise!) patch..
There's another issue: I think the non-cumulative percentages are more
interesting, but perhaps somebody disagrees. So here's a patch that allows
you to say
git diff --dirstat --cumulative v2.6.24..v2.6.25-rc1
and now the percentages will accumulate into the parent directory even
when they are printed out.
Example difference:
- without --cumulative:
3.2% arch/arm/
6.9% arch/powerpc/
3.2% arch/sh/
6.9% arch/x86/
11.0% arch/
3.7% drivers/media/
7.3% drivers/net/wireless/
6.9% drivers/net/
19.1% drivers/
3.5% fs/
10.3% include/
6.0% net/
3.7% sound/
- with --cumulative:
3.2% arch/arm/
6.9% arch/powerpc/
3.2% arch/sh/
6.9% arch/x86/
31.3% arch/
3.7% drivers/media/
7.3% drivers/net/wireless/
14.3% drivers/net/
37.2% drivers/
3.5% fs/
10.3% include/
6.0% net/
3.7% sound/
and note how the latter may be more "logical" (ie it now says "31.3% arch"
which simply means that about a third of the changes were somewhere under
the arch/ subdirectory), it's obvious why I don't like it in general (even
if it's wonderful in this case) when you start looking at other examples:
- without --cumulative:
100.0% arch/x86/mm/
- with --cumulative:
100.0% arch/x86/mm/
100.0% arch/x86/
100.0% arch/
which is obviously just noise and confusion, and not helpful at all.
But here's a trial patch against my original patch (ie this contains it
all - the trivial fixes, tenths of percent reporting, and now the
cumulative flag too). I was too lazy to try to split it up, and I hadn't
committed the previous ones in between (bad Linus!).
Linus
---
diff.c | 19 +++++++++++++------
diff.h | 3 ++-
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/diff.c b/diff.c
index da91bdd..e5b8baa 100644
--- a/diff.c
+++ b/diff.c
@@ -982,7 +982,7 @@ static void show_numstat(struct diffstat_t* data, struct diff_options *options)
struct diffstat_dir {
struct diffstat_file **files;
- int nr, percent;
+ int nr, percent, cumulative;
};
static long gather_dirstat(struct diffstat_dir *dir, unsigned long changed, const char *base, int baselen)
@@ -1012,10 +1012,14 @@ static long gather_dirstat(struct diffstat_dir *dir, unsigned long changed, cons
}
if (baselen) {
- int percent = this_dir * 100 / changed;
- if (percent >= dir->percent) {
- printf("%4d%% %.*s\n", percent, baselen, base);
- return 0;
+ int permille = this_dir * 1000 / changed;
+ if (permille) {
+ int percent = permille / 10;
+ if (percent >= dir->percent) {
+ printf("%4d.%01d%% %.*s\n", percent, permille % 10, baselen, base);
+ if (!dir->cumulative)
+ return 0;
+ }
}
}
return this_dir;
@@ -1042,6 +1046,7 @@ static void show_dirstat(struct diffstat_t *data, struct diff_options *options)
dir.files = data->files;
dir.nr = data->nr;
dir.percent = options->dirstat_percent;
+ dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
gather_dirstat(&dir, changed, "", 0);
}
@@ -2273,8 +2278,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
options->output_format |= DIFF_FORMAT_NUMSTAT;
else if (!strcmp(arg, "--shortstat"))
options->output_format |= DIFF_FORMAT_SHORTSTAT;
- else if (!strcmp(arg, "--dirstat"))
+ else if (opt_arg(arg, 'X', "dirstat", &options->dirstat_percent))
options->output_format |= DIFF_FORMAT_DIRSTAT;
+ else if (!strcmp(arg, "--cumulative"))
+ options->output_format |= DIFF_FORMAT_CUMULATIVE;
else if (!strcmp(arg, "--check"))
options->output_format |= DIFF_FORMAT_CHECKDIFF;
else if (!strcmp(arg, "--summary"))
diff --git a/diff.h b/diff.h
index 3181263..8c6bb54 100644
--- a/diff.h
+++ b/diff.h
@@ -30,7 +30,8 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
#define DIFF_FORMAT_SUMMARY 0x0008
#define DIFF_FORMAT_PATCH 0x0010
#define DIFF_FORMAT_SHORTSTAT 0x0020
-#define DIFF_FORMAT_DIRSTAT 0x0020
+#define DIFF_FORMAT_DIRSTAT 0x0040
+#define DIFF_FORMAT_CUMULATIVE 0x0080
/* These override all above */
#define DIFF_FORMAT_NAME 0x0100
prev parent reply other threads:[~2008-02-11 22:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-11 20:59 Add "--dirstat" for some directory statistics Linus Torvalds
2008-02-11 21:17 ` Linus Torvalds
2008-02-11 21:24 ` Johannes Schindelin
2008-02-11 21:41 ` Linus Torvalds
2008-02-11 22:06 ` Linus Torvalds
2008-02-11 22:25 ` Linus Torvalds [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=alpine.LFD.1.00.0802111414590.2920@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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