Re: Add "--dirstat" for some directory statistics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux