diff --git a/python/mozversioncontrol/mozversioncontrol/__init__.py b/python/mozversioncontrol/mozversioncontrol/__init__.py index 35cc425a09cc..282f3269dade 100644 --- a/python/mozversioncontrol/mozversioncontrol/__init__.py +++ b/python/mozversioncontrol/mozversioncontrol/__init__.py @@ -64,6 +64,10 @@ class Repository(object): self.version = LooseVersion(match.group(1)) return self.version + @abc.abstractproperty + def name(self): + """Name of the tool.""" + @abc.abstractmethod def get_modified_files(self): '''Return a list of files that are modified in this repository's @@ -95,6 +99,10 @@ class HgRepository(Repository): super(HgRepository, self).__init__(path, tool=hg) self._env[b'HGPLAIN'] = b'1' + @property + def name(self): + return 'hg' + def get_modified_files(self): # Use --no-status to print just the filename. return self._run('status', '--modified', '--no-status').splitlines() @@ -123,6 +131,10 @@ class GitRepository(Repository): def __init__(self, path, git='git'): super(GitRepository, self).__init__(path, tool=git) + @property + def name(self): + return 'git' + def get_modified_files(self): return self._run('diff', '--diff-filter=M', '--name-only').splitlines() diff --git a/tools/mach_commands.py b/tools/mach_commands.py index aa30473e3c36..9ff251c2a019 100644 --- a/tools/mach_commands.py +++ b/tools/mach_commands.py @@ -8,7 +8,6 @@ import sys import os import stat import platform -import errno import re from mach.decorators import ( @@ -18,7 +17,6 @@ from mach.decorators import ( ) from mozbuild.base import MachCommandBase, MozbuildObject -import mozversioncontrol @CommandProvider @@ -263,7 +261,7 @@ class FormatProvider(MachCommandBase): # Note that this will potentially miss a lot things from subprocess import Popen, PIPE - if isinstance(self.repository, mozversioncontrol.HgRepository): + if self.repository.name == 'hg': diff_process = Popen(["hg", "diff", "-U0", "-r", ".^", "--include", "glob:**.c", "--include", "glob:**.cpp", "--include", "glob:**.h", @@ -329,9 +327,10 @@ class FormatProvider(MachCommandBase): cf_process = Popen(args) if show: # show the diff - if isinstance(self.repository, mozversioncontrol.HgRepository): + if self.repository.name == 'hg': cf_process = Popen(["hg", "diff"] + path_list) else: + assert self.repository.name == 'git' cf_process = Popen(["git", "diff"] + path_list) return cf_process.communicate()[0]