OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import errno | 5 import errno |
6 import logging | 6 import logging |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 except OSError, e: | 47 except OSError, e: |
48 if e.errno == errno.EAGAIN and sys.platform == 'cygwin': | 48 if e.errno == errno.EAGAIN and sys.platform == 'cygwin': |
49 DieWithError( | 49 DieWithError( |
50 'Visit ' | 50 'Visit ' |
51 'http://code.google.com/p/chromium/wiki/CygwinDllRemappingFailure to ' | 51 'http://code.google.com/p/chromium/wiki/CygwinDllRemappingFailure to ' |
52 'learn how to fix this error; you need to rebase your cygwin dlls') | 52 'learn how to fix this error; you need to rebase your cygwin dlls') |
53 raise | 53 raise |
54 | 54 |
55 | 55 |
56 def RunCommand(cmd, error_ok=False, error_message=None, | 56 def RunCommand(cmd, error_ok=False, error_message=None, |
57 redirect_stdout=True, swallow_stderr=False): | 57 redirect_stdout=True, swallow_stderr=False, **kwargs): |
58 if redirect_stdout: | 58 if redirect_stdout: |
59 stdout = subprocess.PIPE | 59 stdout = subprocess.PIPE |
60 else: | 60 else: |
61 stdout = None | 61 stdout = None |
62 if swallow_stderr: | 62 if swallow_stderr: |
63 stderr = subprocess.PIPE | 63 stderr = subprocess.PIPE |
64 else: | 64 else: |
65 stderr = None | 65 stderr = None |
66 proc = Popen(cmd, stdout=stdout, stderr=stderr) | 66 proc = Popen(cmd, stdout=stdout, stderr=stderr, **kwargs) |
67 output = proc.communicate()[0] | 67 output = proc.communicate()[0] |
68 if not error_ok and proc.returncode != 0: | 68 if not error_ok and proc.returncode != 0: |
69 DieWithError('Command "%s" failed.\n' % (' '.join(cmd)) + | 69 DieWithError('Command "%s" failed.\n' % (' '.join(cmd)) + |
70 (error_message or output or '')) | 70 (error_message or output or '')) |
71 return output | 71 return output |
72 | 72 |
73 | 73 |
74 def RunGit(args, **kwargs): | 74 def RunGit(args, **kwargs): |
75 cmd = ['git'] + args | 75 cmd = ['git'] + args |
76 return RunCommand(cmd, **kwargs) | 76 return RunCommand(cmd, **kwargs) |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 upload_args.extend(['--message', subject]) | 801 upload_args.extend(['--message', subject]) |
802 upload_args.extend(['--description', change_desc]) | 802 upload_args.extend(['--description', change_desc]) |
803 cc = ','.join(filter(None, (settings.GetCCList(), options.cc))) | 803 cc = ','.join(filter(None, (settings.GetCCList(), options.cc))) |
804 if cc: | 804 if cc: |
805 upload_args.extend(['--cc', cc]) | 805 upload_args.extend(['--cc', cc]) |
806 | 806 |
807 # Include the upstream repo's URL in the change -- this is useful for | 807 # Include the upstream repo's URL in the change -- this is useful for |
808 # projects that have their source spread across multiple repos. | 808 # projects that have their source spread across multiple repos. |
809 remote_url = None | 809 remote_url = None |
810 if settings.GetIsGitSvn(): | 810 if settings.GetIsGitSvn(): |
811 data = RunGit(['svn', 'info']) | 811 # URL is dependent on the current directory. |
812 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) | |
812 if data: | 813 if data: |
813 keys = dict(line.split(': ', 1) for line in data.splitlines() | 814 keys = dict(line.split(': ', 1) for line in data.splitlines() |
814 if ': ' in line) | 815 if ': ' in line) |
815 remote_url = keys.get('URL', None) | 816 remote_url = keys.get('URL', None) |
Evan Martin
2011/03/03 19:50:34
FYI, I just learned that "git svn info --url" does
| |
816 else: | 817 else: |
817 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): | 818 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): |
818 remote_url = (cl.GetRemoteUrl() + '@' | 819 remote_url = (cl.GetRemoteUrl() + '@' |
819 + cl.GetUpstreamBranch().split('/')[-1]) | 820 + cl.GetUpstreamBranch().split('/')[-1]) |
820 if remote_url: | 821 if remote_url: |
821 upload_args.extend(['--base_url', remote_url]) | 822 upload_args.extend(['--base_url', remote_url]) |
822 | 823 |
823 try: | 824 try: |
824 issue, patchset = upload.RealMain(['upload'] + upload_args + args) | 825 issue, patchset = upload.RealMain(['upload'] + upload_args + args) |
825 except: | 826 except: |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1278 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1279 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1279 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1280 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1280 | 1281 |
1281 # Not a known command. Default to help. | 1282 # Not a known command. Default to help. |
1282 GenUsage(parser, 'help') | 1283 GenUsage(parser, 'help') |
1283 return CMDhelp(parser, argv) | 1284 return CMDhelp(parser, argv) |
1284 | 1285 |
1285 | 1286 |
1286 if __name__ == '__main__': | 1287 if __name__ == '__main__': |
1287 sys.exit(main(sys.argv[1:])) | 1288 sys.exit(main(sys.argv[1:])) |
OLD | NEW |