{"thread":{"id":"17024","subject":"Quick command to count commits","startedAt":"2009-01-06T18:51:36Z","lastAt":"2009-01-06T19:55:23Z","messageCount":4,"participants":["Henk","Shawn O. Pearce","Linus Torvalds","Ted Pavlic"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"99489","messageId":"1231267896595-2118851.post@n2.nabble.com","threadId":"17024","inReplyTo":null,"subject":"Quick command to count commits","fromName":"Henk","fromEmail":"henk_westhuis@hotmail.com","sentAt":"2009-01-06T18:51:36Z","receivedAt":"2009-01-06T18:51:36Z","isPatch":false,"sender":{"key":"henk_westhuis@hotmail.com","avatar":"https://gravatar.com/avatar/cf9209436cd6db77dded64c77d6afd7a26f776d73b582ef4b3e53df0befae86b?d=mp&s=160"},"body":"\nHi,\n\nFor GitExtensions (windows git ui) I need a command to count all commits. I\nnow use this command:\ngit.cmd rev-list --all --abbrev-commit | wc -l\n\nThis works perfect but its very slow in big repositories. Is there a faster\nway to count the commits?\n\nHenk\n-- \nView this message in context: http://n2.nabble.com/Quick-command-to-count-commits-tp2118851p2118851.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"99491","messageId":"20090106185543.GB24578@spearce.org","threadId":"17024","inReplyTo":"1231267896595-2118851.post@n2.nabble.com","subject":"Re: Quick command to count commits","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-06T18:55:43Z","receivedAt":"2009-01-06T18:55:43Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Henk <henk_westhuis@hotmail.com> wrote:\n> For GitExtensions (windows git ui) I need a command to count all commits. I\n> now use this command:\n> git.cmd rev-list --all --abbrev-commit | wc -l\n> \n> This works perfect but its very slow in big repositories. Is there a faster\n> way to count the commits?\n\nNo.  But drop the --abbrev-commit flag, abbreviating the object ids\nwould take longer than just dumping the full 40 bytes to stdout.\nIt requires a scan of parts of the object database for every commit\nto determine what is a unique abbreviation.\n\nThis isn't a very common operation.  Its expensive to do, as you\ncan see.  What's the reason for supplying it, and needing it so\nquickly?  Nobody really cares how many commits are in their history,\nunless they are trying to produce stats to describe how big their\nrepository is.  In which case the size of the .git/objects/pack\n*.pack and *.idx files is much more relevant, especially the .idx\nfiles as it gives a really quick estimate on the number of total\nobjects in the repository.\n\n-- \nShawn.\n"},{"id":"99495","messageId":"alpine.LFD.2.00.0901061120530.3057@localhost.localdomain","threadId":"17024","inReplyTo":"1231267896595-2118851.post@n2.nabble.com","subject":"Re: Quick command to count commits","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-01-06T19:30:14Z","receivedAt":"2009-01-06T19:30:14Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 6 Jan 2009, Henk wrote:\n>\n> For GitExtensions (windows git ui) I need a command to count all commits. I\n> now use this command:\n> git.cmd rev-list --all --abbrev-commit | wc -l\n> \n> This works perfect but its very slow in big repositories. Is there a faster\n> way to count the commits?\n\nNope. Possibly drop the --abbrev-commit part, but it's not going to hurt \n_that_ much, and maybe avoiding piping the data can be a win in some \ncases.\n\nBasically, to get commit counts, you need to traverse the whole history, \nor at least cache it. So the only way to speed things up is\n\n - make sure your repository is well-packed. That will speed things up by \n   an absolutely huge amount, if they weren't well-packed before. Just a \n   single large pack-file, not lots of small packs, and not lots of loose \n   objects.\n\n - you can certainly cache it. Just index by the sha1sum of all the heads, \n   and you have a great cache. Just keep a single entry. So _if_ the \n   repository seldom changes, and you do this a lot, you'll at least only \n   pay the price once.\n\nIOW, do something like this:\n\n\t#!/bin/sh\n\trevs=$(git rev-parse --all)\n\tindex=$(echo \"$revs\" | sha1sum | cut -d' ' -f1)\n\tcached=$(cat .git/commit_nr_cache)\n\tcached_index=$(echo \"$cached\" | cut -d' ' -f1)\n\tif [ \"$index\" == \"$cached_index\" ]; then\n\t\techo \"$cached\" | cut -d' ' -f2\n\t\texit\n\tfi\n\tnr=$(git rev-list $revs | wc -l)\n\techo \"$index $nr\" > .git/commit_nr_cache\n\techo $nr\n\nand you now have a stupid single-entry cache.\n\nTotally untested. You'll need to do _some_ work yourself ;)\n\n\t\tLinus\n"},{"id":"99499","messageId":"4963B72B.8090406@tedpavlic.com","threadId":"17024","inReplyTo":"1231267896595-2118851.post@n2.nabble.com","subject":"Re: Quick command to count commits","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2009-01-06T19:55:23Z","receivedAt":"2009-01-06T19:55:23Z","isPatch":false,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"I doubt it's going to be much faster, but it's easier to type\n\n\tgit shortlog -s|numsum\n\nI *think* that should give you the same number, and it forces git to do \nmore of the counting (rather than wc).\n\nStrangely, on one repo that I test that on, I get slightly different \nnumbers from that command and yours. I'm not quite sure why (I guess \nshortlog doesn't count all commits?).\n\n--Ted\n\nOn 1/6/09 1:51 PM, Henk wrote:\n>\n> Hi,\n>\n> For GitExtensions (windows git ui) I need a command to count all commits. I\n> now use this command:\n> git.cmd rev-list --all --abbrev-commit | wc -l\n>\n> This works perfect but its very slow in big repositories. Is there a faster\n> way to count the commits?\n>\n> Henk\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n"}]}