view 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
line wrap: on
line source

"""
mercurial front end API using hg CLI
"""

import subprocess

from subprocess import check_output as call

class Hg(object):
    def __init__(self, path, hg=None):
        self.hg = hg or 'hg'
        self.path = path

    def __call__(self, *args):
        call([self.hg] + list(args))

    def commits(self, start, finish=None):
        """
        list all commits in a range: [start..finish]
        if `finish` is omitted, tip is used
        """

        output = self("log", "", "--template", "{rev}\n")
        return [line.strip() for line in output.strip().splitlines()