def __init__(self, manifest, name, remote, gitdir, worktree, relpath, revisionExpr, revisionId): self.manifest = manifest self.name = name self.remote = remote self.gitdir = gitdir.replace('\\', '/') if worktree: self.worktree = worktree.replace('\\', '/') else: self.worktree = None self.relpath = relpath self.revisionExpr = revisionExpr if revisionId is None \ and revisionExpr \ and IsId(revisionExpr): self.revisionId = revisionExpr else: self.revisionId = revisionId self.snapshots = {} self.copyfiles = [] self.config = GitConfig.ForRepository( gitdir=self.gitdir, defaults=self.manifest.globalConfig) if self.worktree: self.work_git = self._GitGetByExec(self, bare=False) else: self.work_git = None self.bare_git = self._GitGetByExec(self, bare=True) self.bare_ref = GitRefs(gitdir)
def Execute(self, opt, args): if not args: self.Usage() nb = args[0] if not git.check_ref_format('heads/%s' % nb): print("error: '%s' is not a valid name" % nb, file=sys.stderr) sys.exit(1) err = [] projects = [] if not opt.all: projects = args[1:] if len(projects) < 1: print("error: at least one project must be specified", file=sys.stderr) sys.exit(1) all_projects = self.GetProjects(projects) pm = Progress('Starting %s' % nb, len(all_projects)) for project in all_projects: pm.update() # If the current revision is a specific SHA1 then we can't push back # to it so substitute the manifest default revision instead. if IsId(project.revisionExpr): project.revisionExpr = self.manifest.default.revisionExpr if not project.StartBranch(nb): err.append(project) pm.end() if err: for p in err: print("error: %s/: cannot start %s" % (p.relpath, nb), file=sys.stderr) sys.exit(1)
def FromXml_Definition(self, old): """Convert another manifest representation to this one. """ mp = self.manifestProject gm = self._modules gr = self._review fd = open(os.path.join(mp.worktree, '.gitignore'), 'ab') fd.write('/.repo\n') fd.close() sort_projects = list(old.projects.keys()) sort_projects.sort() b = mp.GetBranch(mp.CurrentBranch).merge if b.startswith(R_HEADS): b = b[len(R_HEADS):] if old.notice: gm.SetString('repo.notice', old.notice) info = [] pm = Progress('Converting manifest', len(sort_projects)) for p in sort_projects: pm.update() p = old.projects[p] gm.SetString('submodule.%s.path' % p.name, p.relpath) gm.SetString('submodule.%s.url' % p.name, p.remote.url) if gr.GetString('review.url') is None: gr.SetString('review.url', p.remote.review) elif gr.GetString('review.url') != p.remote.review: gr.SetString('review.%s.url' % p.name, p.remote.review) r = p.revisionExpr if r and not IsId(r): if r.startswith(R_HEADS): r = r[len(R_HEADS):] if r == b: r = '.' gm.SetString('submodule.%s.revision' % p.name, r) for c in p.copyfiles: info.append('Moved %s out of %s' % (c.src, p.relpath)) c._Copy() p.work_git.rm(c.src) mp.work_git.add(c.dest) self.SetRevisionId(p.relpath, p.GetRevisionId()) mp.work_git.add('.gitignore', '.gitmodules', '.review') pm.end() for i in info: print >> sys.stderr, i
def Execute(self, opt, args): if not args: self.Usage() nb = args[0] if not git.check_ref_format('heads/%s' % nb): print("error: '%s' is not a valid name" % nb, file=sys.stderr) sys.exit(1) err = [] projects = [] if not opt.all: projects = args[1:] if len(projects) < 1: print("error: at least one project must be specified", file=sys.stderr) sys.exit(1) all_projects = self.GetProjects(projects, missing_ok=bool(self.gitc_manifest)) # This must happen after we find all_projects, since GetProjects may need # the local directory, which will disappear once we save the GITC manifest. if self.gitc_manifest: gitc_projects = self.GetProjects(projects, manifest=self.gitc_manifest, missing_ok=True) for project in gitc_projects: if project.old_revision: project.already_synced = True else: project.already_synced = False project.old_revision = project.revisionExpr project.revisionExpr = None # Save the GITC manifest. gitc_utils.save_manifest(self.gitc_manifest) # Make sure we have a valid CWD if not os.path.exists(os.getcwd()): os.chdir(self.manifest.topdir) pm = Progress('Starting %s' % nb, len(all_projects)) for project in all_projects: pm.update() if self.gitc_manifest: gitc_project = self.gitc_manifest.paths[project.relpath] # Sync projects that have not been opened. if not gitc_project.already_synced: proj_localdir = os.path.join( self.gitc_manifest.gitc_client_dir, project.relpath) project.worktree = proj_localdir if not os.path.exists(proj_localdir): os.makedirs(proj_localdir) project.Sync_NetworkHalf() sync_buf = SyncBuffer(self.manifest.manifestProject.config) project.Sync_LocalHalf(sync_buf) project.revisionId = gitc_project.old_revision # 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 # default revision instead. branch_merge = '' if IsId(project.revisionExpr): if project.dest_branch: branch_merge = project.dest_branch else: branch_merge = self.manifest.default.revisionExpr if not project.StartBranch(nb, branch_merge=branch_merge): err.append(project) pm.end() if err: for p in err: print("error: %s/: cannot start %s" % (p.relpath, nb), file=sys.stderr) sys.exit(1)
def _ParseManifest(self, node_list): for node in itertools.chain(*node_list): if node.nodeName == 'remote': remote = self._ParseRemote(node) if remote: if remote.name in self._remotes: if remote != self._remotes[remote.name]: raise ManifestParseError( 'remote %s already exists with different attributes' % (remote.name)) else: self._remotes[remote.name] = remote for node in itertools.chain(*node_list): if node.nodeName == 'default': new_default = self._ParseDefault(node) if self._default is None: self._default = new_default elif new_default != self._default: raise ManifestParseError('duplicate default in %s' % (self.manifestFile)) if self._default is None: self._default = _Default() for node in itertools.chain(*node_list): if node.nodeName == 'notice': if self._notice is not None: raise ManifestParseError('duplicate notice in %s' % (self.manifestFile)) self._notice = self._ParseNotice(node) for node in itertools.chain(*node_list): if node.nodeName == 'manifest-server': url = self._reqatt(node, 'url') if self._manifest_server is not None: raise ManifestParseError( 'duplicate manifest-server in %s' % (self.manifestFile)) self._manifest_server = url def recursively_add_projects(project): projects = self._projects.setdefault(project.name, []) if project.relpath is None: raise ManifestParseError('missing path for %s in %s' % (project.name, self.manifestFile)) if project.relpath in self._paths: raise ManifestParseError('duplicate path %s in %s' % (project.relpath, self.manifestFile)) self._paths[project.relpath] = project projects.append(project) for subproject in project.subprojects: recursively_add_projects(subproject) for node in itertools.chain(*node_list): if node.nodeName == 'project': project = self._ParseProject(node) recursively_add_projects(project) if node.nodeName == 'extend-project': name = self._reqatt(node, 'name') if name not in self._projects: raise ManifestParseError( 'extend-project element specifies non-existent ' 'project: %s' % name) path = node.getAttribute('path') groups = node.getAttribute('groups') if groups: groups = self._ParseGroups(groups) revision = node.getAttribute('revision') remote = node.getAttribute('remote') if remote: remote = self._get_remote(node) for p in self._projects[name]: if path and p.relpath != path: continue if groups: p.groups.extend(groups) if revision: p.revisionExpr = revision if IsId(revision): p.revisionId = revision else: p.revisionId = None if remote: p.remote = remote.ToRemoteSpec(name) if node.nodeName == 'repo-hooks': # Get the name of the project and the (space-separated) list of enabled. repo_hooks_project = self._reqatt(node, 'in-project') enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() # Only one project can be the hooks project if self._repo_hooks_project is not None: raise ManifestParseError('duplicate repo-hooks in %s' % (self.manifestFile)) # Store a reference to the Project. try: repo_hooks_projects = self._projects[repo_hooks_project] except KeyError: raise ManifestParseError( 'project %s not found for repo-hooks' % (repo_hooks_project)) if len(repo_hooks_projects) != 1: raise ManifestParseError( 'internal error parsing repo-hooks in %s' % (self.manifestFile)) self._repo_hooks_project = repo_hooks_projects[0] # Store the enabled hooks in the Project object. self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks if node.nodeName == 'remove-project': name = self._reqatt(node, 'name') if name not in self._projects: raise ManifestParseError( 'remove-project element specifies non-existent ' 'project: %s' % name) for p in self._projects[name]: del self._paths[p.relpath] del self._projects[name] # If the manifest removes the hooks project, treat it as if it deleted # the repo-hooks element too. if self._repo_hooks_project and (self._repo_hooks_project.name == name): self._repo_hooks_project = None