OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """ | 6 """ |
7 Tool to update all branches to have the latest changes from their upstreams. | 7 Tool to update all branches to have the latest changes from their upstreams. |
8 """ | 8 """ |
9 | 9 |
10 import argparse | 10 import argparse |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 out, err = git.run_with_stderr('fetch', *fetch_args) | 67 out, err = git.run_with_stderr('fetch', *fetch_args) |
68 for data, stream in zip((out, err), (sys.stdout, sys.stderr)): | 68 for data, stream in zip((out, err), (sys.stdout, sys.stderr)): |
69 if data: | 69 if data: |
70 print >> stream, data | 70 print >> stream, data |
71 | 71 |
72 | 72 |
73 def remove_empty_branches(branch_tree): | 73 def remove_empty_branches(branch_tree): |
74 tag_set = git.tags() | 74 tag_set = git.tags() |
75 ensure_root_checkout = git.once(lambda: git.run('checkout', git.root())) | 75 ensure_root_checkout = git.once(lambda: git.run('checkout', git.root())) |
76 | 76 |
| 77 deletions = set() |
77 downstreams = collections.defaultdict(list) | 78 downstreams = collections.defaultdict(list) |
78 for branch, parent in git.topo_iter(branch_tree, top_down=False): | 79 for branch, parent in git.topo_iter(branch_tree, top_down=False): |
79 downstreams[parent].append(branch) | 80 downstreams[parent].append(branch) |
80 | 81 |
81 if git.hash_one(branch) == git.hash_one(parent): | 82 if git.hash_one(branch) == git.hash_one(parent): |
82 ensure_root_checkout() | 83 ensure_root_checkout() |
83 | 84 |
84 logging.debug('branch %s merged to %s', branch, parent) | 85 logging.debug('branch %s merged to %s', branch, parent) |
85 | 86 |
86 for down in downstreams[branch]: | 87 for down in downstreams[branch]: |
| 88 if down in deletions: |
| 89 continue |
| 90 |
87 if parent in tag_set: | 91 if parent in tag_set: |
88 git.set_branch_config(down, 'remote', '.') | 92 git.set_branch_config(down, 'remote', '.') |
89 git.set_branch_config(down, 'merge', 'refs/tags/%s' % parent) | 93 git.set_branch_config(down, 'merge', 'refs/tags/%s' % parent) |
90 print ('Reparented %s to track %s [tag] (was tracking %s)' | 94 print ('Reparented %s to track %s [tag] (was tracking %s)' |
91 % (down, parent, branch)) | 95 % (down, parent, branch)) |
92 else: | 96 else: |
93 git.run('branch', '--set-upstream-to', parent, down) | 97 git.run('branch', '--set-upstream-to', parent, down) |
94 print ('Reparented %s to track %s (was tracking %s)' | 98 print ('Reparented %s to track %s (was tracking %s)' |
95 % (down, parent, branch)) | 99 % (down, parent, branch)) |
96 | 100 |
| 101 deletions.add(branch) |
97 print git.run('branch', '-d', branch) | 102 print git.run('branch', '-d', branch) |
98 | 103 |
99 | 104 |
100 def rebase_branch(branch, parent, start_hash): | 105 def rebase_branch(branch, parent, start_hash): |
101 logging.debug('considering %s(%s) -> %s(%s) : %s', | 106 logging.debug('considering %s(%s) -> %s(%s) : %s', |
102 branch, git.hash_one(branch), parent, git.hash_one(parent), | 107 branch, git.hash_one(branch), parent, git.hash_one(parent), |
103 start_hash) | 108 start_hash) |
104 | 109 |
105 # If parent has FROZEN commits, don't base branch on top of them. Instead, | 110 # If parent has FROZEN commits, don't base branch on top of them. Instead, |
106 # base branch on top of whatever commit is before them. | 111 # base branch on top of whatever commit is before them. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 % (return_branch, root_branch) | 244 % (return_branch, root_branch) |
240 ) | 245 ) |
241 git.run('checkout', root_branch) | 246 git.run('checkout', root_branch) |
242 git.del_config(STARTING_BRANCH_KEY) | 247 git.del_config(STARTING_BRANCH_KEY) |
243 | 248 |
244 return retcode | 249 return retcode |
245 | 250 |
246 | 251 |
247 if __name__ == '__main__': # pragma: no cover | 252 if __name__ == '__main__': # pragma: no cover |
248 sys.exit(main(sys.argv[1:])) | 253 sys.exit(main(sys.argv[1:])) |
OLD | NEW |