mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1289805 - Ensure the VCSFiles class returns paths that have been absolutized to the repository root, r=smacleod
This makes sure we return absolute paths from the VCSFiles class. This is done so we don't accidentally normalize the relative paths onto $CWD in the event the relative path is valid in both places. MozReview-Commit-ID: 2QIuR2YqFos --HG-- extra : rebase_source : 2e82b4a5cf9a18856bbcb8d04fdc916ff7e72deb
This commit is contained in:
parent
64bfc88f52
commit
ce3f82ffbe
@ -62,22 +62,34 @@ class MozlintParser(ArgumentParser):
|
||||
self.add_argument(*cli, **args)
|
||||
|
||||
|
||||
class VCFiles(object):
|
||||
class VCSFiles(object):
|
||||
def __init__(self):
|
||||
self._root = None
|
||||
self._vcs = None
|
||||
|
||||
@property
|
||||
def vcs(self):
|
||||
if self._vcs:
|
||||
return self._vcs
|
||||
def root(self):
|
||||
if self._root:
|
||||
return self._root
|
||||
|
||||
self._vcs = 'none'
|
||||
with open(os.devnull, 'wb') as DEVNULL:
|
||||
if not subprocess.call(['hg', 'root'], stdout=DEVNULL):
|
||||
self._vcs = 'hg'
|
||||
elif not subprocess.call(['git', 'rev-parse'], stdout=DEVNULL):
|
||||
self._vcs = 'git'
|
||||
return self._vcs
|
||||
# First check if we're in an hg repo, if not try git
|
||||
commands = (
|
||||
['hg', 'root'],
|
||||
['git', 'rev-parse', '--show-toplevel'],
|
||||
)
|
||||
|
||||
for cmd in commands:
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
output = proc.communicate()[0].strip()
|
||||
|
||||
if proc.returncode == 0:
|
||||
self._vcs = cmd[0]
|
||||
self._root = output
|
||||
return self._root
|
||||
|
||||
@property
|
||||
def vcs(self):
|
||||
return self._vcs or (self.root and self._vcs)
|
||||
|
||||
@property
|
||||
def is_hg(self):
|
||||
@ -87,23 +99,23 @@ class VCFiles(object):
|
||||
def is_git(self):
|
||||
return self.vcs == 'git'
|
||||
|
||||
def _run(self, cmd):
|
||||
files = subprocess.check_output(cmd).split()
|
||||
return [os.path.join(self.root, f) for f in files]
|
||||
|
||||
def by_rev(self, rev):
|
||||
if self.is_hg:
|
||||
cmd = ['hg', 'log', '-T', '{files % "\\n{file}"}', '-r', rev]
|
||||
elif self.is_git(self):
|
||||
cmd = ['git', 'diff', '--name-only', rev]
|
||||
else:
|
||||
return []
|
||||
return subprocess.check_output(cmd).split()
|
||||
return self._run(['hg', 'log', '-T', '{files % "\\n{file}"}', '-r', rev])
|
||||
elif self.is_git:
|
||||
return self._run(['git', 'diff', '--name-only', rev])
|
||||
return []
|
||||
|
||||
def by_workdir(self):
|
||||
if self.is_hg:
|
||||
cmd = ['hg', 'status', '-amn']
|
||||
elif self.is_git(self):
|
||||
cmd = ['git', 'diff', '--name-only']
|
||||
else:
|
||||
return []
|
||||
return subprocess.check_output(cmd).split()
|
||||
return self._run(['hg', 'status', '-amn'])
|
||||
elif self.is_git:
|
||||
return self._run(['git', 'diff', '--name-only'])
|
||||
return []
|
||||
|
||||
|
||||
def find_linters(linters=None):
|
||||
@ -129,11 +141,11 @@ def run(paths, linters, fmt, rev, workdir, **lintargs):
|
||||
from mozlint import LintRoller, formatters
|
||||
|
||||
# Calculate files from VCS
|
||||
vcfiles = VCFiles()
|
||||
vcs = VCSFiles()
|
||||
if rev:
|
||||
paths.extend(vcfiles.by_rev(rev))
|
||||
paths.extend(vcs.by_rev(rev))
|
||||
if workdir:
|
||||
paths.extend(vcfiles.by_workdir())
|
||||
paths.extend(vcs.by_workdir())
|
||||
paths = paths or ['.']
|
||||
|
||||
lint = LintRoller(**lintargs)
|
||||
|
Loading…
Reference in New Issue
Block a user