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: #7462
Refs: #2693
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Jul 14, 2016
1 parent 09e98a4 commit 4a2bd2d
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 4a2bd2d

Please sign in to comment.