git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-count-objects --all support
@ 2006-01-22  2:27 Petr Baudis
  2006-01-22  2:49 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Baudis @ 2006-01-22  2:27 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Having command called "git-count-objects" count only unpacked objects is
a little strange and confusing. This patch adds a warning if packs are
already present in the current repository, an --unpacked argument to
suppress the warning, and an --all argument to count even packed objects
(useful at least for statistics).

Signed-off-by: Petr Baudis <pasky@suse.cz>
---

 Documentation/git-count-objects.txt |    9 ++++----
 git-count-objects.sh                |   41 ++++++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt
index 36888d9..105721b 100644
--- a/Documentation/git-count-objects.txt
+++ b/Documentation/git-count-objects.txt
@@ -3,16 +3,17 @@ git-count-objects(1)
 
 NAME
 ----
-git-count-objects - Reports on unpacked objects.
+git-count-objects - Reports on objects count.
 
 SYNOPSIS
 --------
-'git-count-objects'
+'git-count-objects' [--unpacked | --all]
 
 DESCRIPTION
 -----------
-This counts the number of unpacked object files and disk space consumed by
-them, to help you decide when it is a good time to repack.
+This counts the number of objects and disk space consumed by them.
+It by default counts only unpacked objects in order to help you decide
+when it is a good time to repack.
 
 Author
 ------
diff --git a/git-count-objects.sh b/git-count-objects.sh
index 40c58ef..986ff14 100755
--- a/git-count-objects.sh
+++ b/git-count-objects.sh
@@ -3,7 +3,8 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+USAGE='[--unpacked | --all]'
+. git-sh-setup
 
 dc </dev/null 2>/dev/null || {
 	# This is not a real DC at all -- it just knows how
@@ -20,12 +21,44 @@ dc </dev/null 2>/dev/null || {
 	}
 }
 
-echo $(find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null | wc -l) objects, \
+all= unpacked=
+while case "$#" in 0) break;; esac
+do
+  case "$1" in
+  -a|--a|--al|--all)
+    all=t
+    shift ;;
+  -u|--u|--un|--unp|--unpa|--unpac|--unpack|--unpacke|--unpacked)
+    unpacked=t
+    shift ;;
+  *)
+    usage ;;
+  esac
+done
+
+has_packs=
+test -d "$GIT_DIR/objects/pack" && test -n "$(ls "$GIT_DIR/objects/pack")" &&
+	has_packs=objects/pack
+test -n "$has_packs" && test -z "$all" && test -z "$unpacked" &&
+	echo "Warning: Ignoring packed objects"
+test -z "$all" &&
+	has_packs=
+
+
+objcount=$(find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null | wc -l)
+test -n "$has_packs" && for pack in "$GIT_DIR/objects/pack"/*.idx; do
+	objcount=$((objcount+$(git-pack-ls-objects <"$pack" 2>/dev/null | wc -l)))
+done
+
+echo $objcount objects, \
 $({
     echo 0
+
+    cd "$GIT_DIR"
     # "no-such" is to help Darwin folks by not using xargs -r.
-    find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null |
-    xargs du -k "$GIT_DIR/objects/no-such" 2>/dev/null |
+    find objects/?? $has_packs -type f -print 2>/dev/null |
+    xargs du -k "objects/no-such" 2>/dev/null |
     sed -e 's/[ 	].*/ +/'
+
     echo p
 } | dc) kilobytes

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] git-count-objects --all support
  2006-01-22  2:27 [PATCH] git-count-objects --all support Petr Baudis
@ 2006-01-22  2:49 ` Junio C Hamano
  2006-01-22  3:02   ` Petr Baudis
  2006-01-22  3:03   ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2006-01-22  2:49 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

Petr Baudis <pasky@suse.cz> writes:

> Having command called "git-count-objects" count only unpacked objects is
> a little strange and confusing. This patch adds a warning if packs are
> already present in the current repository,

The point of counting objects is to see if it is time to repack,
so the warning is something I am quite hesitant to accept, even
with a suppression option.  The other way around is probably OK
("please warn me if I have packs"), but feels somewhat pointless.

The --all option might be a welcome addition, though.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] git-count-objects --all support
  2006-01-22  2:49 ` Junio C Hamano
@ 2006-01-22  3:02   ` Petr Baudis
  2006-01-22  3:48     ` Junio C Hamano
  2006-01-22  3:03   ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Petr Baudis @ 2006-01-22  3:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Dear diary, on Sun, Jan 22, 2006 at 03:49:40AM CET, I got a letter
where Junio C Hamano <junkio@cox.net> said that...
> Petr Baudis <pasky@suse.cz> writes:
> 
> > Having command called "git-count-objects" count only unpacked objects is
> > a little strange and confusing. This patch adds a warning if packs are
> > already present in the current repository,
> 
> The point of counting objects is to see if it is time to repack,
> so the warning is something I am quite hesitant to accept, even
> with a suppression option.

Then please change the command name - it is very confusing this way;
I've been "burnt" (well, no big deal but wrong numbers, but anyway...)
multiple times and I know others who were as well.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Of the 3 great composers Mozart tells us what it's like to be human,
Beethoven tells us what it's like to be Beethoven and Bach tells us
what it's like to be the universe.  -- Douglas Adams

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] git-count-objects --all support
  2006-01-22  2:49 ` Junio C Hamano
  2006-01-22  3:02   ` Petr Baudis
@ 2006-01-22  3:03   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2006-01-22  3:03 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

Junio C Hamano <junkio@cox.net> writes:

> The point of counting objects is to see if it is time to repack,
> so the warning is something I am quite hesitant to accept, even
> with a suppression option.  The other way around is probably OK
> ("please warn me if I have packs"), but feels somewhat pointless.
>
> The --all option might be a welcome addition, though.

I think your patch counts the same object twice if it is packed
in more than one packs and/or it has a loose copy _and_ also in
a pack.  If it is a good thing or not is totally up to the
reason why we are counting.

We might be better off if we did this kind of additions by
building on fsck-objects.  For example, you could give a --stat
option that might say something like this:

	$ git fsck-objects --full --stat
        commit	 2488
        tree    43343
        blob   212234
        total  258065
	packed 184382
	loose   78115
        dups     4432

where "dups" is number of duplicated copies --- an object packed
in more than two packs, or appearing in a pack and also having a
loose copy.  I dunno.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] git-count-objects --all support
  2006-01-22  3:02   ` Petr Baudis
@ 2006-01-22  3:48     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2006-01-22  3:48 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

Petr Baudis <pasky@suse.cz> writes:

>> The point of counting objects is to see if it is time to repack,
>> so the warning is something I am quite hesitant to accept, even
>> with a suppression option.
>
> Then please change the command name - it is very confusing this way;

True.  count-loose-objects would have been a good name, if it
were named that way from the beginning.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-22  3:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-22  2:27 [PATCH] git-count-objects --all support Petr Baudis
2006-01-22  2:49 ` Junio C Hamano
2006-01-22  3:02   ` Petr Baudis
2006-01-22  3:48     ` Junio C Hamano
2006-01-22  3:03   ` Junio C Hamano

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).