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 |
11 from multiprocessing.pool import ThreadPool | 11 from multiprocessing.pool import ThreadPool |
12 import base64 | 12 import base64 |
13 import collections | 13 import collections |
14 import glob | 14 import glob |
15 import httplib | 15 import httplib |
16 import json | 16 import json |
17 import logging | 17 import logging |
18 import multiprocessing | |
18 import optparse | 19 import optparse |
19 import os | 20 import os |
20 import Queue | 21 import Queue |
21 import re | 22 import re |
22 import stat | 23 import stat |
23 import sys | 24 import sys |
24 import tempfile | 25 import tempfile |
25 import textwrap | 26 import textwrap |
26 import time | 27 import time |
27 import traceback | 28 import traceback |
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 cl = Changelist(branchref=branch, auth_config=auth_config) | 1691 cl = Changelist(branchref=branch, auth_config=auth_config) |
1691 url = cl.GetIssueURL() | 1692 url = cl.GetIssueURL() |
1692 status = cl.GetStatus() | 1693 status = cl.GetStatus() |
1693 | 1694 |
1694 if url and (not status or status == 'error'): | 1695 if url and (not status or status == 'error'): |
1695 # The issue probably doesn't exist anymore. | 1696 # The issue probably doesn't exist anymore. |
1696 url += ' (broken)' | 1697 url += ' (broken)' |
1697 | 1698 |
1698 return (branch, url, status) | 1699 return (branch, url, status) |
1699 | 1700 |
1700 def get_cl_statuses( | 1701 def get_cl_statuses( |
Matt Giuca
2016/03/31 03:27:20
Is this only used by git-map-branches? I'm a bit c
calamity
2016/04/01 03:42:24
It's just map-branches.
| |
1701 branches, fine_grained, max_processes=None, auth_config=None): | 1702 branches, fine_grained, max_processes=None, auth_config=None): |
1702 """Returns a blocking iterable of (branch, issue, color) for given branches. | 1703 """Returns a blocking iterable of (branch, issue, color) for given branches. |
Matt Giuca
2016/03/31 03:27:20
Is 'color' a string containing a code like "waitin
calamity
2016/04/01 03:42:24
Yeah, it's actually a status. It's documented in G
| |
1703 | 1704 |
1704 If fine_grained is true, this will fetch CL statuses from the server. | 1705 If fine_grained is true, this will fetch CL statuses from the server. |
1705 Otherwise, simply indicate if there's a matching url for the given branches. | 1706 Otherwise, simply indicate if there's a matching url for the given branches. |
1706 | 1707 |
1707 If max_processes is specified, it is used as the maximum number of processes | 1708 If max_processes is specified, it is used as the maximum number of processes |
1708 to spawn to fetch CL status from the server. Otherwise 1 process per branch is | 1709 to spawn to fetch CL status from the server. Otherwise 1 process per branch is |
1709 spawned. | 1710 spawned. |
1710 """ | 1711 """ |
1711 # Silence upload.py otherwise it becomes unwieldly. | 1712 # Silence upload.py otherwise it becomes unwieldly. |
1712 upload.verbosity = 0 | 1713 upload.verbosity = 0 |
1713 | 1714 |
1714 if fine_grained: | 1715 if fine_grained: |
1715 # Process one branch synchronously to work through authentication, then | 1716 # Process one branch synchronously to work through authentication, then |
1716 # spawn processes to process all the other branches in parallel. | 1717 # spawn processes to process all the other branches in parallel. |
1717 if branches: | 1718 if branches: |
1718 fetch = lambda branch: fetch_cl_status(branch, auth_config=auth_config) | 1719 def fetch(branch): |
Matt Giuca
2016/03/31 03:27:20
This should be at the top of the function (style).
calamity
2016/04/01 03:42:24
I miss the lambda already.
| |
1720 if not branch: | |
1721 return None | |
Matt Giuca
2016/03/31 03:27:20
Blank line after return.
calamity
2016/04/01 03:42:24
Done.
| |
1722 return fetch_cl_status(branch, auth_config=auth_config) | |
1723 | |
1719 yield fetch(branches[0]) | 1724 yield fetch(branches[0]) |
1720 | 1725 |
1721 branches_to_fetch = branches[1:] | 1726 branches_to_fetch = branches[1:] |
1722 pool = ThreadPool( | 1727 pool = ThreadPool( |
1723 min(max_processes, len(branches_to_fetch)) | 1728 min(max_processes, len(branches_to_fetch)) |
1724 if max_processes is not None | 1729 if max_processes is not None |
1725 else len(branches_to_fetch)) | 1730 else len(branches_to_fetch)) |
1726 for x in pool.imap_unordered(fetch, branches_to_fetch): | 1731 x = pool.imap_unordered(fetch, branches_to_fetch).__iter__() |
1727 yield x | 1732 |
1733 fetched_branches = set() | |
1734 while True: | |
1735 try: | |
1736 row = x.next(timeout=5) | |
1737 fetched_branches.add(row[0]) | |
1738 yield row | |
1739 except multiprocessing.TimeoutError: | |
1740 break | |
1741 | |
1742 # Add any branches that failed to fetch. | |
1743 for b in set(branches_to_fetch) - fetched_branches: | |
1744 cl = Changelist(branchref=b, auth_config=auth_config) | |
1745 yield (b, cl.GetIssueURL() if b else None, 'error') | |
1746 | |
1728 else: | 1747 else: |
1729 # Do not use GetApprovingReviewers(), since it requires an HTTP request. | 1748 # Do not use GetApprovingReviewers(), since it requires an HTTP request. |
1730 for b in branches: | 1749 for b in branches: |
1731 cl = Changelist(branchref=b, auth_config=auth_config) | 1750 cl = Changelist(branchref=b, auth_config=auth_config) |
1732 url = cl.GetIssueURL() | 1751 url = cl.GetIssueURL() if b else None |
1733 yield (b, url, 'waiting' if url else 'error') | 1752 yield (b, url, 'waiting' if url else 'error') |
1734 | 1753 |
1735 | 1754 |
1736 def upload_branch_deps(cl, args): | 1755 def upload_branch_deps(cl, args): |
1737 """Uploads CLs of local branches that are dependents of the current branch. | 1756 """Uploads CLs of local branches that are dependents of the current branch. |
1738 | 1757 |
1739 If the local branch dependency tree looks like: | 1758 If the local branch dependency tree looks like: |
1740 test1 -> test2.1 -> test3.1 | 1759 test1 -> test2.1 -> test3.1 |
1741 -> test3.2 | 1760 -> test3.2 |
1742 -> test2.2 -> test3.3 | 1761 -> test2.2 -> test3.3 |
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4007 if __name__ == '__main__': | 4026 if __name__ == '__main__': |
4008 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4027 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4009 # unit testing. | 4028 # unit testing. |
4010 fix_encoding.fix_encoding() | 4029 fix_encoding.fix_encoding() |
4011 colorama.init() | 4030 colorama.init() |
4012 try: | 4031 try: |
4013 sys.exit(main(sys.argv[1:])) | 4032 sys.exit(main(sys.argv[1:])) |
4014 except KeyboardInterrupt: | 4033 except KeyboardInterrupt: |
4015 sys.stderr.write('interrupted\n') | 4034 sys.stderr.write('interrupted\n') |
4016 sys.exit(1) | 4035 sys.exit(1) |
OLD | NEW |