From 1947d61b6ef64c55445c476143ea1962d0db1910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= Date: Fri, 4 Dec 2020 01:44:32 +0100 Subject: [PATCH] Use a single system copy of repo, don't call home Signed-off-by: Bernhard Rosenkraenzer --- MANIFEST.in | 4 ++- git_command.py | 14 +-------- manifest_xml.py | 5 ---- repo | 69 ++++++++----------------------------------- setup.py | 17 +++++++++-- subcmds/init.py | 31 ------------------- subcmds/selfupdate.py | 64 --------------------------------------- subcmds/sync.py | 44 --------------------------- subcmds/version.py | 13 ++------ wrapper.py | 8 ++++- 10 files changed, 40 insertions(+), 229 deletions(-) delete mode 100644 subcmds/selfupdate.py diff --git a/MANIFEST.in b/MANIFEST.in index 8be47dd..1eda860 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,6 @@ -graft docs hooks tests +graft docs +graft hooks +graft tests include *.py include LICENSE include git_ssh diff --git a/git_command.py b/git_command.py index 1cb8f1a..2dbddbb 100644 --- a/git_command.py +++ b/git_command.py @@ -161,19 +161,7 @@ def RepoSourceVersion(): # We avoid GitCommand so we don't run into circular deps -- GitCommand needs # to initialize version info we provide. if ver is None: - env = GitCommand._GetBasicEnv() - - proj = os.path.dirname(os.path.abspath(__file__)) - env[GIT_DIR] = os.path.join(proj, '.git') - - p = subprocess.Popen([GIT, 'describe', HEAD], stdout=subprocess.PIPE, - env=env) - if p.wait() == 0: - ver = p.stdout.read().strip().decode('utf-8') - if ver.startswith('v'): - ver = ver[1:] - else: - ver = 'unknown' + ver = 'OSTC/2.9' setattr(RepoSourceVersion, 'version', ver) return ver diff --git a/manifest_xml.py b/manifest_xml.py index ad0017c..961e25e 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -207,10 +207,6 @@ class XmlManifest(object): self.local_manifests = local_manifests self._load_local_manifests = True - self.repoProject = MetaProject(self, 'repo', - gitdir=os.path.join(repodir, 'repo/.git'), - worktree=os.path.join(repodir, 'repo')) - mp = MetaProject(self, 'manifests', gitdir=os.path.join(repodir, 'manifests.git'), worktree=os.path.join(repodir, 'manifests')) @@ -632,7 +628,6 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md raise e if self.IsMirror: - self._AddMetaProjectMirror(self.repoProject) self._AddMetaProjectMirror(self.manifestProject) self._loaded = True diff --git a/repo b/repo index b13e34c..310316e 100755 --- a/repo +++ b/repo @@ -494,43 +494,9 @@ def check_repo_rev(dst, rev, repo_verify=True, quiet=False): def _Init(args, gitc_init=False): - """Installs repo by cloning it over the network. + """Initializes the .repo directory """ - parser = GetParser(gitc_init=gitc_init) - opt, args = parser.parse_args(args) - if args: - parser.print_usage() - sys.exit(1) - opt.quiet = opt.output_mode is False - opt.verbose = opt.output_mode is True - - if opt.clone_bundle is None: - opt.clone_bundle = False if opt.partial_clone else True - - url = opt.repo_url or REPO_URL - rev = opt.repo_rev or REPO_REV - try: - if gitc_init: - gitc_manifest_dir = get_gitc_manifest_dir() - if not gitc_manifest_dir: - print('fatal: GITC filesystem is not available. Exiting...', - file=sys.stderr) - sys.exit(1) - gitc_client = opt.gitc_client - if not gitc_client: - gitc_client = gitc_parse_clientdir(os.getcwd()) - if not gitc_client: - print('fatal: GITC client (-c) is required.', file=sys.stderr) - sys.exit(1) - client_dir = os.path.join(gitc_manifest_dir, gitc_client) - if not os.path.exists(client_dir): - os.makedirs(client_dir) - os.chdir(client_dir) - if os.path.exists(repodir): - # This GITC Client has already initialized repo so continue. - return - os.mkdir(repodir) except OSError as e: if e.errno != errno.EEXIST: @@ -541,26 +507,6 @@ def _Init(args, gitc_init=False): # sys.exit(1) - _CheckGitVersion() - try: - if not opt.quiet: - print('Downloading Repo source from', url) - dst = os.path.abspath(os.path.join(repodir, S_repo)) - _Clone(url, dst, opt.clone_bundle, opt.quiet, opt.verbose) - - remote_ref, rev = check_repo_rev(dst, rev, opt.repo_verify, quiet=opt.quiet) - _Checkout(dst, remote_ref, rev, opt.quiet) - - if not os.path.isfile(os.path.join(dst, 'repo')): - print("warning: '%s' does not look like a git-repo repository, is " - "REPO_URL set correctly?" % url, file=sys.stderr) - - except CloneFailure: - if opt.quiet: - print('fatal: repo init failed; run without --quiet to see why', - file=sys.stderr) - raise - def run_git(*args, **kwargs): """Run git and return execution details.""" @@ -967,11 +913,12 @@ def _FindRepo(): olddir = None while curdir != olddir and not repo: - repo = os.path.join(curdir, repodir, REPO_MAIN) - if not os.path.isfile(repo): + repo = os.path.join(curdir, ".repo") + if not os.path.isdir(repo): repo = None olddir = curdir curdir = os.path.dirname(curdir) + repo = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "share", "repo", "main.py") return (repo, os.path.join(curdir, repodir)) @@ -1126,6 +1073,13 @@ def main(orig_args): SetGitTrace2ParentSid() repo_main, rel_repo_dir = None, None + + # Since the check for repo_main always succeeds (because we're + # using a locally installed repo), take care of "repo init" before + # running _FindRepo() + if cmd == 'init' or cmd == 'gitc-init': + _Init(args, gitc_init=(cmd == 'gitc-init')) + # Don't use the local repo copy, make sure to switch to the gitc client first. if cmd != 'gitc-init': repo_main, rel_repo_dir = _FindRepo() @@ -1140,6 +1094,7 @@ def main(orig_args): 'command from the corresponding client under /gitc/', file=sys.stderr) sys.exit(1) + if not repo_main: # Only expand aliases here since we'll be parsing the CLI ourselves. # If we had repo_main, alias expansion would happen in main.py. diff --git a/setup.py b/setup.py index f4d7728..72b726a 100755 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ from __future__ import print_function import os import setuptools - +import glob TOPDIR = os.path.dirname(os.path.abspath(__file__)) @@ -31,6 +31,18 @@ with open(os.path.join(TOPDIR, 'README.md')) as fp: end = lines.index('') long_description = ' '.join(lines[0:end]) +wd = os.getcwd() +os.chdir(TOPDIR) +topfiles=['LICENSE', 'git_ssh', 'run_tests'] + glob.glob("*.py") +topfiles.remove('setup.py') +neededfiles=[('share/repo', topfiles)] +for subdir in ['docs', 'hooks', 'release', 'subcmds', 'tests', 'tests/fixtures']: + files=[] + for f in glob.glob(subdir + '/*'): + if not os.path.isdir(f): + files += [f] + neededfiles += [('share/repo/' + subdir, files)] +os.chdir(wd) # https://packaging.python.org/tutorials/packaging-projects/ setuptools.setup( @@ -59,5 +71,6 @@ setuptools.setup( ], # We support Python 2.7 and Python 3.6+. python_requires='>=2.7, ' + ', '.join('!=3.%i.*' % x for x in range(0, 6)), - packages=['subcmds'], + scripts=['repo'], + data_files=neededfiles, ) diff --git a/subcmds/init.py b/subcmds/init.py index f46babf..6258777 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -165,19 +165,6 @@ to update the working directory files. dest='tags', default=True, action='store_false', help="don't fetch tags in the manifest") - # Tool - g = p.add_option_group('repo Version options') - g.add_option('--repo-url', - dest='repo_url', - help='repo repository location', metavar='URL') - g.add_option('--repo-rev', metavar='REV', - help='repo branch or revision') - g.add_option('--repo-branch', dest='repo_rev', - help=optparse.SUPPRESS_HELP) - g.add_option('--no-repo-verify', - dest='repo_verify', default=True, action='store_false', - help='do not verify repo source code') - # Other g = p.add_option_group('Other options') g.add_option('--config-name', @@ -506,24 +493,6 @@ to update the working directory files. opt.quiet = opt.output_mode is False opt.verbose = opt.output_mode is True - rp = self.manifest.repoProject - - # Handle new --repo-url requests. - if opt.repo_url: - remote = rp.GetRemote('origin') - remote.url = opt.repo_url - remote.Save() - - # Handle new --repo-rev requests. - if opt.repo_rev: - wrapper = Wrapper() - remote_ref, rev = wrapper.check_repo_rev( - rp.gitdir, opt.repo_rev, repo_verify=opt.repo_verify, quiet=opt.quiet) - branch = rp.GetBranch('default') - branch.merge = remote_ref - rp.work_git.update_ref('refs/heads/default', rev) - branch.Save() - if opt.worktree: # Older versions of git supported worktree, but had dangerous gc bugs. git_require((2, 15, 0), fail=True, msg='git gc worktree corruption') diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py deleted file mode 100644 index bf6256a..0000000 --- a/subcmds/selfupdate.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding:utf-8 -*- -# -# Copyright (C) 2009 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function -from optparse import SUPPRESS_HELP -import sys - -from command import Command, MirrorSafeCommand -from subcmds.sync import _PostRepoUpgrade -from subcmds.sync import _PostRepoFetch - - -class Selfupdate(Command, MirrorSafeCommand): - common = False - helpSummary = "Update repo to the latest version" - helpUsage = """ -%prog -""" - helpDescription = """ -The '%prog' command upgrades repo to the latest version, if a -newer version is available. - -Normally this is done automatically by 'repo sync' and does not -need to be performed by an end-user. -""" - - def _Options(self, p): - g = p.add_option_group('repo Version options') - g.add_option('--no-repo-verify', - dest='repo_verify', default=True, action='store_false', - help='do not verify repo source code') - g.add_option('--repo-upgraded', - dest='repo_upgraded', action='store_true', - help=SUPPRESS_HELP) - - def Execute(self, opt, args): - rp = self.manifest.repoProject - rp.PreSync() - - if opt.repo_upgraded: - _PostRepoUpgrade(self.manifest) - - else: - if not rp.Sync_NetworkHalf(): - print("error: can't update repo", file=sys.stderr) - sys.exit(1) - - rp.bare_git.gc('--auto') - _PostRepoFetch(rp, - repo_verify=opt.repo_verify, - verbose=True) diff --git a/subcmds/sync.py b/subcmds/sync.py index f5a7b0e..b874fa0 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -853,22 +853,9 @@ later is required to fix a server side protocol bug. err_event = _threading.Event() - rp = self.manifest.repoProject - rp.PreSync() - cb = rp.CurrentBranch - if cb: - base = rp.GetBranch(cb).merge - if not base or not base.startswith('refs/heads/'): - print('warning: repo is not tracking a remote branch, so it will not ' - 'receive updates; run `repo init --repo-rev=stable` to fix.', - file=sys.stderr) - mp = self.manifest.manifestProject mp.PreSync() - if opt.repo_upgraded: - _PostRepoUpgrade(self.manifest, quiet=opt.quiet) - if not opt.mp_update: print('Skipping update of local manifest project.') else: @@ -921,14 +908,11 @@ later is required to fix a server side protocol bug. if not opt.local_only: to_fetch = [] now = time.time() - if _ONE_DAY_S <= (now - rp.LastFetch): - to_fetch.append(rp) to_fetch.extend(all_projects) to_fetch.sort(key=self._fetch_times.Get, reverse=True) fetched = self._Fetch(to_fetch, opt, err_event) - _PostRepoFetch(rp, opt.repo_verify) if opt.network_only: # bail out now; the rest touches the working tree if err_event.isSet(): @@ -1009,34 +993,6 @@ later is required to fix a server side protocol bug. print('repo sync has finished successfully.') -def _PostRepoUpgrade(manifest, quiet=False): - wrapper = Wrapper() - if wrapper.NeedSetupGnuPG(): - wrapper.SetupGnuPG(quiet) - for project in manifest.projects: - if project.Exists: - project.PostRepoUpgrade() - - -def _PostRepoFetch(rp, repo_verify=True, verbose=False): - if rp.HasChanges: - print('info: A new version of repo is available', file=sys.stderr) - print(file=sys.stderr) - if not repo_verify or _VerifyTag(rp): - syncbuf = SyncBuffer(rp.config) - rp.Sync_LocalHalf(syncbuf) - if not syncbuf.Finish(): - sys.exit(1) - print('info: Restarting repo with latest version', file=sys.stderr) - raise RepoChangedException(['--repo-upgraded']) - else: - print('warning: Skipped upgrade to unverified version', file=sys.stderr) - else: - if verbose: - print('repo version %s is current' % rp.work_git.describe(HEAD), - file=sys.stderr) - - def _VerifyTag(project): gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') if not os.path.exists(gpg_dir): diff --git a/subcmds/version.py b/subcmds/version.py index 6a7921d..5d4ee14 100644 --- a/subcmds/version.py +++ b/subcmds/version.py @@ -35,23 +35,14 @@ class Version(Command, MirrorSafeCommand): """ def Execute(self, opt, args): - rp = self.manifest.repoProject - rem = rp.GetRemote(rp.remote.name) - - # These might not be the same. Report them both. src_ver = RepoSourceVersion() - rp_ver = rp.bare_git.describe(HEAD) - print('repo version %s' % rp_ver) - print(' (from %s)' % rem.url) - print(' (%s)' % rp.bare_git.log('-1', '--format=%cD', HEAD)) + print('repo version %s' % src_ver) + print(' (from OSTC)') if self.wrapper_path is not None: print('repo launcher version %s' % self.wrapper_version) print(' (from %s)' % self.wrapper_path) - if src_ver != rp_ver: - print(' (currently at %s)' % src_ver) - print('repo User-Agent %s' % user_agent.repo) print('git %s' % git.version_tuple().full) print('git User-Agent %s' % user_agent.git) diff --git a/wrapper.py b/wrapper.py index 8130298..c73d763 100644 --- a/wrapper.py +++ b/wrapper.py @@ -25,7 +25,13 @@ import os def WrapperPath(): - return os.path.join(os.path.dirname(__file__), 'repo') + wrappers = [ + os.path.join(os.path.dirname(__file__), '..', '..', 'bin', 'repo'), # After setup.py install + os.path.join(os.path.dirname(__file__), 'repo') # Running from source directory + ] + for i in wrappers: + if os.path.exists(i): + return i _wrapper_module = None -- 2.29.2