From 6d5fb6dbde1781fd74c0f7313024871003a5312b Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Wed, 16 Sep 2020 21:30:08 +0100 Subject: lorry: Use a working tree in gitify_cvs Sadly, git cvsimport requires a working tree for most operations, and only an initial import can be done successfully with the '-i' option. Rather than adding back general support for non-bare repositories: * When creating a mirror, let git cvsimport create it non-bare and then convert it to be bare * When updating a mirror, add a temporary working tree with "git worktree add" --- lorry | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 8 deletions(-) (limited to 'lorry') diff --git a/lorry b/lorry index a3b42e0..81fdeb3 100755 --- a/lorry +++ b/lorry @@ -676,21 +676,68 @@ class Lorry(cliapp.Application): self.run_program(['git', 'svn', 'fetch'], cwd=gitdir) def gitify_cvs(self, project_name, dirname, gitdir, spec): + # git cvsimport requires a working tree for some operations; + # keep this separate from the repository + worktree = os.path.join(dirname, 'git-cvs-worktree') + + if os.path.exists(gitdir): + if os.path.exists(worktree): + shutil.rmtree(worktree) + self.run_program(['git', 'worktree', 'prune'], + cwd=gitdir) + self.run_program(['git', 'worktree', 'add', worktree, 'master'], + cwd=gitdir) + + # git cvsimport insists on $GIT_DIR or .git being a + # directory, but .git will be a file. Set $GIT_DIR to + # the subdirectory of gitdir created for this worktree. + cvsimp_gitdir = self.runcmd(['git', 'rev-parse', '--git-dir'], + cwd=worktree) \ + .decode('utf-8') \ + .rstrip('\n') + + # cvsps should find its cache under gitdir, not the + # temporary worktree + cvsps_home = gitdir + else: + # We must let git cvsimport create the repository + cvsimp_gitdir = os.path.join(worktree, '.git') + + # cvsps should create its cache there, and it will be + # moved to gitdir later + cvsps_home = cvsimp_gitdir + self.needs_aggressive = True env = dict(os.environ) env['CVS_RSH'] = 'lorry-ssh-wrapper' - env['GIT_DIR'] = gitdir - env['HOME'] = gitdir # make cvsps store cache under git dir + env['GIT_DIR'] = cvsimp_gitdir + env['HOME'] = cvsps_home self.run_program( ['git', 'cvsimport', '-a', '-d', spec['url'], - '-i', spec['module']], + '-C', worktree, spec['module']], env=env) - # git cvsimport may create an index even in a bare repo - try: - os.remove(os.path.join(gitdir, 'index')) - except FileNotFoundError: - pass + if not os.path.exists(gitdir): + # git cvsimport created a non-bare repository; convert it + # to bare + os.rename(cvsimp_gitdir, gitdir) + self.run_program(['git', 'config', 'core.bare', 'true'], + cwd=gitdir) + self.run_program(['git', 'config', 'core.logallrefupdates', + 'false'], + cwd=gitdir) + try: + os.remove(os.path.join(gitdir, 'index')) + except FileNotFoundError: + pass + try: + shutil.rmtree(os.path.join(gitdir, 'logs')) + except FileNotFoundError: + pass + + shutil.rmtree(worktree) + self.run_program(['git', 'worktree', 'prune'], + cwd=gitdir) def gitify_hg(self, project_name, dirname, gitdir, spec): cert_options = [] -- cgit v1.2.1