mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Revert "GITC: Always update the gitc manifest from the repo manifest"
This reverts commit 250303b437
.
Change-Id: I1fd8af20f802553151aacb953c913f3305ca6057
This commit is contained in:
parent
250303b437
commit
0375523331
@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -24,7 +22,6 @@ import git_command
|
|||||||
import git_config
|
import git_config
|
||||||
import wrapper
|
import wrapper
|
||||||
|
|
||||||
from manifest_xml import GitcManifest
|
|
||||||
|
|
||||||
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
||||||
NUM_BATCH_RETRIEVE_REVISIONID = 300
|
NUM_BATCH_RETRIEVE_REVISIONID = 300
|
||||||
@ -68,86 +65,26 @@ def _set_project_revisions(projects):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
proj.revisionExpr = gitcmd.stdout.split('\t')[0]
|
proj.revisionExpr = gitcmd.stdout.split('\t')[0]
|
||||||
|
|
||||||
def _manifest_groups(manifest):
|
def generate_gitc_manifest(client_dir, manifest, projects=None):
|
||||||
"""Returns the manifest group string that should be synced
|
|
||||||
|
|
||||||
This is the same logic used by Command.GetProjects(), which is used during
|
|
||||||
repo sync
|
|
||||||
|
|
||||||
@param manifest: The XmlManifest object
|
|
||||||
"""
|
|
||||||
mp = manifest.manifestProject
|
|
||||||
groups = mp.config.GetString('manifest.groups')
|
|
||||||
if not groups:
|
|
||||||
groups = 'default,platform-' + platform.system().lower()
|
|
||||||
return groups
|
|
||||||
|
|
||||||
def generate_gitc_manifest(repodir, client_name, gitc_manifest, repo_manifest_file, paths=None):
|
|
||||||
"""Generate a manifest for shafsd to use for this GITC client.
|
"""Generate a manifest for shafsd to use for this GITC client.
|
||||||
|
|
||||||
@param repodir: The repo directory
|
@param client_dir: GITC client directory to install the .manifest file in.
|
||||||
@param client_name: The gitc client name
|
@param manifest: XmlManifest object representing the repo manifest.
|
||||||
@param gitc_manifest: Current gitc manifest, or None if there isn't one yet
|
@param projects: List of projects we want to update, this must be a sublist
|
||||||
@param repo_manifest_file: The file used by the main repo manifest
|
of manifest.projects to work properly. If not provided,
|
||||||
@param paths: List of project paths we want to update.
|
manifest.projects is used.
|
||||||
"""
|
"""
|
||||||
manifest = GitcManifest(repodir, client_name)
|
|
||||||
manifest.Override(repo_manifest_file)
|
|
||||||
|
|
||||||
print('Generating GITC Manifest by fetching revision SHAs for each '
|
print('Generating GITC Manifest by fetching revision SHAs for each '
|
||||||
'project.')
|
'project.')
|
||||||
if paths is None:
|
if projects is None:
|
||||||
paths = manifest.paths.keys()
|
projects = manifest.projects
|
||||||
|
|
||||||
groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
|
|
||||||
|
|
||||||
# Convert the paths to projects, and filter them to the matched groups.
|
|
||||||
projects = [manifest.paths[p] for p in paths]
|
|
||||||
projects = [p for p in projects if p.MatchesGroups(groups)]
|
|
||||||
|
|
||||||
if gitc_manifest is not None:
|
|
||||||
for path, proj in manifest.paths.iteritems():
|
|
||||||
if not proj.MatchesGroups(groups):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not proj.upstream and not git_config.IsId(proj.revisionExpr):
|
|
||||||
proj.upstream = proj.revisionExpr
|
|
||||||
|
|
||||||
if not path in gitc_manifest.paths:
|
|
||||||
# Any new projects need their first revision, even if we weren't asked
|
|
||||||
# for them.
|
|
||||||
projects.append(proj)
|
|
||||||
elif not path in paths:
|
|
||||||
# And copy revisions from the previous manifest if we're not updating
|
|
||||||
# them now.
|
|
||||||
gitc_proj = gitc_manifest.paths[path]
|
|
||||||
if gitc_proj.old_revision:
|
|
||||||
proj.revisionExpr = None
|
|
||||||
proj.old_revision = gitc_proj.old_revision
|
|
||||||
else:
|
|
||||||
proj.revisionExpr = gitc_proj.revisionExpr
|
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
while index < len(projects):
|
while index < len(projects):
|
||||||
_set_project_revisions(
|
_set_project_revisions(
|
||||||
projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
|
projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
|
||||||
index += NUM_BATCH_RETRIEVE_REVISIONID
|
index += NUM_BATCH_RETRIEVE_REVISIONID
|
||||||
|
|
||||||
if gitc_manifest is not None:
|
|
||||||
for path, proj in gitc_manifest.paths.iteritems():
|
|
||||||
if proj.old_revision and path in paths:
|
|
||||||
# If we updated a project that has been started, keep the old-revision
|
|
||||||
# updated.
|
|
||||||
repo_proj = manifest.paths[path]
|
|
||||||
repo_proj.old_revision = repo_proj.revisionExpr
|
|
||||||
repo_proj.revisionExpr = None
|
|
||||||
|
|
||||||
# Convert URLs from relative to absolute.
|
|
||||||
for name, remote in manifest.remotes.iteritems():
|
|
||||||
remote.fetchUrl = remote.resolvedFetchUrl
|
|
||||||
|
|
||||||
# Save the manifest.
|
# Save the manifest.
|
||||||
save_manifest(manifest)
|
save_manifest(manifest, client_dir=client_dir)
|
||||||
|
|
||||||
def save_manifest(manifest, client_dir=None):
|
def save_manifest(manifest, client_dir=None):
|
||||||
"""Save the manifest file in the client_dir.
|
"""Save the manifest file in the client_dir.
|
||||||
@ -158,7 +95,7 @@ def save_manifest(manifest, client_dir=None):
|
|||||||
if not client_dir:
|
if not client_dir:
|
||||||
client_dir = manifest.gitc_client_dir
|
client_dir = manifest.gitc_client_dir
|
||||||
with open(os.path.join(client_dir, '.manifest'), 'w') as f:
|
with open(os.path.join(client_dir, '.manifest'), 'w') as f:
|
||||||
manifest.Save(f, groups=_manifest_groups(manifest))
|
manifest.Save(f)
|
||||||
# TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
|
# TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
|
||||||
# Give the GITC filesystem time to register the manifest changes.
|
# Give the GITC filesystem time to register the manifest changes.
|
||||||
time.sleep(3)
|
time.sleep(3)
|
@ -167,12 +167,11 @@ class XmlManifest(object):
|
|||||||
def _ParseGroups(self, groups):
|
def _ParseGroups(self, groups):
|
||||||
return [x for x in re.split(r'[,\s]+', groups) if x]
|
return [x for x in re.split(r'[,\s]+', groups) if x]
|
||||||
|
|
||||||
def Save(self, fd, peg_rev=False, peg_rev_upstream=True, groups=None):
|
def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
||||||
"""Write the current manifest out to the given file descriptor.
|
"""Write the current manifest out to the given file descriptor.
|
||||||
"""
|
"""
|
||||||
mp = self.manifestProject
|
mp = self.manifestProject
|
||||||
|
|
||||||
if groups is None:
|
|
||||||
groups = mp.config.GetString('manifest.groups')
|
groups = mp.config.GetString('manifest.groups')
|
||||||
if groups:
|
if groups:
|
||||||
groups = self._ParseGroups(groups)
|
groups = self._ParseGroups(groups)
|
||||||
|
@ -68,13 +68,15 @@ use for this GITC client.
|
|||||||
os.mkdir(self.client_dir)
|
os.mkdir(self.client_dir)
|
||||||
super(GitcInit, self).Execute(opt, args)
|
super(GitcInit, self).Execute(opt, args)
|
||||||
|
|
||||||
manifest_file = self.manifest.manifestFile
|
for name, remote in self.manifest.remotes.iteritems():
|
||||||
|
remote.fetchUrl = remote.resolvedFetchUrl
|
||||||
|
|
||||||
if opt.manifest_file:
|
if opt.manifest_file:
|
||||||
if not os.path.exists(opt.manifest_file):
|
if not os.path.exists(opt.manifest_file):
|
||||||
print('fatal: Specified manifest file %s does not exist.' %
|
print('fatal: Specified manifest file %s does not exist.' %
|
||||||
opt.manifest_file)
|
opt.manifest_file)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
manifest_file = opt.manifest_file
|
self.manifest.Override(opt.manifest_file)
|
||||||
gitc_utils.generate_gitc_manifest(self.repodir, opt.gitc_client, None, manifest_file)
|
gitc_utils.generate_gitc_manifest(self.client_dir, self.manifest)
|
||||||
print('Please run `cd %s` to view your GITC client.' %
|
print('Please run `cd %s` to view your GITC client.' %
|
||||||
os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client))
|
os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client))
|
||||||
|
@ -57,6 +57,7 @@ revision specified in the manifest.
|
|||||||
print("error: at least one project must be specified", file=sys.stderr)
|
print("error: at least one project must be specified", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
proj_name_to_gitc_proj_dict = {}
|
||||||
if self.gitc_manifest:
|
if self.gitc_manifest:
|
||||||
all_projects = self.GetProjects(projects, manifest=self.gitc_manifest,
|
all_projects = self.GetProjects(projects, manifest=self.gitc_manifest,
|
||||||
missing_ok=True)
|
missing_ok=True)
|
||||||
@ -66,6 +67,7 @@ revision specified in the manifest.
|
|||||||
else:
|
else:
|
||||||
project.already_synced = False
|
project.already_synced = False
|
||||||
project.old_revision = project.revisionExpr
|
project.old_revision = project.revisionExpr
|
||||||
|
proj_name_to_gitc_proj_dict[project.name] = project
|
||||||
project.revisionExpr = None
|
project.revisionExpr = None
|
||||||
# Save the GITC manifest.
|
# Save the GITC manifest.
|
||||||
gitc_utils.save_manifest(self.gitc_manifest)
|
gitc_utils.save_manifest(self.gitc_manifest)
|
||||||
@ -75,10 +77,9 @@ revision specified in the manifest.
|
|||||||
pm = Progress('Starting %s' % nb, len(all_projects))
|
pm = Progress('Starting %s' % nb, len(all_projects))
|
||||||
for project in all_projects:
|
for project in all_projects:
|
||||||
pm.update()
|
pm.update()
|
||||||
|
|
||||||
if self.gitc_manifest:
|
if self.gitc_manifest:
|
||||||
gitc_project = self.gitc_manifest.paths[project.relpath]
|
gitc_project = proj_name_to_gitc_proj_dict[project.name]
|
||||||
# Sync projects that have not been opened.
|
# Sync projects that have already been opened.
|
||||||
if not gitc_project.already_synced:
|
if not gitc_project.already_synced:
|
||||||
proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir,
|
proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir,
|
||||||
project.relpath)
|
project.relpath)
|
||||||
@ -88,7 +89,7 @@ revision specified in the manifest.
|
|||||||
project.Sync_NetworkHalf()
|
project.Sync_NetworkHalf()
|
||||||
sync_buf = SyncBuffer(self.manifest.manifestProject.config)
|
sync_buf = SyncBuffer(self.manifest.manifestProject.config)
|
||||||
project.Sync_LocalHalf(sync_buf)
|
project.Sync_LocalHalf(sync_buf)
|
||||||
project.revisionId = gitc_project.old_revision
|
project.revisionExpr = gitc_project.old_revision
|
||||||
|
|
||||||
# If the current revision is a specific SHA1 then we can't push back
|
# If the current revision is a specific SHA1 then we can't push back
|
||||||
# to it; so substitute with dest_branch if defined, or with manifest
|
# to it; so substitute with dest_branch if defined, or with manifest
|
||||||
@ -99,7 +100,6 @@ revision specified in the manifest.
|
|||||||
branch_merge = project.dest_branch
|
branch_merge = project.dest_branch
|
||||||
else:
|
else:
|
||||||
branch_merge = self.manifest.default.revisionExpr
|
branch_merge = self.manifest.default.revisionExpr
|
||||||
|
|
||||||
if not project.StartBranch(nb, branch_merge=branch_merge):
|
if not project.StartBranch(nb, branch_merge=branch_merge):
|
||||||
err.append(project)
|
err.append(project)
|
||||||
pm.end()
|
pm.end()
|
||||||
|
@ -670,36 +670,32 @@ later is required to fix a server side protocol bug.
|
|||||||
if opt.jobs is None:
|
if opt.jobs is None:
|
||||||
self.jobs = self.manifest.default.sync_j
|
self.jobs = self.manifest.default.sync_j
|
||||||
|
|
||||||
|
# TODO (sbasi) - Add support for manifest changes, aka projects
|
||||||
|
# have been added or deleted from the manifest.
|
||||||
if self.gitc_manifest:
|
if self.gitc_manifest:
|
||||||
gitc_manifest_projects = self.GetProjects(args,
|
gitc_manifest_projects = self.GetProjects(args,
|
||||||
|
manifest=self.gitc_manifest,
|
||||||
missing_ok=True)
|
missing_ok=True)
|
||||||
gitc_projects = []
|
gitc_projects = []
|
||||||
opened_projects = []
|
opened_projects = []
|
||||||
for project in gitc_manifest_projects:
|
for project in gitc_manifest_projects:
|
||||||
if project.relpath in self.gitc_manifest.paths and \
|
if not project.old_revision:
|
||||||
self.gitc_manifest.paths[project.relpath].old_revision:
|
gitc_projects.append(project)
|
||||||
opened_projects.append(project.relpath)
|
|
||||||
else:
|
else:
|
||||||
gitc_projects.append(project.relpath)
|
opened_projects.append(project)
|
||||||
|
|
||||||
if not args:
|
if gitc_projects and not opt.local_only:
|
||||||
gitc_projects = None
|
|
||||||
|
|
||||||
if gitc_projects != [] and not opt.local_only:
|
|
||||||
print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name)
|
print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name)
|
||||||
gitc_utils.generate_gitc_manifest(self.repodir,
|
gitc_utils.generate_gitc_manifest(self.gitc_manifest.gitc_client_dir,
|
||||||
self.gitc_manifest.gitc_client_name,
|
|
||||||
self.gitc_manifest,
|
self.gitc_manifest,
|
||||||
self.manifest.manifestFile,
|
|
||||||
gitc_projects)
|
gitc_projects)
|
||||||
print('GITC client successfully synced.')
|
print('GITC client successfully synced.')
|
||||||
|
|
||||||
# The opened projects need to be synced as normal, therefore we
|
# The opened projects need to be synced as normal, therefore we
|
||||||
# generate a new args list to represent the opened projects.
|
# generate a new args list to represent the opened projects.
|
||||||
# TODO: make this more reliable -- if there's a project name/path overlap,
|
args = []
|
||||||
# this may choose the wrong project.
|
for proj in opened_projects:
|
||||||
args = [os.path.relpath(self.manifest.paths[p].worktree, os.getcwd())
|
args.append(os.path.relpath(proj.worktree, os.getcwd()))
|
||||||
for p in opened_projects]
|
|
||||||
if not args:
|
if not args:
|
||||||
return
|
return
|
||||||
all_projects = self.GetProjects(args,
|
all_projects = self.GetProjects(args,
|
||||||
|
Loading…
Reference in New Issue
Block a user