From: Linus Torvalds <torvalds@linux-foundation.org>
To: Henk <henk_westhuis@hotmail.com>
Cc: git@vger.kernel.org
Subject: Re: Quick command to count commits
Date: Tue, 6 Jan 2009 11:30:14 -0800 (PST) [thread overview]
Message-ID: <alpine.LFD.2.00.0901061120530.3057@localhost.localdomain> (raw)
In-Reply-To: <1231267896595-2118851.post@n2.nabble.com>
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
next prev parent reply other threads:[~2009-01-06 19:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-01-06 19:55 ` Ted Pavlic
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.2.00.0901061120530.3057@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=henk_westhuis@hotmail.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