Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 # Skip file only checkout. | 634 # Skip file only checkout. |
| 635 scm = gclient_scm.GetScmName(parsed_url) | 635 scm = gclient_scm.GetScmName(parsed_url) |
| 636 if not options.scm or scm in options.scm: | 636 if not options.scm or scm in options.scm: |
| 637 cwd = os.path.normpath(os.path.join(self.root.root_dir, self.name)) | 637 cwd = os.path.normpath(os.path.join(self.root.root_dir, self.name)) |
| 638 # Pass in the SCM type as an env variable | 638 # Pass in the SCM type as an env variable |
| 639 env = os.environ.copy() | 639 env = os.environ.copy() |
| 640 if scm: | 640 if scm: |
| 641 env['GCLIENT_SCM'] = scm | 641 env['GCLIENT_SCM'] = scm |
| 642 if parsed_url: | 642 if parsed_url: |
| 643 env['GCLIENT_URL'] = parsed_url | 643 env['GCLIENT_URL'] = parsed_url |
| 644 if options.prepend_dir: | 644 if options.prepend_dir: |
|
M-A Ruel
2012/11/28 01:43:11
if options.prepend_dir and scm == 'git':
Isaac (away)
2012/11/28 02:02:36
Done.
| |
| 645 print_stdout = False | 645 print_stdout = False |
| 646 def filter_fn(line): | 646 def filter_fn(line): |
|
M-A Ruel
2012/11/28 01:43:11
Add docstring along the lines
"""Git-specific path
Isaac (away)
2012/11/28 02:02:36
Done.
| |
| 647 def mod_path(git_pathspec): | |
| 648 match = re.match('(\S+?:)?([^\0]+)$', git_pathspec) | |
|
M-A Ruel
2012/11/28 01:43:11
r
Isaac (away)
2012/11/28 02:02:36
Can't use r for these, because I am looking for a
| |
| 649 modified_path = os.path.join(self.name, match.group(2)) | |
| 650 branch = match.group(1) or '' | |
|
M-A Ruel
2012/11/28 01:43:11
When r'(\S+?:)?' doesn't match, match.group(1) is
Isaac (away)
2012/11/28 02:02:36
Yep
| |
| 651 return '%s%s' % (branch, modified_path) | |
| 652 | |
| 653 match = re.match('Binary file ([^\0]+) matches$', line) | |
|
M-A Ruel
2012/11/28 01:43:11
r'^ ...
Isaac (away)
2012/11/28 02:02:36
ditto on the r. The ^ isn't necessary because of
| |
| 654 if match: | |
| 655 print 'Binary file %s matches' % mod_path(match.group(1)) | |
| 656 return | |
| 657 | |
| 647 items = line.split('\0') | 658 items = line.split('\0') |
| 648 if len(items) == 1: | 659 if len(items) == 2 and items[1]: |
| 649 match = re.match('Binary file (.*) matches$', line) | 660 print '%s : %s' % (mod_path(items[0]), items[1]) |
|
M-A Ruel
2012/11/28 01:43:11
normal git-grep output doesn't have a whitespace b
Isaac (away)
2012/11/28 02:02:36
Adding a space lets you double click and highlight
| |
| 650 if match: | 661 elif len(items) >= 2: |
| 651 print 'Binary file %s matches' % os.path.join( | |
| 652 self.name, match.group(1)) | |
| 653 else: | |
| 654 print line | |
| 655 elif len(items) == 2 and items[1]: | |
| 656 print '%s : %s' % (os.path.join(self.name, items[0]), items[1]) | |
| 657 else: | |
| 658 # Multiple null bytes or a single trailing null byte indicate | 662 # Multiple null bytes or a single trailing null byte indicate |
| 659 # git is likely displaying filenames only (such as with -l) | 663 # git is likely displaying filenames only (such as with -l) |
| 660 print '\n'.join(os.path.join(self.name, f) for f in items if f) | 664 print '\n'.join([mod_path(path) for path in items if path]) |
|
M-A Ruel
2012/11/28 01:43:11
Please don't convert the generator into a list bef
Isaac (away)
2012/11/28 02:02:36
Nice! I always forget about these.
| |
| 665 else: | |
| 666 print line | |
| 661 else: | 667 else: |
| 662 print_stdout = True | 668 print_stdout = True |
| 663 filter_fn = None | 669 filter_fn = None |
| 664 | 670 |
| 665 if os.path.isdir(cwd): | 671 if os.path.isdir(cwd): |
| 666 try: | 672 try: |
| 667 gclient_utils.CheckCallAndFilter( | 673 gclient_utils.CheckCallAndFilter( |
| 668 args, cwd=cwd, env=env, print_stdout=print_stdout, | 674 args, cwd=cwd, env=env, print_stdout=print_stdout, |
| 669 filter_fn=filter_fn, | 675 filter_fn=filter_fn, |
| 670 ) | 676 ) |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1739 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1745 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1740 print >> sys.stderr, 'Error: %s' % str(e) | 1746 print >> sys.stderr, 'Error: %s' % str(e) |
| 1741 return 1 | 1747 return 1 |
| 1742 | 1748 |
| 1743 | 1749 |
| 1744 if '__main__' == __name__: | 1750 if '__main__' == __name__: |
| 1745 fix_encoding.fix_encoding() | 1751 fix_encoding.fix_encoding() |
| 1746 sys.exit(Main(sys.argv[1:])) | 1752 sys.exit(Main(sys.argv[1:])) |
| 1747 | 1753 |
| 1748 # vim: ts=2:sw=2:tw=80:et: | 1754 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |