| 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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 parser.add_option('--reject', action='store_true', dest='reject', | 1165 parser.add_option('--reject', action='store_true', dest='reject', |
| 1166 help='allow failed patches and spew .rej files') | 1166 help='allow failed patches and spew .rej files') |
| 1167 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 1167 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
| 1168 help="don't commit after patch applies") | 1168 help="don't commit after patch applies") |
| 1169 (options, args) = parser.parse_args(args) | 1169 (options, args) = parser.parse_args(args) |
| 1170 if len(args) != 1: | 1170 if len(args) != 1: |
| 1171 parser.print_help() | 1171 parser.print_help() |
| 1172 return 1 | 1172 return 1 |
| 1173 issue_arg = args[0] | 1173 issue_arg = args[0] |
| 1174 | 1174 |
| 1175 if re.match(r'\d+', input): | 1175 if re.match(r'\d+', issue_arg): |
| 1176 # Input is an issue id. Figure out the URL. | 1176 # Input is an issue id. Figure out the URL. |
| 1177 issue = issue_arg | 1177 issue = issue_arg |
| 1178 server = settings.GetDefaultServerUrl() | 1178 server = settings.GetDefaultServerUrl() |
| 1179 fetch = urllib2.urlopen('%s/%s' % (server, issue)).read() | 1179 fetch = urllib2.urlopen('%s/%s' % (server, issue)).read() |
| 1180 m = re.search(r'/download/issue[0-9]+_[0-9]+.diff', fetch) | 1180 m = re.search(r'/download/issue[0-9]+_[0-9]+.diff', fetch) |
| 1181 if not m: | 1181 if not m: |
| 1182 DieWithError('Must pass an issue ID or full URL for ' | 1182 DieWithError('Must pass an issue ID or full URL for ' |
| 1183 '\'Download raw patch set\'') | 1183 '\'Download raw patch set\'') |
| 1184 url = '%s%s' % (server, m.group(0).strip()) | 1184 url = '%s%s' % (server, m.group(0).strip()) |
| 1185 else: | 1185 else: |
| 1186 # Assume it's a URL to the patch. Default to http. | 1186 # Assume it's a URL to the patch. Default to http. |
| 1187 issue_url = FixUrl(issue_arg) | 1187 issue_url = FixUrl(issue_arg) |
| 1188 match = re.match(r'.*?/issue(\d+)_\d+.diff', issue_url) | 1188 match = re.match(r'.*?/issue(\d+)_\d+.diff', issue_url) |
| 1189 if match: | 1189 if match: |
| 1190 issue = match.group(1) | 1190 issue = match.group(1) |
| 1191 url = input | 1191 url = issue_arg |
| 1192 else: | 1192 else: |
| 1193 DieWithError('Must pass an issue ID or full URL for ' | 1193 DieWithError('Must pass an issue ID or full URL for ' |
| 1194 '\'Download raw patch set\'') | 1194 '\'Download raw patch set\'') |
| 1195 | 1195 |
| 1196 if options.newbranch: | 1196 if options.newbranch: |
| 1197 if options.force: | 1197 if options.force: |
| 1198 RunGit(['branch', '-D', options.newbranch], | 1198 RunGit(['branch', '-D', options.newbranch], |
| 1199 swallow_stderr=True, error_ok=True) | 1199 swallow_stderr=True, error_ok=True) |
| 1200 RunGit(['checkout', '-b', options.newbranch, | 1200 RunGit(['checkout', '-b', options.newbranch, |
| 1201 Changelist().GetUpstreamBranch()]) | 1201 Changelist().GetUpstreamBranch()]) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1370 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 1371 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1371 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1372 | 1372 |
| 1373 # Not a known command. Default to help. | 1373 # Not a known command. Default to help. |
| 1374 GenUsage(parser, 'help') | 1374 GenUsage(parser, 'help') |
| 1375 return CMDhelp(parser, argv) | 1375 return CMDhelp(parser, argv) |
| 1376 | 1376 |
| 1377 | 1377 |
| 1378 if __name__ == '__main__': | 1378 if __name__ == '__main__': |
| 1379 sys.exit(main(sys.argv[1:])) | 1379 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |