Chromium Code Reviews| Index: gclient_scm.py |
| =================================================================== |
| --- gclient_scm.py (revision 135106) |
| +++ 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 = None |
| original_prefix = "--- " |
| working_prefix = "+++ " |
| @@ -28,17 +28,17 @@ |
| # Note that we always use '/' as the path separator to be |
| # consistent with svn's cygwin-style output on Windows |
| self._relpath = relpath.replace("\\", "/") |
| - self._current_file = "" |
| - self._replacement_file = "" |
| + self._current_file = None |
| + @property |
| + def _replacement_file(self): |
| + return posixpath.join(self._relpath, self._current_file) |
| + |
| 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 |
|
M-A Ruel
2012/05/03 13:37:07
raise NotImplementedError()
|
| def _Replace(self, line): |
| - return line.replace(self._current_file, self._replacement_file) |
| + pass |
|
M-A Ruel
2012/05/03 13:37:07
raise NotImplementedError()
Or as a matter of fac
haitao.feng
2012/05/04 00:42:55
Done.
|
| def Filter(self, line): |
| if (line.startswith(self.index_string)): |
| @@ -51,6 +51,32 @@ |
| print(line) |
| +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 SetCurrentFile(self, current_file): |
| + self._current_file = current_file |
| + |
| + def _Replace(self, line): |
| + return line.replace(self._current_file, self._replacement_file) |
| + |
| + |
| +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 SetCurrentFile(self, current_file): |
| + self._current_file = current_file.split()[0][2:] |
|
M-A Ruel
2012/05/03 13:37:07
current_file.split() will not behave correctly wit
haitao.feng
2012/05/04 00:42:55
Replace with self._current_file = current_file[:(l
|
| + |
| + def _Replace(self, line): |
| + return re.sub("[a|b]/" + self._current_file, self._replacement_file, line) |
| + |
| + |
| def ask_for_data(prompt): |
| try: |
| return raw_input(prompt) |
| @@ -177,7 +203,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 +856,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. |