diff options
Diffstat (limited to 'gitc_utils.py')
-rw-r--r-- | gitc_utils.py | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/gitc_utils.py b/gitc_utils.py index 89cfbeca..a2786c9f 100644 --- a/gitc_utils.py +++ b/gitc_utils.py | |||
@@ -13,6 +13,7 @@ | |||
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import os | 15 | import os |
16 | import multiprocessing | ||
16 | import platform | 17 | import platform |
17 | import re | 18 | import re |
18 | import sys | 19 | import sys |
@@ -35,6 +36,15 @@ def parse_clientdir(gitc_fs_path): | |||
35 | return wrapper.Wrapper().gitc_parse_clientdir(gitc_fs_path) | 36 | return wrapper.Wrapper().gitc_parse_clientdir(gitc_fs_path) |
36 | 37 | ||
37 | 38 | ||
39 | def _get_project_revision(args): | ||
40 | """Worker for _set_project_revisions to lookup one project remote.""" | ||
41 | (i, url, expr) = args | ||
42 | gitcmd = git_command.GitCommand( | ||
43 | None, ['ls-remote', url, expr], capture_stdout=True, cwd='/tmp') | ||
44 | rc = gitcmd.Wait() | ||
45 | return (i, rc, gitcmd.stdout.split('\t', 1)[0]) | ||
46 | |||
47 | |||
38 | def _set_project_revisions(projects): | 48 | def _set_project_revisions(projects): |
39 | """Sets the revisionExpr for a list of projects. | 49 | """Sets the revisionExpr for a list of projects. |
40 | 50 | ||
@@ -47,22 +57,24 @@ def _set_project_revisions(projects): | |||
47 | """ | 57 | """ |
48 | # Retrieve the commit id for each project based off of it's current | 58 | # Retrieve the commit id for each project based off of it's current |
49 | # revisionExpr and it is not already a commit id. | 59 | # revisionExpr and it is not already a commit id. |
50 | project_gitcmds = [( | 60 | with multiprocessing.Pool(NUM_BATCH_RETRIEVE_REVISIONID) as pool: |
51 | project, git_command.GitCommand(None, | 61 | results_iter = pool.imap_unordered( |
52 | ['ls-remote', | 62 | _get_project_revision, |
53 | project.remote.url, | 63 | ((i, project.remote.url, project.revisionExpr) |
54 | project.revisionExpr], | 64 | for i, project in enumerate(projects) |
55 | capture_stdout=True, cwd='/tmp')) | 65 | if not git_config.IsId(project.revisionExpr)), |
56 | for project in projects if not git_config.IsId(project.revisionExpr)] | 66 | chunksize=8) |
57 | for proj, gitcmd in project_gitcmds: | 67 | for (i, rc, revisionExpr) in results_iter: |
58 | if gitcmd.Wait(): | 68 | project = projects[i] |
59 | print('FATAL: Failed to retrieve revisionExpr for %s' % proj) | 69 | if rc: |
60 | sys.exit(1) | 70 | print('FATAL: Failed to retrieve revisionExpr for %s' % project.name) |
61 | revisionExpr = gitcmd.stdout.split('\t')[0] | 71 | pool.terminate() |
62 | if not revisionExpr: | 72 | sys.exit(1) |
63 | raise ManifestParseError('Invalid SHA-1 revision project %s (%s)' % | 73 | if not revisionExpr: |
64 | (proj.remote.url, proj.revisionExpr)) | 74 | pool.terminate() |
65 | proj.revisionExpr = revisionExpr | 75 | raise ManifestParseError('Invalid SHA-1 revision project %s (%s)' % |
76 | (project.remote.url, project.revisionExpr)) | ||
77 | project.revisionExpr = revisionExpr | ||
66 | 78 | ||
67 | 79 | ||
68 | def _manifest_groups(manifest): | 80 | def _manifest_groups(manifest): |
@@ -123,11 +135,7 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): | |||
123 | else: | 135 | else: |
124 | proj.revisionExpr = gitc_proj.revisionExpr | 136 | proj.revisionExpr = gitc_proj.revisionExpr |
125 | 137 | ||
126 | index = 0 | 138 | _set_project_revisions(projects) |
127 | while index < len(projects): | ||
128 | _set_project_revisions( | ||
129 | projects[index:(index + NUM_BATCH_RETRIEVE_REVISIONID)]) | ||
130 | index += NUM_BATCH_RETRIEVE_REVISIONID | ||
131 | 139 | ||
132 | if gitc_manifest is not None: | 140 | if gitc_manifest is not None: |
133 | for path, proj in gitc_manifest.paths.items(): | 141 | for path, proj in gitc_manifest.paths.items(): |