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

Side by Side Diff: trychange.py

Issue 8771042: Enforces using cwd in all svn calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Address comments Created 9 years 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 | « tests/scm_unittest.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Client-side script to send a try job to the try server. It communicates to 6 """Client-side script to send a try job to the try server. It communicates to
7 the try server by either writting to a svn repository or by directly connecting 7 the try server by either writting to a svn repository or by directly connecting
8 to the server by HTTP. 8 to the server by HTTP.
9 """ 9 """
10 10
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 return data 237 return data
238 238
239 # Try to search on the subversion repository for the file. 239 # Try to search on the subversion repository for the file.
240 if not gcl: 240 if not gcl:
241 return None 241 return None
242 data = gcl.GetCachedFile(filename) 242 data = gcl.GetCachedFile(filename)
243 logging.debug('%s:\n%s' % (filename, data)) 243 logging.debug('%s:\n%s' % (filename, data))
244 return data 244 return data
245 245
246 def CaptureStatus(self): 246 def CaptureStatus(self):
247 previous_cwd = os.getcwd() 247 return scm.SVN.CaptureStatus(None, self.checkout_root)
248 os.chdir(self.checkout_root)
249 result = scm.SVN.CaptureStatus(self.checkout_root)
250 os.chdir(previous_cwd)
251 return result
252 248
253 def GenerateDiff(self): 249 def GenerateDiff(self):
254 """Returns a string containing the diff for the given file list. 250 """Returns a string containing the diff for the given file list.
255 251
256 The files in the list should either be absolute paths or relative to the 252 The files in the list should either be absolute paths or relative to the
257 given root. 253 given root.
258 """ 254 """
259 return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True, 255 return scm.SVN.GenerateDiff(self.files, self.checkout_root, full_move=True,
260 revision=self.diff_against) 256 revision=self.diff_against)
261 257
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 return GIT(options, path, file_list) 457 return GIT(options, path, file_list)
462 except OSError, e: 458 except OSError, e:
463 if e.errno != errno.ENOENT: 459 if e.errno != errno.ENOENT:
464 raise 460 raise
465 except subprocess2.CalledProcessError, e: 461 except subprocess2.CalledProcessError, e:
466 if e.returncode != errno.ENOENT and e.returncode != 128: 462 if e.returncode != errno.ENOENT and e.returncode != 128:
467 # ENOENT == 2 = they don't have git installed. 463 # ENOENT == 2 = they don't have git installed.
468 # 128 = git error code when not in a repo. 464 # 128 = git error code when not in a repo.
469 logging.warning('Unexpected error code: %s' % e.returncode) 465 logging.warning('Unexpected error code: %s' % e.returncode)
470 raise 466 raise
471 raise NoTryServerAccess("Could not guess version control system. " 467 raise NoTryServerAccess(
472 "Are you in a working copy directory?") 468 ( 'Could not guess version control system for %s.\n'
469 'Are you in a working copy directory?') % path)
473 470
474 471
475 def GetMungedDiff(path_diff, diff): 472 def GetMungedDiff(path_diff, diff):
476 # Munge paths to match svn. 473 # Munge paths to match svn.
477 changed_files = [] 474 changed_files = []
478 for i in range(len(diff)): 475 for i in range(len(diff)):
479 if diff[i].startswith('--- ') or diff[i].startswith('+++ '): 476 if diff[i].startswith('--- ') or diff[i].startswith('+++ '):
480 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/') 477 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/')
481 if diff[i].startswith('--- '): 478 if diff[i].startswith('--- '):
482 file_path = new_file.split('\t')[0].strip() 479 file_path = new_file.split('\t')[0].strip()
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 return 1 811 return 1
815 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 812 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
816 print >> sys.stderr, e 813 print >> sys.stderr, e
817 return 1 814 return 1
818 return 0 815 return 0
819 816
820 817
821 if __name__ == "__main__": 818 if __name__ == "__main__":
822 fix_encoding.fix_encoding() 819 fix_encoding.fix_encoding()
823 sys.exit(TryChange(None, None, False)) 820 sys.exit(TryChange(None, None, False))
OLDNEW
« no previous file with comments | « tests/scm_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698