summaryrefslogtreecommitdiffstats
path: root/gitc_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitc_utils.py')
-rw-r--r--gitc_utils.py85
1 files changed, 74 insertions, 11 deletions
diff --git a/gitc_utils.py b/gitc_utils.py
index d082c8d7..04307a3c 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -15,6 +15,8 @@
15 15
16from __future__ import print_function 16from __future__ import print_function
17import os 17import os
18import platform
19import re
18import sys 20import sys
19import time 21import time
20 22
@@ -22,6 +24,7 @@ import git_command
22import git_config 24import git_config
23import wrapper 25import wrapper
24 26
27from manifest_xml import GitcManifest
25 28
26GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' 29GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
27NUM_BATCH_RETRIEVE_REVISIONID = 300 30NUM_BATCH_RETRIEVE_REVISIONID = 300
@@ -65,26 +68,86 @@ def _set_project_revisions(projects):
65 sys.exit(1) 68 sys.exit(1)
66 proj.revisionExpr = gitcmd.stdout.split('\t')[0] 69 proj.revisionExpr = gitcmd.stdout.split('\t')[0]
67 70
68def generate_gitc_manifest(client_dir, manifest, projects=None): 71def _manifest_groups(manifest):
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
85def generate_gitc_manifest(repodir, client_name, gitc_manifest, repo_manifest_file, paths=None):
69 """Generate a manifest for shafsd to use for this GITC client. 86 """Generate a manifest for shafsd to use for this GITC client.
70 87
71 @param client_dir: GITC client directory to install the .manifest file in. 88 @param repodir: The repo directory
72 @param manifest: XmlManifest object representing the repo manifest. 89 @param client_name: The gitc client name
73 @param projects: List of projects we want to update, this must be a sublist 90 @param gitc_manifest: Current gitc manifest, or None if there isn't one yet
74 of manifest.projects to work properly. If not provided, 91 @param repo_manifest_file: The file used by the main repo manifest
75 manifest.projects is used. 92 @param paths: List of project paths we want to update.
76 """ 93 """
94 manifest = GitcManifest(repodir, client_name)
95 manifest.Override(repo_manifest_file)
96
77 print('Generating GITC Manifest by fetching revision SHAs for each ' 97 print('Generating GITC Manifest by fetching revision SHAs for each '
78 'project.') 98 'project.')
79 if projects is None: 99 if paths is None:
80 projects = manifest.projects 100 paths = manifest.paths.keys()
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
81 index = 0 130 index = 0
82 while index < len(projects): 131 while index < len(projects):
83 _set_project_revisions( 132 _set_project_revisions(
84 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) 133 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
85 index += NUM_BATCH_RETRIEVE_REVISIONID 134 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
86 # Save the manifest. 149 # Save the manifest.
87 save_manifest(manifest, client_dir=client_dir) 150 save_manifest(manifest)
88 151
89def save_manifest(manifest, client_dir=None): 152def save_manifest(manifest, client_dir=None):
90 """Save the manifest file in the client_dir. 153 """Save the manifest file in the client_dir.
@@ -95,7 +158,7 @@ def save_manifest(manifest, client_dir=None):
95 if not client_dir: 158 if not client_dir:
96 client_dir = manifest.gitc_client_dir 159 client_dir = manifest.gitc_client_dir
97 with open(os.path.join(client_dir, '.manifest'), 'w') as f: 160 with open(os.path.join(client_dir, '.manifest'), 'w') as f:
98 manifest.Save(f) 161 manifest.Save(f, groups=_manifest_groups(manifest))
99 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. 162 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
100 # Give the GITC filesystem time to register the manifest changes. 163 # Give the GITC filesystem time to register the manifest changes.
101 time.sleep(3) \ No newline at end of file 164 time.sleep(3)