From b2bd91c99b9435cf950ecf8efbb8439f31d3fcbc Mon Sep 17 00:00:00 2001 From: Che-Liang Chiou Date: Wed, 11 Jan 2012 11:28:42 +0800 Subject: Represent git-submodule as nested projects, take 2 (Previous submission of this change broke Android buildbot due to incorrect regular expression for parsing git-config output. During investigation, we also found that Android, which pulls Chromium, has a workaround for Chromium's submodules; its manifest includes Chromium's submodules. This new change, in addition to fixing the regex, also take this type of workarounds into consideration; it adds a new attribute that makes repo not fetch submodules unless submodules have a project element defined in the manifest, or this attribute is overridden by a parent project element or by the default element.) We need a representation of git-submodule in repo; otherwise repo will not sync submodules, and leave workspace in a broken state. Of course this will not be a problem if all projects are owned by the owner of the manifest file, who may simply choose not to use git-submodule in all projects. However, this is not possible in practice because manifest file owner is unlikely to own all upstream projects. As git submodules are simply git repositories, it is natural to treat them as plain repo projects that live inside a repo project. That is, we could use recursively declared projects to denote the is-submodule relation of git repositories. The behavior of repo remains the same to projects that do not have a sub-project within. As for parent projects, repo fetches them and their sub-projects as normal projects, and then checks out subprojects at the commit specified in parent's commit object. The sub-project is fetched at a path relative to parent project's working directory; so the path specified in manifest file should match that of .gitmodules file. If a submodule is not registered in repo manifest, repo will derive its properties from itself and its parent project, which might not always be correct. In such cases, the subproject is called a derived subproject. To a user, a sub-project is merely a git-submodule; so all tips of working with a git-submodule apply here, too. For example, you should not run `repo sync` in a parent repository if its submodule is dirty. Change-Id: I4b8344c1b9ccad2f58ad304573133e5d52e1faef --- subcmds/sync.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index 5b3dca78..f8094738 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -114,6 +114,9 @@ resumeable bundle file on a content delivery network. This may be necessary if there are problems with the local Python HTTP client or proxy configuration, but the Git binary works. +The --fetch-submodules option enables fetching Git submodules +of a project from server. + SSH Connections --------------- @@ -180,6 +183,9 @@ later is required to fix a server side protocol bug. p.add_option('-p', '--manifest-server-password', action='store', dest='manifest_server_password', help='password to authenticate with the manifest server') + p.add_option('--fetch-submodules', + dest='fetch_submodules', action='store_true', + help='fetch submodules from server') if show_smart: p.add_option('-s', '--smart-sync', dest='smart_sync', action='store_true', @@ -559,7 +565,9 @@ later is required to fix a server side protocol bug. self.manifest._Unload() if opt.jobs is None: self.jobs = self.manifest.default.sync_j - all_projects = self.GetProjects(args, missing_ok=True) + all_projects = self.GetProjects(args, + missing_ok=True, + submodules_ok=opt.fetch_submodules) self._fetch_times = _FetchTimes(self.manifest) if not opt.local_only: @@ -570,12 +578,33 @@ later is required to fix a server side protocol bug. to_fetch.extend(all_projects) to_fetch.sort(key=self._fetch_times.Get, reverse=True) - self._Fetch(to_fetch, opt) + fetched = self._Fetch(to_fetch, opt) _PostRepoFetch(rp, opt.no_repo_verify) if opt.network_only: # bail out now; the rest touches the working tree return + # Iteratively fetch missing and/or nested unregistered submodules + previously_missing_set = set() + while True: + self.manifest._Unload() + all_projects = self.GetProjects(args, + missing_ok=True, + submodules_ok=opt.fetch_submodules) + missing = [] + for project in all_projects: + if project.gitdir not in fetched: + missing.append(project) + if not missing: + break + # Stop us from non-stopped fetching actually-missing repos: If set of + # missing repos has not been changed from last fetch, we break. + missing_set = set(p.name for p in missing) + if previously_missing_set == missing_set: + break + previously_missing_set = missing_set + fetched.update(self._Fetch(missing, opt)) + if self.manifest.IsMirror: # bail out now, we have no working tree return -- cgit v1.2.3-54-g00ecf