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

Side by Side Diff: gclient_scm.py

Issue 344004: Make 'gclient update' and 'gclient status' quieter by default - they don't... (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 1 month 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') | gclient_utils.py » ('j') | gclient_utils.py » ('J')
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(command, self._root_dir, file_list) 254 RunSVNAndGetFileList(options, 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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(command, self._root_dir, file_list) 312 RunSVNAndGetFileList(options, 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(command, self._root_dir, file_list) 326 RunSVNAndGetFileList(options, 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(['update', '--revision', 'BASE'], path, 377 RunSVNAndGetFileList(options, ['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(command, path, file_list) 399 RunSVNAndGetFileList(options, 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(args, in_directory, file_list): 549 def RunSVNAndGetFileList(options, 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
559 args: A sequence of command line parameters to be passed to svn. 560 args: A sequence of command line parameters to be passed to svn.
560 in_directory: The directory where svn is to be run. 561 in_directory: The directory where svn is to be run.
561 562
562 Raises: 563 Raises:
563 Error: An error occurred while running the svn command. 564 Error: An error occurred while running the svn command.
564 """ 565 """
565 command = [SVN_COMMAND] 566 command = [SVN_COMMAND]
566 command.extend(args) 567 command.extend(args)
567 568
568 # svn update and svn checkout use the same pattern: the first three columns 569 # svn update and svn checkout use the same pattern: the first three columns
(...skipping 19 matching lines...) Expand all
588 589
589 compiled_pattern = re.compile(pattern) 590 compiled_pattern = re.compile(pattern)
590 591
591 def CaptureMatchingLines(line): 592 def CaptureMatchingLines(line):
592 match = compiled_pattern.search(line) 593 match = compiled_pattern.search(line)
593 if match: 594 if match:
594 file_list.append(match.group(1)) 595 file_list.append(match.group(1))
595 596
596 RunSVNAndFilterOutput(args, 597 RunSVNAndFilterOutput(args,
597 in_directory, 598 in_directory,
598 True, 599 options.verbose,
599 True, 600 True,
600 CaptureMatchingLines) 601 CaptureMatchingLines)
601 602
602 def RunSVNAndFilterOutput(args, 603 def RunSVNAndFilterOutput(args,
603 in_directory, 604 in_directory,
604 print_messages, 605 print_messages,
605 print_stdout, 606 print_stdout,
606 filter): 607 filter):
607 """Runs svn checkout, update, status, or diff, optionally outputting 608 """Runs svn checkout, update, status, or diff, optionally outputting
608 to stdout. 609 to stdout.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 # Col 3 755 # Col 3
755 if wc_status[0].getAttribute('copied') == 'true': 756 if wc_status[0].getAttribute('copied') == 'true':
756 statuses[3] = '+' 757 statuses[3] = '+'
757 # Col 4 758 # Col 4
758 if wc_status[0].getAttribute('switched') == 'true': 759 if wc_status[0].getAttribute('switched') == 'true':
759 statuses[4] = 'S' 760 statuses[4] = 'S'
760 # TODO(maruel): Col 5 and 6 761 # TODO(maruel): Col 5 and 6
761 item = (''.join(statuses), file) 762 item = (''.join(statuses), file)
762 results.append(item) 763 results.append(item)
763 return results 764 return results
OLDNEW
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | gclient_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698