Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: gclient_scm.py

Issue 10317002: Make gclient pack work again by not prefixing "thread_id>" (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Gclient-specific SCM-specific operations.""" 5 """Gclient-specific SCM-specific operations."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import posixpath 9 import posixpath
10 import re 10 import re
11 import sys 11 import sys
12 import time 12 import time
13 13
14 import gclient_utils 14 import gclient_utils
15 import scm 15 import scm
16 import subprocess2 16 import subprocess2
17 17
18 18
19 class DiffFilterer(object): 19 class DiffFiltererWrapper(object):
20 """Simple class which tracks which file is being diffed and 20 """Simple class which tracks which file is being diffed and
21 replaces instances of its file name in the original and 21 replaces instances of its file name in the original and
22 working copy lines of the svn/git diff output.""" 22 working copy lines of the svn/git diff output."""
23 index_string = "Index: " 23 index_string = None
24 original_prefix = "--- " 24 original_prefix = "--- "
25 working_prefix = "+++ " 25 working_prefix = "+++ "
26 26
27 def __init__(self, relpath): 27 def __init__(self, relpath):
28 # Note that we always use '/' as the path separator to be 28 # Note that we always use '/' as the path separator to be
29 # consistent with svn's cygwin-style output on Windows 29 # consistent with svn's cygwin-style output on Windows
30 self._relpath = relpath.replace("\\", "/") 30 self._relpath = relpath.replace("\\", "/")
31 self._current_file = "" 31 self._current_file = None
32 self._replacement_file = "" 32
33 @property
34 def _replacement_file(self):
35 return posixpath.join(self._relpath, self._current_file)
33 36
34 def SetCurrentFile(self, current_file): 37 def SetCurrentFile(self, current_file):
35 self._current_file = current_file 38 pass
M-A Ruel 2012/05/03 13:37:07 raise NotImplementedError()
36 # Note that we always use '/' as the path separator to be
37 # consistent with svn's cygwin-style output on Windows
38 self._replacement_file = posixpath.join(self._relpath, current_file)
39 39
40 def _Replace(self, line): 40 def _Replace(self, line):
41 return line.replace(self._current_file, self._replacement_file) 41 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.
42 42
43 def Filter(self, line): 43 def Filter(self, line):
44 if (line.startswith(self.index_string)): 44 if (line.startswith(self.index_string)):
45 self.SetCurrentFile(line[len(self.index_string):]) 45 self.SetCurrentFile(line[len(self.index_string):])
46 line = self._Replace(line) 46 line = self._Replace(line)
47 else: 47 else:
48 if (line.startswith(self.original_prefix) or 48 if (line.startswith(self.original_prefix) or
49 line.startswith(self.working_prefix)): 49 line.startswith(self.working_prefix)):
50 line = self._Replace(line) 50 line = self._Replace(line)
51 print(line) 51 print(line)
52 52
53 53
54 class SvnDiffFilterer(DiffFiltererWrapper):
55 """Simple class which tracks which file is being diffed and
56 replaces instances of its file name in the original and
57 working copy lines of the svn diff output."""
58 index_string = "Index: "
59
60 def SetCurrentFile(self, current_file):
61 self._current_file = current_file
62
63 def _Replace(self, line):
64 return line.replace(self._current_file, self._replacement_file)
65
66
67 class GitDiffFilterer(DiffFiltererWrapper):
68 """Simple class which tracks which file is being diffed and
69 replaces instances of its file name in the original and
70 working copy lines of the git diff output."""
71 index_string = "diff --git "
72
73 def SetCurrentFile(self, current_file):
74 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
75
76 def _Replace(self, line):
77 return re.sub("[a|b]/" + self._current_file, self._replacement_file, line)
78
79
54 def ask_for_data(prompt): 80 def ask_for_data(prompt):
55 try: 81 try:
56 return raw_input(prompt) 82 return raw_input(prompt)
57 except KeyboardInterrupt: 83 except KeyboardInterrupt:
58 # Hide the exception. 84 # Hide the exception.
59 sys.exit(1) 85 sys.exit(1)
60 86
61 87
62 ### SCM abstraction layer 88 ### SCM abstraction layer
63 89
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 """Generates a patch file which can be applied to the root of the 196 """Generates a patch file which can be applied to the root of the
171 repository. 197 repository.
172 198
173 The patch file is generated from a diff of the merge base of HEAD and 199 The patch file is generated from a diff of the merge base of HEAD and
174 its upstream branch. 200 its upstream branch.
175 """ 201 """
176 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) 202 merge_base = self._Capture(['merge-base', 'HEAD', 'origin'])
177 gclient_utils.CheckCallAndFilter( 203 gclient_utils.CheckCallAndFilter(
178 ['git', 'diff', merge_base], 204 ['git', 'diff', merge_base],
179 cwd=self.checkout_path, 205 cwd=self.checkout_path,
180 filter_fn=DiffFilterer(self.relpath).Filter) 206 filter_fn=GitDiffFilterer(self.relpath).Filter)
181 207
182 def update(self, options, args, file_list): 208 def update(self, options, args, file_list):
183 """Runs git to update or transparently checkout the working copy. 209 """Runs git to update or transparently checkout the working copy.
184 210
185 All updated files will be appended to file_list. 211 All updated files will be appended to file_list.
186 212
187 Raises: 213 Raises:
188 Error: if can't get URL for relative path. 214 Error: if can't get URL for relative path.
189 """ 215 """
190 if args: 216 if args:
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 def pack(self, options, args, file_list): 849 def pack(self, options, args, file_list):
824 """Generates a patch file which can be applied to the root of the 850 """Generates a patch file which can be applied to the root of the
825 repository.""" 851 repository."""
826 if not os.path.isdir(self.checkout_path): 852 if not os.path.isdir(self.checkout_path):
827 raise gclient_utils.Error('Directory %s is not present.' % 853 raise gclient_utils.Error('Directory %s is not present.' %
828 self.checkout_path) 854 self.checkout_path)
829 gclient_utils.CheckCallAndFilter( 855 gclient_utils.CheckCallAndFilter(
830 ['svn', 'diff', '-x', '--ignore-eol-style'] + args, 856 ['svn', 'diff', '-x', '--ignore-eol-style'] + args,
831 cwd=self.checkout_path, 857 cwd=self.checkout_path,
832 print_stdout=False, 858 print_stdout=False,
833 filter_fn=DiffFilterer(self.relpath).Filter) 859 filter_fn=SvnDiffFilterer(self.relpath).Filter)
834 860
835 def update(self, options, args, file_list): 861 def update(self, options, args, file_list):
836 """Runs svn to update or transparently checkout the working copy. 862 """Runs svn to update or transparently checkout the working copy.
837 863
838 All updated files will be appended to file_list. 864 All updated files will be appended to file_list.
839 865
840 Raises: 866 Raises:
841 Error: if can't get URL for relative path. 867 Error: if can't get URL for relative path.
842 """ 868 """
843 # Only update if git or hg is not controlling the directory. 869 # Only update if git or hg is not controlling the directory.
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 new_command.append('--force') 1181 new_command.append('--force')
1156 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1182 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1157 new_command.extend(('--accept', 'theirs-conflict')) 1183 new_command.extend(('--accept', 'theirs-conflict'))
1158 elif options.manually_grab_svn_rev: 1184 elif options.manually_grab_svn_rev:
1159 new_command.append('--force') 1185 new_command.append('--force')
1160 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1186 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1161 new_command.extend(('--accept', 'postpone')) 1187 new_command.extend(('--accept', 'postpone'))
1162 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1188 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1163 new_command.extend(('--accept', 'postpone')) 1189 new_command.extend(('--accept', 'postpone'))
1164 return new_command 1190 return new_command
OLDNEW
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698