annotate examples/stats.py @ 180:ff6efc1ab9e4

protocol: allow hglib user to get call backs for prompts, output and errors setcbout(cbout), setcberr(cberr) and setcbprompt(cbprompt) are used to set the call back function used by the hgclient class. cb stands for call back. cbout is a function that will be called with the stdout data of the command as it runs. cbout is called with output as it is made available, which can be as partial lines or multiple lines. cberr is a function that will be called with the stderr data of the command as it runs. cberr is called with output as it is made available, which can be as partial lines or multiple lines. Command that make remote connects can prompt for username and password for HTTP/HTTPS connections. cbprompt is called when hgclient need a response to a prompt from the server. It receives the max number of bytes to return and the contents of stdout received so far. The last text sent to either cbout or cberr will contain the prompt text itself.
author Barry A. Scott <barry@barrys-emacs.org>
date Fri, 28 Oct 2016 11:33:20 +0100
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)