Index: gclient_scm.py |
=================================================================== |
--- gclient_scm.py (revision 134877) |
+++ gclient_scm.py (working copy) |
@@ -16,11 +16,11 @@ |
import subprocess2 |
-class DiffFilterer(object): |
+class DiffFiltererWrapper(object): |
"""Simple class which tracks which file is being diffed and |
replaces instances of its file name in the original and |
working copy lines of the svn/git diff output.""" |
- index_string = "Index: " |
+ index_string = "" |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
index_string = None
so the code would fail if not
haitao.feng
2012/05/03 09:15:18
Done.
|
original_prefix = "--- " |
working_prefix = "+++ " |
@@ -32,13 +32,10 @@ |
self._replacement_file = "" |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
self._replacement_file is not really needed, you c
haitao.feng
2012/05/03 09:15:18
Done.
|
def SetCurrentFile(self, current_file): |
- self._current_file = current_file |
- # Note that we always use '/' as the path separator to be |
- # consistent with svn's cygwin-style output on Windows |
- self._replacement_file = posixpath.join(self._relpath, current_file) |
+ pass |
def _Replace(self, line): |
- return line.replace(self._current_file, self._replacement_file) |
+ pass |
def Filter(self, line): |
if (line.startswith(self.index_string)): |
@@ -50,7 +47,40 @@ |
line = self._Replace(line) |
print(line) |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
2 lines
haitao.feng
2012/05/03 09:15:18
Done.
|
+class SvnDiffFilterer(DiffFiltererWrapper): |
+ """Simple class which tracks which file is being diffed and |
+ replaces instances of its file name in the original and |
+ working copy lines of the svn diff output.""" |
+ index_string = "Index: " |
+ def __init__(self, relpath): |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
You can remove this constructor entirely. The clas
haitao.feng
2012/05/03 09:15:18
Done.
|
+ DiffFiltererWrapper.__init__(self, relpath) |
+ |
+ def SetCurrentFile(self, current_file): |
+ self._current_file = current_file |
+ self._replacement_file = posixpath.join(self._relpath, current_file) |
+ |
+ def _Replace(self, line): |
+ return line.replace(self._current_file, self._replacement_file) |
+ |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
2 lines
haitao.feng
2012/05/03 09:15:18
Done.
|
+class GitDiffFilterer(DiffFiltererWrapper): |
+ """Simple class which tracks which file is being diffed and |
+ replaces instances of its file name in the original and |
+ working copy lines of the git diff output.""" |
+ index_string = "diff --git " |
+ |
+ def __init__(self, relpath): |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
Same, remove
haitao.feng
2012/05/03 09:15:18
Done.
|
+ DiffFiltererWrapper.__init__(self, relpath) |
+ |
+ def SetCurrentFile(self, current_file): |
+ self._current_file = current_file.split()[0][2:] |
+ self._replacement_file = posixpath.join(self._relpath, self._current_file) |
+ |
+ def _Replace(self, line): |
+ result = line.replace("a/" + self._current_file, self._replacement_file) |
Marc-Antoine Ruel (Google)
2012/05/03 01:30:53
that's a bit tricky though, if the file name is in
haitao.feng
2012/05/03 09:15:18
Replace with re.sub("[a|b]/" + self._current_file,
|
+ return result.replace("b/" + self._current_file, self._replacement_file) |
+ |
+ |
def ask_for_data(prompt): |
try: |
return raw_input(prompt) |
@@ -177,7 +207,7 @@ |
gclient_utils.CheckCallAndFilter( |
['git', 'diff', merge_base], |
cwd=self.checkout_path, |
- filter_fn=DiffFilterer(self.relpath).Filter) |
+ filter_fn=GitDiffFilterer(self.relpath).Filter) |
def update(self, options, args, file_list): |
"""Runs git to update or transparently checkout the working copy. |
@@ -830,7 +860,7 @@ |
['svn', 'diff', '-x', '--ignore-eol-style'] + args, |
cwd=self.checkout_path, |
print_stdout=False, |
- filter_fn=DiffFilterer(self.relpath).Filter) |
+ filter_fn=SvnDiffFilterer(self.relpath).Filter) |
def update(self, options, args, file_list): |
"""Runs svn to update or transparently checkout the working copy. |