* Re: Quick command to count commits
2009-01-06 18:51 Quick command to count commits Henk
@ 2009-01-06 18:55 ` Shawn O. Pearce
2009-01-06 19:30 ` Linus Torvalds
2009-01-06 19:55 ` Ted Pavlic
2 siblings, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2009-01-06 18:55 UTC (permalink / raw)
To: Henk; +Cc: git
Henk <henk_westhuis@hotmail.com> wrote:
> For GitExtensions (windows git ui) I need a command to count all commits. I
> now use this command:
> git.cmd rev-list --all --abbrev-commit | wc -l
>
> This works perfect but its very slow in big repositories. Is there a faster
> way to count the commits?
No. But drop the --abbrev-commit flag, abbreviating the object ids
would take longer than just dumping the full 40 bytes to stdout.
It requires a scan of parts of the object database for every commit
to determine what is a unique abbreviation.
This isn't a very common operation. Its expensive to do, as you
can see. What's the reason for supplying it, and needing it so
quickly? Nobody really cares how many commits are in their history,
unless they are trying to produce stats to describe how big their
repository is. In which case the size of the .git/objects/pack
*.pack and *.idx files is much more relevant, especially the .idx
files as it gives a really quick estimate on the number of total
objects in the repository.
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Quick command to count commits
2009-01-06 18:51 Quick command to count commits Henk
2009-01-06 18:55 ` Shawn O. Pearce
@ 2009-01-06 19:30 ` Linus Torvalds
2009-01-06 19:55 ` Ted Pavlic
2 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2009-01-06 19:30 UTC (permalink / raw)
To: Henk; +Cc: git
On Tue, 6 Jan 2009, Henk wrote:
>
> For GitExtensions (windows git ui) I need a command to count all commits. I
> now use this command:
> git.cmd rev-list --all --abbrev-commit | wc -l
>
> This works perfect but its very slow in big repositories. Is there a faster
> way to count the commits?
Nope. Possibly drop the --abbrev-commit part, but it's not going to hurt
_that_ much, and maybe avoiding piping the data can be a win in some
cases.
Basically, to get commit counts, you need to traverse the whole history,
or at least cache it. So the only way to speed things up is
- make sure your repository is well-packed. That will speed things up by
an absolutely huge amount, if they weren't well-packed before. Just a
single large pack-file, not lots of small packs, and not lots of loose
objects.
- you can certainly cache it. Just index by the sha1sum of all the heads,
and you have a great cache. Just keep a single entry. So _if_ the
repository seldom changes, and you do this a lot, you'll at least only
pay the price once.
IOW, do something like this:
#!/bin/sh
revs=$(git rev-parse --all)
index=$(echo "$revs" | sha1sum | cut -d' ' -f1)
cached=$(cat .git/commit_nr_cache)
cached_index=$(echo "$cached" | cut -d' ' -f1)
if [ "$index" == "$cached_index" ]; then
echo "$cached" | cut -d' ' -f2
exit
fi
nr=$(git rev-list $revs | wc -l)
echo "$index $nr" > .git/commit_nr_cache
echo $nr
and you now have a stupid single-entry cache.
Totally untested. You'll need to do _some_ work yourself ;)
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Quick command to count commits
2009-01-06 18:51 Quick command to count commits Henk
2009-01-06 18:55 ` Shawn O. Pearce
2009-01-06 19:30 ` Linus Torvalds
@ 2009-01-06 19:55 ` Ted Pavlic
2 siblings, 0 replies; 4+ messages in thread
From: Ted Pavlic @ 2009-01-06 19:55 UTC (permalink / raw)
To: Henk; +Cc: git
I doubt it's going to be much faster, but it's easier to type
git shortlog -s|numsum
I *think* that should give you the same number, and it forces git to do
more of the counting (rather than wc).
Strangely, on one repo that I test that on, I get slightly different
numbers from that command and yours. I'm not quite sure why (I guess
shortlog doesn't count all commits?).
--Ted
On 1/6/09 1:51 PM, Henk wrote:
>
> Hi,
>
> For GitExtensions (windows git ui) I need a command to count all commits. I
> now use this command:
> git.cmd rev-list --all --abbrev-commit | wc -l
>
> This works perfect but its very slow in big repositories. Is there a faster
> way to count the commits?
>
> Henk
--
Ted Pavlic <ted@tedpavlic.com>
^ permalink raw reply [flat|nested] 4+ messages in thread