| OLD | NEW |
| 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 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 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import shutil | 9 import shutil |
| 10 import subprocess | 10 import subprocess |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 results = [] | 61 results = [] |
| 62 if status: | 62 if status: |
| 63 for statusline in status.split('\n'): | 63 for statusline in status.split('\n'): |
| 64 m = re.match('^(\w)\t(.+)$', statusline) | 64 m = re.match('^(\w)\t(.+)$', statusline) |
| 65 if not m: | 65 if not m: |
| 66 raise Exception("status currently unsupported: %s" % statusline) | 66 raise Exception("status currently unsupported: %s" % statusline) |
| 67 results.append(('%s ' % m.group(1), m.group(2))) | 67 results.append(('%s ' % m.group(1), m.group(2))) |
| 68 return results | 68 return results |
| 69 | 69 |
| 70 @staticmethod | 70 @staticmethod |
| 71 def RunAndFilterOutput(args, |
| 72 in_directory, |
| 73 print_messages, |
| 74 print_stdout, |
| 75 filter): |
| 76 """Runs a command, optionally outputting to stdout. |
| 77 |
| 78 stdout is passed line-by-line to the given filter function. If |
| 79 print_stdout is true, it is also printed to sys.stdout as in Run. |
| 80 |
| 81 Args: |
| 82 args: A sequence of command line parameters to be passed. |
| 83 in_directory: The directory where svn is to be run. |
| 84 print_messages: Whether to print status messages to stdout about |
| 85 which commands are being run. |
| 86 print_stdout: Whether to forward program's output to stdout. |
| 87 filter: A function taking one argument (a string) which will be |
| 88 passed each line (with the ending newline character removed) of |
| 89 program's output for filtering. |
| 90 |
| 91 Raises: |
| 92 gclient_utils.Error: An error occurred while running the command. |
| 93 """ |
| 94 command = [GIT.COMMAND] |
| 95 command.extend(args) |
| 96 gclient_utils.SubprocessCallAndFilter(command, |
| 97 in_directory, |
| 98 print_messages, |
| 99 print_stdout, |
| 100 filter=filter) |
| 101 |
| 102 @staticmethod |
| 71 def GetEmail(repo_root): | 103 def GetEmail(repo_root): |
| 72 """Retrieves the user email address if known.""" | 104 """Retrieves the user email address if known.""" |
| 73 # We could want to look at the svn cred when it has a svn remote but it | 105 # We could want to look at the svn cred when it has a svn remote but it |
| 74 # should be fine for now, users should simply configure their git settings. | 106 # should be fine for now, users should simply configure their git settings. |
| 75 return GIT.Capture(['config', 'user.email'], | 107 return GIT.Capture(['config', 'user.email'], |
| 76 repo_root, error_ok=True).strip() | 108 repo_root, error_ok=True).strip() |
| 77 | 109 |
| 78 @staticmethod | 110 @staticmethod |
| 79 def ShortBranchName(branch): | 111 def ShortBranchName(branch): |
| 80 """Converts a name like 'refs/heads/foo' to just 'foo'.""" | 112 """Converts a name like 'refs/heads/foo' to just 'foo'.""" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 args[0] = 'update' | 358 args[0] = 'update' |
| 327 continue | 359 continue |
| 328 break | 360 break |
| 329 | 361 |
| 330 @staticmethod | 362 @staticmethod |
| 331 def RunAndFilterOutput(args, | 363 def RunAndFilterOutput(args, |
| 332 in_directory, | 364 in_directory, |
| 333 print_messages, | 365 print_messages, |
| 334 print_stdout, | 366 print_stdout, |
| 335 filter): | 367 filter): |
| 336 """Runs svn checkout, update, status, or diff, optionally outputting | 368 """Runs a command, optionally outputting to stdout. |
| 337 to stdout. | |
| 338 | 369 |
| 339 The first item in args must be either "checkout", "update", | 370 stdout is passed line-by-line to the given filter function. If |
| 340 "status", or "diff". | |
| 341 | |
| 342 svn's stdout is passed line-by-line to the given filter function. If | |
| 343 print_stdout is true, it is also printed to sys.stdout as in Run. | 371 print_stdout is true, it is also printed to sys.stdout as in Run. |
| 344 | 372 |
| 345 Args: | 373 Args: |
| 346 args: A sequence of command line parameters to be passed to svn. | 374 args: A sequence of command line parameters to be passed. |
| 347 in_directory: The directory where svn is to be run. | 375 in_directory: The directory where svn is to be run. |
| 348 print_messages: Whether to print status messages to stdout about | 376 print_messages: Whether to print status messages to stdout about |
| 349 which Subversion commands are being run. | 377 which commands are being run. |
| 350 print_stdout: Whether to forward Subversion's output to stdout. | 378 print_stdout: Whether to forward program's output to stdout. |
| 351 filter: A function taking one argument (a string) which will be | 379 filter: A function taking one argument (a string) which will be |
| 352 passed each line (with the ending newline character removed) of | 380 passed each line (with the ending newline character removed) of |
| 353 Subversion's output for filtering. | 381 program's output for filtering. |
| 354 | 382 |
| 355 Raises: | 383 Raises: |
| 356 Error: An error occurred while running the svn command. | 384 gclient_utils.Error: An error occurred while running the command. |
| 357 """ | 385 """ |
| 358 command = [SVN.COMMAND] | 386 command = [SVN.COMMAND] |
| 359 command.extend(args) | 387 command.extend(args) |
| 360 | |
| 361 gclient_utils.SubprocessCallAndFilter(command, | 388 gclient_utils.SubprocessCallAndFilter(command, |
| 362 in_directory, | 389 in_directory, |
| 363 print_messages, | 390 print_messages, |
| 364 print_stdout, | 391 print_stdout, |
| 365 filter=filter) | 392 filter=filter) |
| 366 | 393 |
| 367 @staticmethod | 394 @staticmethod |
| 368 def CaptureInfo(relpath, in_directory=None, print_error=True): | 395 def CaptureInfo(relpath, in_directory=None, print_error=True): |
| 369 """Returns a dictionary from the svn info output for the given file. | 396 """Returns a dictionary from the svn info output for the given file. |
| 370 | 397 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 if not cur_dir_repo_root: | 695 if not cur_dir_repo_root: |
| 669 return None | 696 return None |
| 670 | 697 |
| 671 while True: | 698 while True: |
| 672 parent = os.path.dirname(directory) | 699 parent = os.path.dirname(directory) |
| 673 if (SVN.CaptureInfo(parent, print_error=False).get( | 700 if (SVN.CaptureInfo(parent, print_error=False).get( |
| 674 "Repository Root") != cur_dir_repo_root): | 701 "Repository Root") != cur_dir_repo_root): |
| 675 break | 702 break |
| 676 directory = parent | 703 directory = parent |
| 677 return directory | 704 return directory |
| OLD | NEW |