Index: runtime/PRESUBMIT.py |
=================================================================== |
--- runtime/PRESUBMIT.py (revision 28687) |
+++ runtime/PRESUBMIT.py (working copy) |
@@ -14,7 +14,15 @@ |
def __str__(self): |
return repr(self.error_msg) |
+def AddSvnPathIfNeeded(runtime_path): |
+ # Add the .svn into the runtime directory if needed for git or svn 1.7. |
+ fake_svn_path = os.path.join(runtime_path, '.svn') |
+ if os.path.exists(fake_svn_path): |
+ return None |
+ open(fake_svn_path, 'w').close() |
+ return lambda: os.remove(fake_svn_path) |
+ |
def TrySvnPathHack(parent_path): |
orig_path = os.path.join(parent_path, '.svn') |
renamed_path = os.path.join(parent_path, '.svn_orig') |
@@ -31,27 +39,6 @@ |
return lambda: os.rename(renamed_path, orig_path) |
-def TryGitPathHack(filename, parent_path): |
- def CommonSubdirectory(parent, child): |
- while len(child) > len(parent): |
- child, tail = os.path.split(child) |
- if child == parent: |
- return os.path.join(parent, tail) |
- if os.path.exists(os.path.join(parent_path, '.git')): |
- runtime_path = CommonSubdirectory(parent_path, filename) |
- if runtime_path is not None: |
- fake_svn_path = os.path.join(runtime_path, '.svn') |
- if os.path.exists(fake_svn_path): |
- error_msg = '".svn" exists in presubmit parent subdirectory(' |
- error_msg += fake_svn_path |
- error_msg += '). Consider removing it manually.' |
- raise PathHackException(error_msg) |
- # Deposit a file named ".svn" in the runtime directory to fool |
- # cpplint into thinking it is the source root. |
- open(fake_svn_path, 'w').close() |
- return lambda: os.remove(fake_svn_path) |
- |
- |
def RunLint(input_api, output_api): |
result = [] |
cpplint._cpplint_state.ResetErrorCounts() |
@@ -60,19 +47,22 @@ |
for svn_file in input_api.AffectedTextFiles(): |
filename = svn_file.AbsoluteLocalPath() |
if filename.endswith('.cc') or filename.endswith('.h'): |
- cleanup = None |
- parent_path = os.path.dirname(input_api.PresubmitLocalPath()) |
+ cleanup_parent = None |
+ cleanup_runtime = None |
try: |
+ runtime_path = input_api.PresubmitLocalPath() |
+ parent_path = os.path.dirname(runtime_path) |
if filename.endswith('.h'): |
- cleanup = TrySvnPathHack(parent_path) |
- if cleanup is None: |
- cleanup = TryGitPathHack(filename, parent_path) |
+ cleanup_runtime = AddSvnPathIfNeeded(runtime_path) |
+ cleanup_parent = TrySvnPathHack(parent_path) |
except PathHackException, exception: |
return [output_api.PresubmitError(str(exception))] |
# Run cpplint on the file. |
cpplint.ProcessFile(filename, 1) |
- if cleanup is not None: |
- cleanup() |
+ if cleanup_parent is not None: |
+ cleanup_parent() |
+ if cleanup_runtime is not None: |
+ cleanup_runtime() |
# memcpy does not handle overlapping memory regions. Even though this |
# is well documented it seems to be used in error quite often. To avoid |
# problems we disallow the direct use of memcpy. The exceptions are in |