Bug 1392886 - Expose repository type as an instance property; r=mshal

This will remove the need to sniff class types. The 1 in-tree
consumer doing this has been converted.

MozReview-Commit-ID: I8cUa8J54VE

--HG--
extra : rebase_source : 4c24adaf7eb9d62678ac78604e819a7376d4073b
This commit is contained in:
Gregory Szorc 2017-08-22 20:04:55 -07:00
Родитель f9bdc9486a
Коммит ad141eef1b
2 изменённых файлов: 15 добавлений и 4 удалений

Просмотреть файл

@ -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()

Просмотреть файл

@ -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]