annotate mozillahg/api.py @ 0:1855ba0b873a

initial commit
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 22 Jan 2013 21:30:20 -0800
parents
children da64ea951cd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 mercurial front end API using hg CLI
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 import subprocess
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 from subprocess import check_output as call
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class Hg(object):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 def __init__(self, path, hg=None):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 self.hg = hg or 'hg'
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 self.path = path
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 def __call__(self, *args):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 call([self.hg] + list(args))
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 def commits(self, start, finish=None):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 list all commits in a range: [start..finish]
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 if `finish` is omitted, tip is used
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 output = self("log", "", "--template", "{rev}\n")
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 return [line.strip() for line in output.strip().splitlines()