annotate examples/stats.py @ 129:bcc8390d7819

tests: remove "with" usage for 2.4 compatibility
author Matt Mackall <mpm@selenic.com>
date Thu, 31 Jul 2014 15:49:00 -0500
parents 031cbb8d4f65
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
1 # stats - get stats on the given repo
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
3 import sys
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4 import hglib
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
5
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
6 # figure out what repo path to use
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7 repo = '.'
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
8 if len(sys.argv) > 1:
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
9 repo = sys.argv[1]
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
10
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
11 # connect to hg
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
12 client = hglib.open(repo)
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
13
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
14 # gather some stats
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
15 revs = int(client.tip().rev)
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
16 files = len(list(client.manifest()))
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
17 heads = len(client.heads())
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
18 branches = len(client.branches())
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
19 tags = len(client.tags()) - 1 # don't count tip
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
20
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
21 authors = {}
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
22 for e in client.log():
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
23 authors[e.author] = True
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
24
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
25 merges = 0
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
26 for e in client.log(onlymerges=True):
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
27 merges += 1
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
28
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
29 print "%d revisions" % revs
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
30 print "%d merges" % merges
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
31 print "%d files" % files
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
32 print "%d heads" % heads
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
33 print "%d branches" % branches
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
34 print "%d tags" % tags
031cbb8d4f65 examples: add simple stat-gathering example
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
35 print "%d authors" % len(authors)