annotate mozillahg/api.py @ 1:da64ea951cd8 default tip

notes to self
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 24 Mar 2013 00:44:33 -0700
parents 1855ba0b873a
children
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 from subprocess import check_output as call
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 class Hg(object):
1
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
9 """front end to mercurial using subprocess"""
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
10
0
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def __init__(self, path, hg=None):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 self.hg = hg or 'hg'
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 self.path = path
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 def __call__(self, *args):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 call([self.hg] + list(args))
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 def commits(self, start, finish=None):
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 list all commits in a range: [start..finish]
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 if `finish` is omitted, tip is used
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 """
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
1855ba0b873a initial commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 output = self("log", "", "--template", "{rev}\n")
1
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
25 return [line.strip() for line in output.strip().splitlines()]
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
26
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
27 def clone(self):
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
28 """clone a repo"""
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
29
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
30 # TODO: how does this fit in with path?
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
31 # probably ideally anything this class does can operate locally
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
32 # or remotely (using a local clone for staging when needed)
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
33
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
34 # TODO:
da64ea951cd8 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
35 # fill out .hgrc files default-push