annotate examples/stats.py @ 224:2ab42323f149

client: handle commit messages with \0 characters for all commands Each of the impacted commands will now use the 'json' template, which they all support as of Mercurial 3.7.3 (the first version tested in the regression tests). Note: I tried to add a test with null bytes, but both hglib and using hg directly through subprocess rejected adding a commit message with a null byte.
author Mathias De Mare <mathias.de_mare@nokia.com>
date Mon, 13 Mar 2023 15:32: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)