Skip to content

Commit

Permalink
tools: allow cpplint to run outside git repo
Browse files Browse the repository at this point in the history
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: nodejs#7462
Refs: nodejs#2693
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Jun 28, 2016
1 parent bb81d69 commit fadf66a
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,40 +1073,10 @@ def RepositoryName(self):
locations won't see bogus errors.
"""
fullname = self.FullName()

if os.path.exists(fullname):
project_dir = os.path.dirname(fullname)

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

# 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
# XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory.
toplevel = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
prefix = os.path.commonprefix([fullname, toplevel])
return fullname[len(prefix) + 1:]

def Split(self):
"""Splits the file into the directory, basename, and extension.
Expand Down

0 comments on commit fadf66a

Please sign in to comment.