Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 try: | 22 try: |
| 23 # Add the parent directory in case it's a depot_tools checkout. | 23 # Add the parent directory in case it's a depot_tools checkout. |
| 24 depot_tools_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 24 depot_tools_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 25 sys.path.append(depot_tools_path) | 25 sys.path.append(depot_tools_path) |
| 26 import breakpad | 26 import breakpad |
| 27 except ImportError: | 27 except ImportError: |
| 28 pass | 28 pass |
| 29 | 29 |
| 30 DEFAULT_SERVER = 'http://codereview.appspot.com' | 30 DEFAULT_SERVER = 'http://codereview.appspot.com' |
| 31 PREDCOMMIT_HOOK = '.git/hooks/pre-cl-dcommit' | 31 PREDCOMMIT_HOOK = '.git/hooks/pre-cl-dcommit' |
| 32 POSTDCOMMIT_HOOK = '.git/hooks/post-cl-dcommit' | |
| 32 PREUPLOAD_HOOK = '.git/hooks/pre-cl-upload' | 33 PREUPLOAD_HOOK = '.git/hooks/pre-cl-upload' |
| 33 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' | 34 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
| 34 | 35 |
| 35 def DieWithError(message): | 36 def DieWithError(message): |
| 36 print >>sys.stderr, message | 37 print >>sys.stderr, message |
| 37 sys.exit(1) | 38 sys.exit(1) |
| 38 | 39 |
| 39 | 40 |
| 40 def Popen(cmd, **kwargs): | 41 def Popen(cmd, **kwargs): |
| 41 """Wrapper for subprocess.Popen() that logs and watch for cygwin issues""" | 42 """Wrapper for subprocess.Popen() that logs and watch for cygwin issues""" |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 # We might be in a directory that's present in this branch but not in the | 965 # We might be in a directory that's present in this branch but not in the |
| 965 # trunk. Move up to the top of the tree so that git commands that expect a | 966 # trunk. Move up to the top of the tree so that git commands that expect a |
| 966 # valid CWD won't fail after we check out the merge branch. | 967 # valid CWD won't fail after we check out the merge branch. |
| 967 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() | 968 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() |
| 968 if rel_base_path: | 969 if rel_base_path: |
| 969 os.chdir(rel_base_path) | 970 os.chdir(rel_base_path) |
| 970 | 971 |
| 971 # Stuff our change into the merge branch. | 972 # Stuff our change into the merge branch. |
| 972 # We wrap in a try...finally block so if anything goes wrong, | 973 # We wrap in a try...finally block so if anything goes wrong, |
| 973 # we clean up the branches. | 974 # we clean up the branches. |
| 975 retcode = -1 | |
| 974 try: | 976 try: |
| 975 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) | 977 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) |
| 976 RunGit(['merge', '--squash', cl.GetBranchRef()]) | 978 RunGit(['merge', '--squash', cl.GetBranchRef()]) |
| 977 if options.contributor: | 979 if options.contributor: |
| 978 RunGit(['commit', '--author', options.contributor, '-m', description]) | 980 RunGit(['commit', '--author', options.contributor, '-m', description]) |
| 979 else: | 981 else: |
| 980 RunGit(['commit', '-m', description]) | 982 RunGit(['commit', '-m', description]) |
| 981 if cmd == 'push': | 983 if cmd == 'push': |
| 982 # push the merge branch. | 984 # push the merge branch. |
| 983 remote, branch = cl.FetchUpstreamTuple() | 985 remote, branch = cl.FetchUpstreamTuple() |
| 984 retcode, output = RunGitWithCode( | 986 retcode, output = RunGitWithCode( |
| 985 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) | 987 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) |
| 986 logging.debug(output) | 988 logging.debug(output) |
| 987 else: | 989 else: |
| 988 # dcommit the merge branch. | 990 # dcommit the merge branch. |
| 989 output = RunGit(['svn', 'dcommit', '--no-rebase']) | 991 retcode, output = RunGitWithCode(['svn', 'dcommit', '--no-rebase']) |
| 990 finally: | 992 finally: |
| 991 # And then swap back to the original branch and clean up. | 993 # And then swap back to the original branch and clean up. |
| 992 RunGit(['checkout', '-q', cl.GetBranch()]) | 994 RunGit(['checkout', '-q', cl.GetBranch()]) |
| 993 RunGit(['branch', '-D', MERGE_BRANCH]) | 995 RunGit(['branch', '-D', MERGE_BRANCH]) |
| 994 | 996 |
| 997 if retcode == 0 and os.path.isfile(POSTDCOMMIT_HOOK): | |
|
Evan Martin
2010/12/23 00:32:07
My point was that you don't need to check retcode
sadrul
2010/12/23 00:41:32
Ah. I wasn't sure if that would always be the case
| |
| 998 RunHook(POSTDCOMMIT_HOOK, upstream_branch=base_branch, error_ok=True) | |
| 999 | |
| 995 if cl.GetIssue(): | 1000 if cl.GetIssue(): |
| 996 if cmd == 'dcommit' and 'Committed r' in output: | 1001 if cmd == 'dcommit' and 'Committed r' in output: |
| 997 revision = re.match('.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) | 1002 revision = re.match('.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) |
| 998 elif cmd == 'push' and retcode == 0: | 1003 elif cmd == 'push' and retcode == 0: |
| 999 revision = output.splitlines()[1].split('\t')[2].split('..')[1] | 1004 revision = output.splitlines()[1].split('\t')[2].split('..')[1] |
| 1000 else: | 1005 else: |
| 1001 return 1 | 1006 return 1 |
| 1002 viewvc_url = settings.GetViewVCUrl() | 1007 viewvc_url = settings.GetViewVCUrl() |
| 1003 if viewvc_url and revision: | 1008 if viewvc_url and revision: |
| 1004 cl.description += ('\n\nCommitted: ' + viewvc_url + revision) | 1009 cl.description += ('\n\nCommitted: ' + viewvc_url + revision) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1245 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1250 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 1246 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1251 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1247 | 1252 |
| 1248 # Not a known command. Default to help. | 1253 # Not a known command. Default to help. |
| 1249 GenUsage(parser, 'help') | 1254 GenUsage(parser, 'help') |
| 1250 return CMDhelp(parser, argv) | 1255 return CMDhelp(parser, argv) |
| 1251 | 1256 |
| 1252 | 1257 |
| 1253 if __name__ == '__main__': | 1258 if __name__ == '__main__': |
| 1254 sys.exit(main(sys.argv[1:])) | 1259 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |