Browse Source

tools: allow cpplint to run outside git repo

This reapplies commit a493dab ("cpplint: make it possible to run
outside git repo") from September 2015, this time with a proper
status line.

PR-URL: https://github.com/nodejs/node/pull/7462
Refs: https://github.com/nodejs/node/issues/2693
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v7.x
Ben Noordhuis 9 years ago
parent
commit
fadf66a02b
  1. 36
      tools/cpplint.py

36
tools/cpplint.py

@ -1073,41 +1073,11 @@ class FileInfo(object):
locations won't see bogus errors. locations won't see bogus errors.
""" """
fullname = self.FullName() fullname = self.FullName()
# XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory.
if os.path.exists(fullname): toplevel = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
project_dir = os.path.dirname(fullname) prefix = os.path.commonprefix([fullname, toplevel])
if os.path.exists(os.path.join(project_dir, ".svn")):
# If there's a .svn file in the current directory, we recursively look
# up the directory tree for the top of the SVN checkout
root_dir = project_dir
one_up_dir = os.path.dirname(root_dir)
while os.path.exists(os.path.join(one_up_dir, ".svn")):
root_dir = os.path.dirname(root_dir)
one_up_dir = os.path.dirname(one_up_dir)
prefix = os.path.commonprefix([root_dir, project_dir])
return fullname[len(prefix) + 1:] return fullname[len(prefix) + 1:]
# Not SVN <= 1.6? Try to find a git, hg, or svn top level directory by
# searching up from the current path.
root_dir = current_dir = os.path.dirname(fullname)
while current_dir != os.path.dirname(current_dir):
if (os.path.exists(os.path.join(current_dir, ".git")) or
os.path.exists(os.path.join(current_dir, ".hg")) or
os.path.exists(os.path.join(current_dir, ".svn"))):
root_dir = current_dir
current_dir = os.path.dirname(current_dir)
if (os.path.exists(os.path.join(root_dir, ".git")) or
os.path.exists(os.path.join(root_dir, ".hg")) or
os.path.exists(os.path.join(root_dir, ".svn"))):
prefix = os.path.commonprefix([root_dir, project_dir])
return fullname[len(prefix) + 1:]
# Don't know what to do; header guard warnings may be wrong...
return fullname
def Split(self): def Split(self):
"""Splits the file into the directory, basename, and extension. """Splits the file into the directory, basename, and extension.

Loading…
Cancel
Save