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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 def remove_empty_branches(branch_tree): | 86 def remove_empty_branches(branch_tree): |
87 tag_set = git.tags() | 87 tag_set = git.tags() |
88 ensure_root_checkout = git.once(lambda: git.run('checkout', git.root())) | 88 ensure_root_checkout = git.once(lambda: git.run('checkout', git.root())) |
89 | 89 |
90 deletions = {} | 90 deletions = {} |
91 reparents = {} | 91 reparents = {} |
92 downstreams = collections.defaultdict(list) | 92 downstreams = collections.defaultdict(list) |
93 for branch, parent in git.topo_iter(branch_tree, top_down=False): | 93 for branch, parent in git.topo_iter(branch_tree, top_down=False): |
94 downstreams[parent].append(branch) | 94 downstreams[parent].append(branch) |
95 | 95 |
96 # If branch and parent have the same state, then branch has to be marked | 96 # If branch and parent have the same tree, then branch has to be marked |
97 # for deletion and its children and grand-children reparented to parent. | 97 # for deletion and its children and grand-children reparented to parent. |
98 if git.hash_one(branch) == git.hash_one(parent): | 98 if git.hash_one(branch+":") == git.hash_one(parent+":"): |
99 ensure_root_checkout() | 99 ensure_root_checkout() |
100 | 100 |
101 logging.debug('branch %s merged to %s', branch, parent) | 101 logging.debug('branch %s merged to %s', branch, parent) |
102 | 102 |
103 # Mark branch for deletion while remembering the ordering, then add all | 103 # Mark branch for deletion while remembering the ordering, then add all |
104 # its children as grand-children of its parent and record reparenting | 104 # its children as grand-children of its parent and record reparenting |
105 # information if necessary. | 105 # information if necessary. |
106 deletions[branch] = len(deletions) | 106 deletions[branch] = len(deletions) |
107 | 107 |
108 for down in downstreams[branch]: | 108 for down in downstreams[branch]: |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 return retcode | 320 return retcode |
321 | 321 |
322 | 322 |
323 if __name__ == '__main__': # pragma: no cover | 323 if __name__ == '__main__': # pragma: no cover |
324 try: | 324 try: |
325 sys.exit(main()) | 325 sys.exit(main()) |
326 except KeyboardInterrupt: | 326 except KeyboardInterrupt: |
327 sys.stderr.write('interrupted\n') | 327 sys.stderr.write('interrupted\n') |
328 sys.exit(1) | 328 sys.exit(1) |
OLD | NEW |