mojombo/grit — pull request #121 by nathanvda (2012-06-03 00:57:01+00:00)
Title: More efficient counting of tags/remotes/heads 

In Gitlab the number of tags is shown, using the command `repo.tags.count`. Now we have some very large repositories where this takes a lot of time, and slows down the complete UI.

Instead of first building the list of tags, just to take the size of it, I added a method `count_all` to `Ref`, which can then be used to implement the methods `tag_count`, `head_count` and `remote_count` on `Repo`.

Some timings, to start on the `grit` repository itself:

```

ruby-1.9.3-p125@grit ~/work/git/grit (master) $ irb
1.9.3p125 :001 > require 'grit'
=> true
1.9.3p125 :002 > repo = Grit::Repo.new('.')
=> #
1.9.3p125 :003 > repo.tag_count
=> 15
1.9.3p125 :004 > repo.tags.count
=> 15
1.9.3p125 :005 > require 'benchmark'
=> true
1.9.3p125 :006 > Benchmark.measure { repo.tag_count }
=> 0.000000 0.000000 0.000000 ( 0.000788)

1.9.3p125 :007 > Benchmark.measure { repo.tags.count }
=> 0.030000 0.000000 0.030000 ( 0.024960)
```

Then, for good measurement, on our huge repository:

```
ruby-1.9.3-p125@grit ~/work/git/grit (master) $ irb
1.9.3p125 :001 > require 'grit'
=> true
1.9.3p125 :002 > require 'benchmark'
=> true
1.9.3p125 :004 > repo = Grit::Repo.new('../../vasco/git/ttt')
=> #
1.9.3p125 :005 > Benchmark.measure { repo.tag_count }
=> 0.020000 0.000000 0.020000 ( 0.023077)

1.9.3p125 :006 > Benchmark.measure { repo.tags.count }
=> 4.130000 0.140000 4.270000 ( 4.283126)
```

I added tests as well. Any remarks or suggestions?