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

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
« no previous file with comments | « 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 = ""
33 32
34 def SetCurrentFile(self, current_file): 33 def SetCurrentFile(self, current_file):
35 self._current_file = current_file 34 self._current_file = current_file
36 # Note that we always use '/' as the path separator to be 35
37 # consistent with svn's cygwin-style output on Windows 36 @property
38 self._replacement_file = posixpath.join(self._relpath, current_file) 37 def _replacement_file(self):
38 return posixpath.join(self._relpath, self._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 return line.replace(self._current_file, self._replacement_file)
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
M-A Ruel 2012/05/04 02:07:31 Remove the docstring, it's not informative.
haitao.feng 2012/05/04 09:46:22 Done.
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
61 class GitDiffFilterer(DiffFiltererWrapper):
62 """Simple class which tracks which file is being diffed and
63 replaces instances of its file name in the original and
64 working copy lines of the git diff output."""
65 index_string = "diff --git "
66
67 def SetCurrentFile(self, current_file):
68 # Get filename by parsing "a/<filename> b/<filename>"
69 self._current_file = current_file[:(len(current_file)/2)][2:]
M-A Ruel 2012/05/04 02:07:31 ~/src/chrome/src> git mv AUTHORS foo ~/src/chrome/
haitao.feng 2012/05/04 09:46:22 There is no option "-C" in the git diff command. T
70
71 def _Replace(self, line):
72 return re.sub("[a|b]/" + self._current_file, self._replacement_file, line)
73
74
54 def ask_for_data(prompt): 75 def ask_for_data(prompt):
55 try: 76 try:
56 return raw_input(prompt) 77 return raw_input(prompt)
57 except KeyboardInterrupt: 78 except KeyboardInterrupt:
58 # Hide the exception. 79 # Hide the exception.
59 sys.exit(1) 80 sys.exit(1)
60 81
61 82
62 ### SCM abstraction layer 83 ### SCM abstraction layer
63 84
(...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 191 """Generates a patch file which can be applied to the root of the
171 repository. 192 repository.
172 193
173 The patch file is generated from a diff of the merge base of HEAD and 194 The patch file is generated from a diff of the merge base of HEAD and
174 its upstream branch. 195 its upstream branch.
175 """ 196 """
176 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) 197 merge_base = self._Capture(['merge-base', 'HEAD', 'origin'])
177 gclient_utils.CheckCallAndFilter( 198 gclient_utils.CheckCallAndFilter(
178 ['git', 'diff', merge_base], 199 ['git', 'diff', merge_base],
179 cwd=self.checkout_path, 200 cwd=self.checkout_path,
180 filter_fn=DiffFilterer(self.relpath).Filter) 201 filter_fn=GitDiffFilterer(self.relpath).Filter)
181 202
182 def update(self, options, args, file_list): 203 def update(self, options, args, file_list):
183 """Runs git to update or transparently checkout the working copy. 204 """Runs git to update or transparently checkout the working copy.
184 205
185 All updated files will be appended to file_list. 206 All updated files will be appended to file_list.
186 207
187 Raises: 208 Raises:
188 Error: if can't get URL for relative path. 209 Error: if can't get URL for relative path.
189 """ 210 """
190 if args: 211 if args:
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 def pack(self, options, args, file_list): 844 def pack(self, options, args, file_list):
824 """Generates a patch file which can be applied to the root of the 845 """Generates a patch file which can be applied to the root of the
825 repository.""" 846 repository."""
826 if not os.path.isdir(self.checkout_path): 847 if not os.path.isdir(self.checkout_path):
827 raise gclient_utils.Error('Directory %s is not present.' % 848 raise gclient_utils.Error('Directory %s is not present.' %
828 self.checkout_path) 849 self.checkout_path)
829 gclient_utils.CheckCallAndFilter( 850 gclient_utils.CheckCallAndFilter(
830 ['svn', 'diff', '-x', '--ignore-eol-style'] + args, 851 ['svn', 'diff', '-x', '--ignore-eol-style'] + args,
831 cwd=self.checkout_path, 852 cwd=self.checkout_path,
832 print_stdout=False, 853 print_stdout=False,
833 filter_fn=DiffFilterer(self.relpath).Filter) 854 filter_fn=SvnDiffFilterer(self.relpath).Filter)
834 855
835 def update(self, options, args, file_list): 856 def update(self, options, args, file_list):
836 """Runs svn to update or transparently checkout the working copy. 857 """Runs svn to update or transparently checkout the working copy.
837 858
838 All updated files will be appended to file_list. 859 All updated files will be appended to file_list.
839 860
840 Raises: 861 Raises:
841 Error: if can't get URL for relative path. 862 Error: if can't get URL for relative path.
842 """ 863 """
843 # Only update if git or hg is not controlling the directory. 864 # 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') 1176 new_command.append('--force')
1156 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1177 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1157 new_command.extend(('--accept', 'theirs-conflict')) 1178 new_command.extend(('--accept', 'theirs-conflict'))
1158 elif options.manually_grab_svn_rev: 1179 elif options.manually_grab_svn_rev:
1159 new_command.append('--force') 1180 new_command.append('--force')
1160 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1181 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1161 new_command.extend(('--accept', 'postpone')) 1182 new_command.extend(('--accept', 'postpone'))
1162 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1183 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1163 new_command.extend(('--accept', 'postpone')) 1184 new_command.extend(('--accept', 'postpone'))
1164 return new_command 1185 return new_command
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698