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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 29 matching lines...) Expand all Loading... | |
40 from third_party import colorama | 40 from third_party import colorama |
41 from third_party import httplib2 | 41 from third_party import httplib2 |
42 from third_party import upload | 42 from third_party import upload |
43 import auth | 43 import auth |
44 from luci_hacks import trigger_luci_job as luci_trigger | 44 from luci_hacks import trigger_luci_job as luci_trigger |
45 import clang_format | 45 import clang_format |
46 import commit_queue | 46 import commit_queue |
47 import dart_format | 47 import dart_format |
48 import fix_encoding | 48 import fix_encoding |
49 import gclient_utils | 49 import gclient_utils |
50 import git_cache | |
50 import git_common | 51 import git_common |
51 import git_footers | 52 import git_footers |
52 import owners | 53 import owners |
53 import owners_finder | 54 import owners_finder |
54 import presubmit_support | 55 import presubmit_support |
55 import rietveld | 56 import rietveld |
56 import scm | 57 import scm |
57 import subcommand | 58 import subcommand |
58 import subprocess2 | 59 import subprocess2 |
59 import watchlists | 60 import watchlists |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 | 622 |
622 @staticmethod | 623 @staticmethod |
623 def GetRelativeRoot(): | 624 def GetRelativeRoot(): |
624 return RunGit(['rev-parse', '--show-cdup']).strip() | 625 return RunGit(['rev-parse', '--show-cdup']).strip() |
625 | 626 |
626 def GetRoot(self): | 627 def GetRoot(self): |
627 if self.root is None: | 628 if self.root is None: |
628 self.root = os.path.abspath(self.GetRelativeRoot()) | 629 self.root = os.path.abspath(self.GetRelativeRoot()) |
629 return self.root | 630 return self.root |
630 | 631 |
632 def GetGitMirror(self, remote='origin'): | |
633 """If this checkout is from a local git mirror, return a Mirror object.""" | |
634 local_url = RunGit(['remote', 'get-url', remote]).strip() | |
smut
2016/03/09 22:17:31
"git remote get-url" is not available in all versi
| |
635 if not os.path.isdir(local_url): | |
636 return None | |
637 git_cache.Mirror.SetCachePath(os.path.dirname(local_url)) | |
638 remote_url = git_cache.Mirror.CacheDirToUrl(local_url) | |
639 # Use the /dev/null print_func to avoid terminal spew in WaitForRealCommit. | |
640 mirror = git_cache.Mirror(remote_url, print_func = lambda *args: None) | |
641 if mirror.exists(): | |
642 return mirror | |
643 return None | |
644 | |
631 def GetIsGitSvn(self): | 645 def GetIsGitSvn(self): |
632 """Return true if this repo looks like it's using git-svn.""" | 646 """Return true if this repo looks like it's using git-svn.""" |
633 if self.is_git_svn is None: | 647 if self.is_git_svn is None: |
634 if self.GetPendingRefPrefix(): | 648 if self.GetPendingRefPrefix(): |
635 # If PENDING_REF_PREFIX is set then it's a pure git repo no matter what. | 649 # If PENDING_REF_PREFIX is set then it's a pure git repo no matter what. |
636 self.is_git_svn = False | 650 self.is_git_svn = False |
637 else: | 651 else: |
638 # If you have any "svn-remote.*" config keys, we think you're using svn. | 652 # If you have any "svn-remote.*" config keys, we think you're using svn. |
639 self.is_git_svn = RunGitWithCode( | 653 self.is_git_svn = RunGitWithCode( |
640 ['config', '--local', '--get-regexp', r'^svn-remote\.'])[0] == 0 | 654 ['config', '--local', '--get-regexp', r'^svn-remote\.'])[0] == 0 |
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2858 ]) | 2872 ]) |
2859 else: | 2873 else: |
2860 RunGit(['commit', '-m', commit_desc.description]) | 2874 RunGit(['commit', '-m', commit_desc.description]) |
2861 if base_has_submodules: | 2875 if base_has_submodules: |
2862 cherry_pick_commit = RunGit(['rev-list', 'HEAD^!']).rstrip() | 2876 cherry_pick_commit = RunGit(['rev-list', 'HEAD^!']).rstrip() |
2863 RunGit(['branch', CHERRY_PICK_BRANCH, svn_head]) | 2877 RunGit(['branch', CHERRY_PICK_BRANCH, svn_head]) |
2864 RunGit(['checkout', CHERRY_PICK_BRANCH]) | 2878 RunGit(['checkout', CHERRY_PICK_BRANCH]) |
2865 RunGit(['cherry-pick', cherry_pick_commit]) | 2879 RunGit(['cherry-pick', cherry_pick_commit]) |
2866 if cmd == 'land': | 2880 if cmd == 'land': |
2867 remote, branch = cl.FetchUpstreamTuple(cl.GetBranch()) | 2881 remote, branch = cl.FetchUpstreamTuple(cl.GetBranch()) |
2882 mirror = settings.GetGitMirror(remote) | |
2883 pushurl = mirror.url if mirror else remote | |
2868 pending_prefix = settings.GetPendingRefPrefix() | 2884 pending_prefix = settings.GetPendingRefPrefix() |
2869 if not pending_prefix or branch.startswith(pending_prefix): | 2885 if not pending_prefix or branch.startswith(pending_prefix): |
2870 # If not using refs/pending/heads/* at all, or target ref is already set | 2886 # If not using refs/pending/heads/* at all, or target ref is already set |
2871 # to pending, then push to the target ref directly. | 2887 # to pending, then push to the target ref directly. |
2872 retcode, output = RunGitWithCode( | 2888 retcode, output = RunGitWithCode( |
2873 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) | 2889 ['push', '--porcelain', pushurl, 'HEAD:%s' % branch]) |
2874 pushed_to_pending = pending_prefix and branch.startswith(pending_prefix) | 2890 pushed_to_pending = pending_prefix and branch.startswith(pending_prefix) |
2875 else: | 2891 else: |
2876 # Cherry-pick the change on top of pending ref and then push it. | 2892 # Cherry-pick the change on top of pending ref and then push it. |
2877 assert branch.startswith('refs/'), branch | 2893 assert branch.startswith('refs/'), branch |
2878 assert pending_prefix[-1] == '/', pending_prefix | 2894 assert pending_prefix[-1] == '/', pending_prefix |
2879 pending_ref = pending_prefix + branch[len('refs/'):] | 2895 pending_ref = pending_prefix + branch[len('refs/'):] |
2880 retcode, output = PushToGitPending(remote, pending_ref, branch) | 2896 retcode, output = PushToGitPending(pushurl, pending_ref, branch) |
2881 pushed_to_pending = (retcode == 0) | 2897 pushed_to_pending = (retcode == 0) |
2882 if retcode == 0: | 2898 if retcode == 0: |
2883 revision = RunGit(['rev-parse', 'HEAD']).strip() | 2899 revision = RunGit(['rev-parse', 'HEAD']).strip() |
2884 else: | 2900 else: |
2885 # dcommit the merge branch. | 2901 # dcommit the merge branch. |
2886 cmd_args = [ | 2902 cmd_args = [ |
2887 'svn', 'dcommit', | 2903 'svn', 'dcommit', |
2888 '-C%s' % options.similarity, | 2904 '-C%s' % options.similarity, |
2889 '--no-rebase', '--rmdir', | 2905 '--no-rebase', '--rmdir', |
2890 ] | 2906 ] |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2958 | 2974 |
2959 return 1 if killed else 0 | 2975 return 1 if killed else 0 |
2960 | 2976 |
2961 | 2977 |
2962 def WaitForRealCommit(remote, pushed_commit, local_base_ref, real_ref): | 2978 def WaitForRealCommit(remote, pushed_commit, local_base_ref, real_ref): |
2963 print | 2979 print |
2964 print 'Waiting for commit to be landed on %s...' % real_ref | 2980 print 'Waiting for commit to be landed on %s...' % real_ref |
2965 print '(If you are impatient, you may Ctrl-C once without harm)' | 2981 print '(If you are impatient, you may Ctrl-C once without harm)' |
2966 target_tree = RunGit(['rev-parse', '%s:' % pushed_commit]).strip() | 2982 target_tree = RunGit(['rev-parse', '%s:' % pushed_commit]).strip() |
2967 current_rev = RunGit(['rev-parse', local_base_ref]).strip() | 2983 current_rev = RunGit(['rev-parse', local_base_ref]).strip() |
2984 mirror = settings.GetGitMirror(remote) | |
2968 | 2985 |
2969 loop = 0 | 2986 loop = 0 |
2970 while True: | 2987 while True: |
2971 sys.stdout.write('fetching (%d)... \r' % loop) | 2988 sys.stdout.write('fetching (%d)... \r' % loop) |
2972 sys.stdout.flush() | 2989 sys.stdout.flush() |
2973 loop += 1 | 2990 loop += 1 |
2974 | 2991 |
2992 if mirror: | |
2993 mirror.populate() | |
2975 RunGit(['retry', 'fetch', remote, real_ref], stderr=subprocess2.VOID) | 2994 RunGit(['retry', 'fetch', remote, real_ref], stderr=subprocess2.VOID) |
2976 to_rev = RunGit(['rev-parse', 'FETCH_HEAD']).strip() | 2995 to_rev = RunGit(['rev-parse', 'FETCH_HEAD']).strip() |
2977 commits = RunGit(['rev-list', '%s..%s' % (current_rev, to_rev)]) | 2996 commits = RunGit(['rev-list', '%s..%s' % (current_rev, to_rev)]) |
2978 for commit in commits.splitlines(): | 2997 for commit in commits.splitlines(): |
2979 if RunGit(['rev-parse', '%s:' % commit]).strip() == target_tree: | 2998 if RunGit(['rev-parse', '%s:' % commit]).strip() == target_tree: |
2980 print 'Found commit on %s' % real_ref | 2999 print 'Found commit on %s' % real_ref |
2981 return commit | 3000 return commit |
2982 | 3001 |
2983 current_rev = to_rev | 3002 current_rev = to_rev |
2984 | 3003 |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3964 if __name__ == '__main__': | 3983 if __name__ == '__main__': |
3965 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3984 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3966 # unit testing. | 3985 # unit testing. |
3967 fix_encoding.fix_encoding() | 3986 fix_encoding.fix_encoding() |
3968 colorama.init() | 3987 colorama.init() |
3969 try: | 3988 try: |
3970 sys.exit(main(sys.argv[1:])) | 3989 sys.exit(main(sys.argv[1:])) |
3971 except KeyboardInterrupt: | 3990 except KeyboardInterrupt: |
3972 sys.stderr.write('interrupted\n') | 3991 sys.stderr.write('interrupted\n') |
3973 sys.exit(1) | 3992 sys.exit(1) |
OLD | NEW |