1 # Copyright (C) 2012-2014 W. Trevor King <wking@tremily.us>
3 # This file is part of update-copyright.
5 # update-copyright is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # update-copyright is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # update-copyright. If not, see <http://www.gnu.org/licenses/>.
18 from . import VCSBackend as _VCSBackend
19 from . import utils as _utils
22 class MercurialBackend (_VCSBackend):
25 def __init__(self, **kwargs):
26 super(MercurialBackend, self).__init__(**kwargs)
27 self._version = _version
30 status,stdout,stderr = _utils.invoke(
31 ['hg'] + list(args), cwd=self._root, unicode_output=True)
32 return stdout.rstrip('\n')
34 def _years(self, filename=None):
36 '--template', '{date|shortdate}\n',
37 # shortdate filter: YEAR-MONTH-DAY
39 if filename is not None:
40 args.extend(['--follow', filename])
41 output,error = mercurial_cmd('log', *args)
42 years = set(int(line.split('-', 1)[0]) for line in output.splitlines())
45 def _authors(self, filename=None):
46 args = ['--template', '{author}\n']
47 if filename is not None:
48 args.extend(['--follow', filename])
49 output,error = mercurial_cmd('log', *args)
50 authors = set(output.splitlines())
53 def is_versioned(self, filename):
54 output,error = mercurial_cmd('log', '--follow', filename)