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

Side by Side Diff: gclient_scm.py

Issue 269006: Revert "Un-revert the reverted 28058, so that we get quiet again." (Closed)
Patch Set: Created 11 years, 2 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
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 rev_str = "" 245 rev_str = ""
246 if revision: 246 if revision:
247 rev_str = ' at %s' % revision 247 rev_str = ' at %s' % revision
248 248
249 if not os.path.exists(checkout_path): 249 if not os.path.exists(checkout_path):
250 # We need to checkout. 250 # We need to checkout.
251 command = ['checkout', url, checkout_path] 251 command = ['checkout', url, checkout_path]
252 if revision: 252 if revision:
253 command.extend(['--revision', str(revision)]) 253 command.extend(['--revision', str(revision)])
254 RunSVNAndGetFileList(options, command, self._root_dir, file_list) 254 RunSVNAndGetFileList(command, self._root_dir, file_list)
255 return 255 return
256 256
257 # Get the existing scm url and the revision number of the current checkout. 257 # Get the existing scm url and the revision number of the current checkout.
258 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') 258 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.')
259 if not from_info: 259 if not from_info:
260 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " 260 raise gclient_utils.Error("Can't update/checkout %r if an unversioned "
261 "directory is present. Delete the directory " 261 "directory is present. Delete the directory "
262 "and try again." % 262 "and try again." %
263 checkout_path) 263 checkout_path)
264 264
265 # Retrieve the current HEAD version because svn is slow at null updates. 265 if options.manually_grab_svn_rev:
266 if not revision: 266 # Retrieve the current HEAD version because svn is slow at null updates.
267 from_info_live = CaptureSVNInfo(from_info['URL'], '.') 267 if not revision:
268 revision = str(from_info_live['Revision']) 268 from_info_live = CaptureSVNInfo(from_info['URL'], '.')
269 rev_str = ' at %s' % revision 269 revision = str(from_info_live['Revision'])
270 forced_revision = True 270 rev_str = ' at %s' % revision
271 271
272 if from_info['URL'] != components[0]: 272 if from_info['URL'] != components[0]:
273 to_info = CaptureSVNInfo(url, '.') 273 to_info = CaptureSVNInfo(url, '.')
274 if not to_info.get('Repository Root') or not to_info.get('UUID'): 274 if not to_info.get('Repository Root') or not to_info.get('UUID'):
275 # The url is invalid or the server is not accessible, it's safer to bail 275 # The url is invalid or the server is not accessible, it's safer to bail
276 # out right now. 276 # out right now.
277 raise gclient_utils.Error('This url is unreachable: %s' % url) 277 raise gclient_utils.Error('This url is unreachable: %s' % url)
278 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) 278 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
279 and (from_info['UUID'] == to_info['UUID'])) 279 and (from_info['UUID'] == to_info['UUID']))
280 if can_switch: 280 if can_switch:
(...skipping 21 matching lines...) Expand all
302 "don't match and there is local changes " 302 "don't match and there is local changes "
303 "in %s. Delete the directory and " 303 "in %s. Delete the directory and "
304 "try again." % (url, checkout_path)) 304 "try again." % (url, checkout_path))
305 # Ok delete it. 305 # Ok delete it.
306 print("\n_____ switching %s to a new checkout" % self.relpath) 306 print("\n_____ switching %s to a new checkout" % self.relpath)
307 gclient_utils.RemoveDirectory(checkout_path) 307 gclient_utils.RemoveDirectory(checkout_path)
308 # We need to checkout. 308 # We need to checkout.
309 command = ['checkout', url, checkout_path] 309 command = ['checkout', url, checkout_path]
310 if revision: 310 if revision:
311 command.extend(['--revision', str(revision)]) 311 command.extend(['--revision', str(revision)])
312 RunSVNAndGetFileList(options, command, self._root_dir, file_list) 312 RunSVNAndGetFileList(command, self._root_dir, file_list)
313 return 313 return
314 314
315 315
316 # If the provided url has a revision number that matches the revision 316 # If the provided url has a revision number that matches the revision
317 # number of the existing directory, then we don't need to bother updating. 317 # number of the existing directory, then we don't need to bother updating.
318 if not options.force and str(from_info['Revision']) == revision: 318 if not options.force and str(from_info['Revision']) == revision:
319 if options.verbose or not forced_revision: 319 if options.verbose or not forced_revision:
320 print("\n_____ %s%s" % (self.relpath, rev_str)) 320 print("\n_____ %s%s" % (self.relpath, rev_str))
321 return 321 return
322 322
323 command = ["update", checkout_path] 323 command = ["update", checkout_path]
324 if revision: 324 if revision:
325 command.extend(['--revision', str(revision)]) 325 command.extend(['--revision', str(revision)])
326 RunSVNAndGetFileList(options, command, self._root_dir, file_list) 326 RunSVNAndGetFileList(command, self._root_dir, file_list)
327 327
328 def revert(self, options, args, file_list): 328 def revert(self, options, args, file_list):
329 """Reverts local modifications. Subversion specific. 329 """Reverts local modifications. Subversion specific.
330 330
331 All reverted files will be appended to file_list, even if Subversion 331 All reverted files will be appended to file_list, even if Subversion
332 doesn't know about them. 332 doesn't know about them.
333 """ 333 """
334 path = os.path.join(self._root_dir, self.relpath) 334 path = os.path.join(self._root_dir, self.relpath)
335 if not os.path.isdir(path): 335 if not os.path.isdir(path):
336 # svn revert won't work if the directory doesn't exist. It needs to 336 # svn revert won't work if the directory doesn't exist. It needs to
(...skipping 30 matching lines...) Expand all
367 gclient_utils.RemoveDirectory(file_path) 367 gclient_utils.RemoveDirectory(file_path)
368 else: 368 else:
369 logging.error('no idea what is %s.\nYou just found a bug in gclient' 369 logging.error('no idea what is %s.\nYou just found a bug in gclient'
370 ', please ping maruel@chromium.org ASAP!' % file_path) 370 ', please ping maruel@chromium.org ASAP!' % file_path)
371 except EnvironmentError: 371 except EnvironmentError:
372 logging.error('Failed to remove %s.' % file_path) 372 logging.error('Failed to remove %s.' % file_path)
373 373
374 try: 374 try:
375 # svn revert is so broken we don't even use it. Using 375 # svn revert is so broken we don't even use it. Using
376 # "svn up --revision BASE" achieve the same effect. 376 # "svn up --revision BASE" achieve the same effect.
377 RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path, 377 RunSVNAndGetFileList(['update', '--revision', 'BASE'], path,
378 file_list) 378 file_list)
379 except OSError, e: 379 except OSError, e:
380 # Maybe the directory disapeared meanwhile. We don't want it to throw an 380 # Maybe the directory disapeared meanwhile. We don't want it to throw an
381 # exception. 381 # exception.
382 logging.error('Failed to update:\n%s' % str(e)) 382 logging.error('Failed to update:\n%s' % str(e))
383 383
384 def runhooks(self, options, args, file_list): 384 def runhooks(self, options, args, file_list):
385 self.status(options, args, file_list) 385 self.status(options, args, file_list)
386 386
387 def status(self, options, args, file_list): 387 def status(self, options, args, file_list):
388 """Display status information.""" 388 """Display status information."""
389 path = os.path.join(self._root_dir, self.relpath) 389 path = os.path.join(self._root_dir, self.relpath)
390 command = ['status'] 390 command = ['status']
391 command.extend(args) 391 command.extend(args)
392 if not os.path.isdir(path): 392 if not os.path.isdir(path):
393 # svn status won't work if the directory doesn't exist. 393 # svn status won't work if the directory doesn't exist.
394 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " 394 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory "
395 "does not exist." 395 "does not exist."
396 % (' '.join(command), path)) 396 % (' '.join(command), path))
397 # There's no file list to retrieve. 397 # There's no file list to retrieve.
398 else: 398 else:
399 RunSVNAndGetFileList(options, command, path, file_list) 399 RunSVNAndGetFileList(command, path, file_list)
400 400
401 def pack(self, options, args, file_list): 401 def pack(self, options, args, file_list):
402 """Generates a patch file which can be applied to the root of the 402 """Generates a patch file which can be applied to the root of the
403 repository.""" 403 repository."""
404 path = os.path.join(self._root_dir, self.relpath) 404 path = os.path.join(self._root_dir, self.relpath)
405 command = ['diff'] 405 command = ['diff']
406 command.extend(args) 406 command.extend(args)
407 # Simple class which tracks which file is being diffed and 407 # Simple class which tracks which file is being diffed and
408 # replaces instances of its file name in the original and 408 # replaces instances of its file name in the original and
409 # working copy lines of the svn diff output. 409 # working copy lines of the svn diff output.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 stderr = None 539 stderr = None
540 if not print_error: 540 if not print_error:
541 stderr = subprocess.PIPE 541 stderr = subprocess.PIPE
542 return subprocess.Popen(c, 542 return subprocess.Popen(c,
543 cwd=in_directory, 543 cwd=in_directory,
544 shell=(sys.platform == 'win32'), 544 shell=(sys.platform == 'win32'),
545 stdout=subprocess.PIPE, 545 stdout=subprocess.PIPE,
546 stderr=stderr).communicate()[0] 546 stderr=stderr).communicate()[0]
547 547
548 548
549 def RunSVNAndGetFileList(options, args, in_directory, file_list): 549 def RunSVNAndGetFileList(args, in_directory, file_list):
550 """Runs svn checkout, update, or status, output to stdout. 550 """Runs svn checkout, update, or status, output to stdout.
551 551
552 The first item in args must be either "checkout", "update", or "status". 552 The first item in args must be either "checkout", "update", or "status".
553 553
554 svn's stdout is parsed to collect a list of files checked out or updated. 554 svn's stdout is parsed to collect a list of files checked out or updated.
555 These files are appended to file_list. svn's stdout is also printed to 555 These files are appended to file_list. svn's stdout is also printed to
556 sys.stdout as in RunSVN. 556 sys.stdout as in RunSVN.
557 557
558 Args: 558 Args:
559 options: command line options to gclient
560 args: A sequence of command line parameters to be passed to svn. 559 args: A sequence of command line parameters to be passed to svn.
561 in_directory: The directory where svn is to be run. 560 in_directory: The directory where svn is to be run.
562 561
563 Raises: 562 Raises:
564 Error: An error occurred while running the svn command. 563 Error: An error occurred while running the svn command.
565 """ 564 """
566 command = [SVN_COMMAND] 565 command = [SVN_COMMAND]
567 command.extend(args) 566 command.extend(args)
568 567
569 # svn update and svn checkout use the same pattern: the first three columns 568 # svn update and svn checkout use the same pattern: the first three columns
(...skipping 19 matching lines...) Expand all
589 588
590 compiled_pattern = re.compile(pattern) 589 compiled_pattern = re.compile(pattern)
591 590
592 def CaptureMatchingLines(line): 591 def CaptureMatchingLines(line):
593 match = compiled_pattern.search(line) 592 match = compiled_pattern.search(line)
594 if match: 593 if match:
595 file_list.append(match.group(1)) 594 file_list.append(match.group(1))
596 595
597 RunSVNAndFilterOutput(args, 596 RunSVNAndFilterOutput(args,
598 in_directory, 597 in_directory,
599 options.verbose, 598 True,
600 True, 599 True,
601 CaptureMatchingLines) 600 CaptureMatchingLines)
602 601
603 def RunSVNAndFilterOutput(args, 602 def RunSVNAndFilterOutput(args,
604 in_directory, 603 in_directory,
605 print_messages, 604 print_messages,
606 print_stdout, 605 print_stdout,
607 filter): 606 filter):
608 """Runs svn checkout, update, status, or diff, optionally outputting 607 """Runs svn checkout, update, status, or diff, optionally outputting
609 to stdout. 608 to stdout.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 # Col 3 754 # Col 3
756 if wc_status[0].getAttribute('copied') == 'true': 755 if wc_status[0].getAttribute('copied') == 'true':
757 statuses[3] = '+' 756 statuses[3] = '+'
758 # Col 4 757 # Col 4
759 if wc_status[0].getAttribute('switched') == 'true': 758 if wc_status[0].getAttribute('switched') == 'true':
760 statuses[4] = 'S' 759 statuses[4] = 'S'
761 # TODO(maruel): Col 5 and 6 760 # TODO(maruel): Col 5 and 6
762 item = (''.join(statuses), file) 761 item = (''.join(statuses), file)
763 results.append(item) 762 results.append(item)
764 return results 763 return results
OLDNEW
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698