diff options
| author | Dan Willemsen <dwillemsen@google.com> | 2015-09-09 21:44:11 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-09-09 21:44:11 +0000 |
| commit | 5cc384034d144c339d2e5822c36c5ca4529ac487 (patch) | |
| tree | e2a5cb35a8ea85984c7e4f92bac9fffd4d1e617c /gitc_utils.py | |
| parent | c32ba1961e3451101ce94a26f83cf56681ff6414 (diff) | |
| parent | 037552333182497e9e38bff984de44df0f93e54b (diff) | |
| download | git-repo-5cc384034d144c339d2e5822c36c5ca4529ac487.tar.gz | |
Merge "Revert "GITC: Always update the gitc manifest from the repo manifest""v1.12.30.1
Diffstat (limited to 'gitc_utils.py')
| -rw-r--r-- | gitc_utils.py | 85 |
1 files changed, 11 insertions, 74 deletions
diff --git a/gitc_utils.py b/gitc_utils.py index 04307a3c..d082c8d7 100644 --- a/gitc_utils.py +++ b/gitc_utils.py | |||
| @@ -15,8 +15,6 @@ | |||
| 15 | 15 | ||
| 16 | from __future__ import print_function | 16 | from __future__ import print_function |
| 17 | import os | 17 | import os |
| 18 | import platform | ||
| 19 | import re | ||
| 20 | import sys | 18 | import sys |
| 21 | import time | 19 | import time |
| 22 | 20 | ||
| @@ -24,7 +22,6 @@ import git_command | |||
| 24 | import git_config | 22 | import git_config |
| 25 | import wrapper | 23 | import wrapper |
| 26 | 24 | ||
| 27 | from manifest_xml import GitcManifest | ||
| 28 | 25 | ||
| 29 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' | 26 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
| 30 | NUM_BATCH_RETRIEVE_REVISIONID = 300 | 27 | NUM_BATCH_RETRIEVE_REVISIONID = 300 |
| @@ -68,86 +65,26 @@ def _set_project_revisions(projects): | |||
| 68 | sys.exit(1) | 65 | sys.exit(1) |
| 69 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] | 66 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] |
| 70 | 67 | ||
| 71 | def _manifest_groups(manifest): | 68 | def generate_gitc_manifest(client_dir, manifest, projects=None): |
| 72 | """Returns the manifest group string that should be synced | ||
| 73 | |||
| 74 | This is the same logic used by Command.GetProjects(), which is used during | ||
| 75 | repo sync | ||
| 76 | |||
| 77 | @param manifest: The XmlManifest object | ||
| 78 | """ | ||
| 79 | mp = manifest.manifestProject | ||
| 80 | groups = mp.config.GetString('manifest.groups') | ||
| 81 | if not groups: | ||
| 82 | groups = 'default,platform-' + platform.system().lower() | ||
| 83 | return groups | ||
| 84 | |||
| 85 | def generate_gitc_manifest(repodir, client_name, gitc_manifest, repo_manifest_file, paths=None): | ||
| 86 | """Generate a manifest for shafsd to use for this GITC client. | 69 | """Generate a manifest for shafsd to use for this GITC client. |
| 87 | 70 | ||
| 88 | @param repodir: The repo directory | 71 | @param client_dir: GITC client directory to install the .manifest file in. |
| 89 | @param client_name: The gitc client name | 72 | @param manifest: XmlManifest object representing the repo manifest. |
| 90 | @param gitc_manifest: Current gitc manifest, or None if there isn't one yet | 73 | @param projects: List of projects we want to update, this must be a sublist |
| 91 | @param repo_manifest_file: The file used by the main repo manifest | 74 | of manifest.projects to work properly. If not provided, |
| 92 | @param paths: List of project paths we want to update. | 75 | manifest.projects is used. |
| 93 | """ | 76 | """ |
| 94 | manifest = GitcManifest(repodir, client_name) | ||
| 95 | manifest.Override(repo_manifest_file) | ||
| 96 | |||
| 97 | print('Generating GITC Manifest by fetching revision SHAs for each ' | 77 | print('Generating GITC Manifest by fetching revision SHAs for each ' |
| 98 | 'project.') | 78 | 'project.') |
| 99 | if paths is None: | 79 | if projects is None: |
| 100 | paths = manifest.paths.keys() | 80 | projects = manifest.projects |
| 101 | |||
| 102 | groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x] | ||
| 103 | |||
| 104 | # Convert the paths to projects, and filter them to the matched groups. | ||
| 105 | projects = [manifest.paths[p] for p in paths] | ||
| 106 | projects = [p for p in projects if p.MatchesGroups(groups)] | ||
| 107 | |||
| 108 | if gitc_manifest is not None: | ||
| 109 | for path, proj in manifest.paths.iteritems(): | ||
| 110 | if not proj.MatchesGroups(groups): | ||
| 111 | continue | ||
| 112 | |||
| 113 | if not proj.upstream and not git_config.IsId(proj.revisionExpr): | ||
| 114 | proj.upstream = proj.revisionExpr | ||
| 115 | |||
| 116 | if not path in gitc_manifest.paths: | ||
| 117 | # Any new projects need their first revision, even if we weren't asked | ||
| 118 | # for them. | ||
| 119 | projects.append(proj) | ||
| 120 | elif not path in paths: | ||
| 121 | # And copy revisions from the previous manifest if we're not updating | ||
| 122 | # them now. | ||
| 123 | gitc_proj = gitc_manifest.paths[path] | ||
| 124 | if gitc_proj.old_revision: | ||
| 125 | proj.revisionExpr = None | ||
| 126 | proj.old_revision = gitc_proj.old_revision | ||
| 127 | else: | ||
| 128 | proj.revisionExpr = gitc_proj.revisionExpr | ||
| 129 | |||
| 130 | index = 0 | 81 | index = 0 |
| 131 | while index < len(projects): | 82 | while index < len(projects): |
| 132 | _set_project_revisions( | 83 | _set_project_revisions( |
| 133 | projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) | 84 | projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) |
| 134 | index += NUM_BATCH_RETRIEVE_REVISIONID | 85 | index += NUM_BATCH_RETRIEVE_REVISIONID |
| 135 | |||
| 136 | if gitc_manifest is not None: | ||
| 137 | for path, proj in gitc_manifest.paths.iteritems(): | ||
| 138 | if proj.old_revision and path in paths: | ||
| 139 | # If we updated a project that has been started, keep the old-revision | ||
| 140 | # updated. | ||
| 141 | repo_proj = manifest.paths[path] | ||
| 142 | repo_proj.old_revision = repo_proj.revisionExpr | ||
| 143 | repo_proj.revisionExpr = None | ||
| 144 | |||
| 145 | # Convert URLs from relative to absolute. | ||
| 146 | for name, remote in manifest.remotes.iteritems(): | ||
| 147 | remote.fetchUrl = remote.resolvedFetchUrl | ||
| 148 | |||
| 149 | # Save the manifest. | 86 | # Save the manifest. |
| 150 | save_manifest(manifest) | 87 | save_manifest(manifest, client_dir=client_dir) |
| 151 | 88 | ||
| 152 | def save_manifest(manifest, client_dir=None): | 89 | def save_manifest(manifest, client_dir=None): |
| 153 | """Save the manifest file in the client_dir. | 90 | """Save the manifest file in the client_dir. |
| @@ -158,7 +95,7 @@ def save_manifest(manifest, client_dir=None): | |||
| 158 | if not client_dir: | 95 | if not client_dir: |
| 159 | client_dir = manifest.gitc_client_dir | 96 | client_dir = manifest.gitc_client_dir |
| 160 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: | 97 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: |
| 161 | manifest.Save(f, groups=_manifest_groups(manifest)) | 98 | manifest.Save(f) |
| 162 | # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. | 99 | # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. |
| 163 | # Give the GITC filesystem time to register the manifest changes. | 100 | # Give the GITC filesystem time to register the manifest changes. |
| 164 | time.sleep(3) | 101 | time.sleep(3) \ No newline at end of file |
