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

Side by Side Diff: gclient_scm.py

Issue 257023: Modify the output of gclient update, gclient status to only print out... (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
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 | Annotate | Revision Log
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 rev_str = "" 244 rev_str = ""
245 if revision: 245 if revision:
246 rev_str = ' at %s' % revision 246 rev_str = ' at %s' % revision
247 247
248 if not os.path.exists(checkout_path): 248 if not os.path.exists(checkout_path):
249 # We need to checkout. 249 # We need to checkout.
250 command = ['checkout', url, checkout_path] 250 command = ['checkout', url, checkout_path]
251 if revision: 251 if revision:
252 command.extend(['--revision', str(revision)]) 252 command.extend(['--revision', str(revision)])
253 RunSVNAndGetFileList(command, self._root_dir, file_list) 253 RunSVNAndGetFileList(options, command, self._root_dir, file_list)
254 return 254 return
255 255
256 # Get the existing scm url and the revision number of the current checkout. 256 # Get the existing scm url and the revision number of the current checkout.
257 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') 257 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.')
258 if not from_info: 258 if not from_info:
259 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " 259 raise gclient_utils.Error("Can't update/checkout %r if an unversioned "
260 "directory is present. Delete the directory " 260 "directory is present. Delete the directory "
261 "and try again." % 261 "and try again." %
262 checkout_path) 262 checkout_path)
263 263
264 if options.manually_grab_svn_rev: 264 # Retrieve the current HEAD version because svn is slow at null updates.
265 # Retrieve the current HEAD version because svn is slow at null updates. 265 if not revision:
266 if not revision: 266 from_info_live = CaptureSVNInfo(from_info['URL'], '.')
267 from_info_live = CaptureSVNInfo(from_info['URL'], '.') 267 revision = str(from_info_live['Revision'])
268 revision = str(from_info_live['Revision']) 268 rev_str = ' at %s' % revision
269 rev_str = ' at %s' % revision 269 forced_revision = True
270 270
271 if from_info['URL'] != components[0]: 271 if from_info['URL'] != components[0]:
272 to_info = CaptureSVNInfo(url, '.') 272 to_info = CaptureSVNInfo(url, '.')
273 if not to_info.get('Repository Root') or not to_info.get('UUID'): 273 if not to_info.get('Repository Root') or not to_info.get('UUID'):
274 # The url is invalid or the server is not accessible, it's safer to bail 274 # The url is invalid or the server is not accessible, it's safer to bail
275 # out right now. 275 # out right now.
276 raise gclient_utils.Error('This url is unreachable: %s' % url) 276 raise gclient_utils.Error('This url is unreachable: %s' % url)
277 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) 277 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
278 and (from_info['UUID'] == to_info['UUID'])) 278 and (from_info['UUID'] == to_info['UUID']))
279 if can_switch: 279 if can_switch:
(...skipping 21 matching lines...) Expand all
301 "don't match and there is local changes " 301 "don't match and there is local changes "
302 "in %s. Delete the directory and " 302 "in %s. Delete the directory and "
303 "try again." % (url, checkout_path)) 303 "try again." % (url, checkout_path))
304 # Ok delete it. 304 # Ok delete it.
305 print("\n_____ switching %s to a new checkout" % self.relpath) 305 print("\n_____ switching %s to a new checkout" % self.relpath)
306 gclient_utils.RemoveDirectory(checkout_path) 306 gclient_utils.RemoveDirectory(checkout_path)
307 # We need to checkout. 307 # We need to checkout.
308 command = ['checkout', url, checkout_path] 308 command = ['checkout', url, checkout_path]
309 if revision: 309 if revision:
310 command.extend(['--revision', str(revision)]) 310 command.extend(['--revision', str(revision)])
311 RunSVNAndGetFileList(command, self._root_dir, file_list) 311 RunSVNAndGetFileList(options, command, self._root_dir, file_list)
312 return 312 return
313 313
314 314
315 # If the provided url has a revision number that matches the revision 315 # If the provided url has a revision number that matches the revision
316 # number of the existing directory, then we don't need to bother updating. 316 # number of the existing directory, then we don't need to bother updating.
317 if not options.force and str(from_info['Revision']) == revision: 317 if not options.force and str(from_info['Revision']) == revision:
318 if options.verbose or not forced_revision: 318 if options.verbose or not forced_revision:
319 print("\n_____ %s%s" % (self.relpath, rev_str)) 319 print("\n_____ %s%s" % (self.relpath, rev_str))
320 return 320 return
321 321
322 command = ["update", checkout_path] 322 command = ["update", checkout_path]
323 if revision: 323 if revision:
324 command.extend(['--revision', str(revision)]) 324 command.extend(['--revision', str(revision)])
325 RunSVNAndGetFileList(command, self._root_dir, file_list) 325 RunSVNAndGetFileList(options, command, self._root_dir, file_list)
326 326
327 def revert(self, options, args, file_list): 327 def revert(self, options, args, file_list):
328 """Reverts local modifications. Subversion specific. 328 """Reverts local modifications. Subversion specific.
329 329
330 All reverted files will be appended to file_list, even if Subversion 330 All reverted files will be appended to file_list, even if Subversion
331 doesn't know about them. 331 doesn't know about them.
332 """ 332 """
333 path = os.path.join(self._root_dir, self.relpath) 333 path = os.path.join(self._root_dir, self.relpath)
334 if not os.path.isdir(path): 334 if not os.path.isdir(path):
335 # svn revert won't work if the directory doesn't exist. It needs to 335 # svn revert won't work if the directory doesn't exist. It needs to
(...skipping 29 matching lines...) Expand all
365 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) 365 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
366 gclient_utils.RemoveDirectory(file_path) 366 gclient_utils.RemoveDirectory(file_path)
367 else: 367 else:
368 logging.error('no idea what is %s.\nYou just found a bug in gclient' 368 logging.error('no idea what is %s.\nYou just found a bug in gclient'
369 ', please ping maruel@chromium.org ASAP!' % file_path) 369 ', please ping maruel@chromium.org ASAP!' % file_path)
370 except EnvironmentError: 370 except EnvironmentError:
371 logging.error('Failed to remove %s.' % file_path) 371 logging.error('Failed to remove %s.' % file_path)
372 372
373 # svn revert is so broken we don't even use it. Using 373 # svn revert is so broken we don't even use it. Using
374 # "svn up --revision BASE" achieve the same effect. 374 # "svn up --revision BASE" achieve the same effect.
375 RunSVNAndGetFileList(['update', '--revision', 'BASE'], path, file_list) 375 RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path, file_l ist)
M-A Ruel 2009/10/02 01:23:10 80 cols
376 376
377 def runhooks(self, options, args, file_list): 377 def runhooks(self, options, args, file_list):
378 self.status(options, args, file_list) 378 self.status(options, args, file_list)
379 379
380 def status(self, options, args, file_list): 380 def status(self, options, args, file_list):
381 """Display status information.""" 381 """Display status information."""
382 path = os.path.join(self._root_dir, self.relpath) 382 path = os.path.join(self._root_dir, self.relpath)
383 command = ['status'] 383 command = ['status']
384 command.extend(args) 384 command.extend(args)
385 if not os.path.isdir(path): 385 if not os.path.isdir(path):
386 # svn status won't work if the directory doesn't exist. 386 # svn status won't work if the directory doesn't exist.
387 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " 387 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory "
388 "does not exist." 388 "does not exist."
389 % (' '.join(command), path)) 389 % (' '.join(command), path))
390 # There's no file list to retrieve. 390 # There's no file list to retrieve.
391 else: 391 else:
392 RunSVNAndGetFileList(command, path, file_list) 392 RunSVNAndGetFileList(options, command, path, file_list)
393 393
394 def pack(self, options, args, file_list): 394 def pack(self, options, args, file_list):
395 """Generates a patch file which can be applied to the root of the 395 """Generates a patch file which can be applied to the root of the
396 repository.""" 396 repository."""
397 path = os.path.join(self._root_dir, self.relpath) 397 path = os.path.join(self._root_dir, self.relpath)
398 command = ['diff'] 398 command = ['diff']
399 command.extend(args) 399 command.extend(args)
400 # Simple class which tracks which file is being diffed and 400 # Simple class which tracks which file is being diffed and
401 # replaces instances of its file name in the original and 401 # replaces instances of its file name in the original and
402 # working copy lines of the svn diff output. 402 # working copy lines of the svn diff output.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 stderr = None 476 stderr = None
477 if not print_error: 477 if not print_error:
478 stderr = subprocess.PIPE 478 stderr = subprocess.PIPE
479 return subprocess.Popen(c, 479 return subprocess.Popen(c,
480 cwd=in_directory, 480 cwd=in_directory,
481 shell=(sys.platform == 'win32'), 481 shell=(sys.platform == 'win32'),
482 stdout=subprocess.PIPE, 482 stdout=subprocess.PIPE,
483 stderr=stderr).communicate()[0] 483 stderr=stderr).communicate()[0]
484 484
485 485
486 def RunSVNAndGetFileList(args, in_directory, file_list): 486 def RunSVNAndGetFileList(options, args, in_directory, file_list):
487 """Runs svn checkout, update, or status, output to stdout. 487 """Runs svn checkout, update, or status, output to stdout.
488 488
489 The first item in args must be either "checkout", "update", or "status". 489 The first item in args must be either "checkout", "update", or "status".
490 490
491 svn's stdout is parsed to collect a list of files checked out or updated. 491 svn's stdout is parsed to collect a list of files checked out or updated.
492 These files are appended to file_list. svn's stdout is also printed to 492 These files are appended to file_list. svn's stdout is also printed to
493 sys.stdout as in RunSVN. 493 sys.stdout as in RunSVN.
494 494
495 Args: 495 Args:
496 options: command line options to gclient
496 args: A sequence of command line parameters to be passed to svn. 497 args: A sequence of command line parameters to be passed to svn.
497 in_directory: The directory where svn is to be run. 498 in_directory: The directory where svn is to be run.
498 499
499 Raises: 500 Raises:
500 Error: An error occurred while running the svn command. 501 Error: An error occurred while running the svn command.
501 """ 502 """
502 command = [SVN_COMMAND] 503 command = [SVN_COMMAND]
503 command.extend(args) 504 command.extend(args)
504 505
505 # svn update and svn checkout use the same pattern: the first three columns 506 # svn update and svn checkout use the same pattern: the first three columns
(...skipping 19 matching lines...) Expand all
525 526
526 compiled_pattern = re.compile(pattern) 527 compiled_pattern = re.compile(pattern)
527 528
528 def CaptureMatchingLines(line): 529 def CaptureMatchingLines(line):
529 match = compiled_pattern.search(line) 530 match = compiled_pattern.search(line)
530 if match: 531 if match:
531 file_list.append(match.group(1)) 532 file_list.append(match.group(1))
532 533
533 RunSVNAndFilterOutput(args, 534 RunSVNAndFilterOutput(args,
534 in_directory, 535 in_directory,
535 True, 536 options.verbose,
536 True, 537 True,
537 CaptureMatchingLines) 538 CaptureMatchingLines)
538 539
539 def RunSVNAndFilterOutput(args, 540 def RunSVNAndFilterOutput(args,
540 in_directory, 541 in_directory,
541 print_messages, 542 print_messages,
542 print_stdout, 543 print_stdout,
543 filter): 544 filter):
544 """Runs svn checkout, update, status, or diff, optionally outputting 545 """Runs svn checkout, update, status, or diff, optionally outputting
545 to stdout. 546 to stdout.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 # Col 3 692 # Col 3
692 if wc_status[0].getAttribute('copied') == 'true': 693 if wc_status[0].getAttribute('copied') == 'true':
693 statuses[3] = '+' 694 statuses[3] = '+'
694 # Col 4 695 # Col 4
695 if wc_status[0].getAttribute('switched') == 'true': 696 if wc_status[0].getAttribute('switched') == 'true':
696 statuses[4] = 'S' 697 statuses[4] = 'S'
697 # TODO(maruel): Col 5 and 6 698 # TODO(maruel): Col 5 and 6
698 item = (''.join(statuses), file) 699 item = (''.join(statuses), file)
699 results.append(item) 700 results.append(item)
700 return results 701 return results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698