From 4fe8ec373ec8005fe34eb584e53fc8215e9bb995 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 9 Jul 2020 19:49:36 +0100 Subject: Add support for Breezy (brz) as alternative Bazaar implementation The original Bazaar implementation (bzr) only runs on Python 2, but there is a fork known as Breezy (brz) that has been ported to Python 3. To support environments without Python 2, allow using Breezy: * Add a setting 'bazaar-command' that specifies which command to run * Set the default based on a path search, preferring 'bzr' but using 'brz' if only 'brz' is found * Implement a similar fallback in the test setup for Bazaar import * Update README to mention Breezy as an alternative. The 'fastimport' extension is included in it rather than being a separate package. Closes #3. --- README | 6 +++--- lorry | 31 +++++++++++++++++++++++++++---- tests/bzr-single-commit.setup | 5 +++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/README b/README index e6ac568..357e77c 100644 --- a/README +++ b/README @@ -42,9 +42,9 @@ Required: Optional: -* **bzr-fastimport**: Needed if you want to import Bazaar (bzr) - repositories. Can be installed as the `bzr-fastimport` package in - Debian. +* **bzr-fastimport** or **Breezy**: Needed if you want to import + Bazaar (bzr) repositories. Can be installed as the `bzr-fastimport` + or `brz` package in Debian. * **cmdtest**: Needed if you want to run the test suite. Can be installed as the `cmdtest` package in Debian, or from the source at diff --git a/lorry b/lorry index 90257b1..0318ef8 100755 --- a/lorry +++ b/lorry @@ -26,6 +26,7 @@ from datetime import datetime import shutil import traceback import functools +import stat import yaml @@ -52,6 +53,22 @@ def quote_url(url): return ''.join([transl(x) for x in url]) +def find_exec_in_path(name): + for dir_name in os.environ['PATH'].split(os.pathsep): + file_name = os.path.join(dir_name, name) + try: + file_stat = os.stat(file_name) + except OSError: + continue + if stat.S_ISREG(file_stat.st_mode) and file_stat.st_mode & 0o111: + return file_name + return None + + +def find_bazaar_command(): + return find_exec_in_path('bzr') or find_exec_in_path('brz') + + class Lorry(cliapp.Application): def add_settings(self): @@ -101,6 +118,10 @@ class Lorry(cliapp.Application): self.settings.string_list(['push-option'], "option for 'git push' to pass to the " 'remote server') + self.settings.string(['bazaar-command'], + 'command used to access Bazaar repositories', + metavar='COMMAND', + default=find_bazaar_command()) def process_args(self, args): status = 0 @@ -334,11 +355,13 @@ class Lorry(cliapp.Application): self.run_program(argv, cwd=gitdir, env=env) def gitify_bzr(self, project_name, dirname, gitdir, spec): + bzr = self.settings['bazaar-command'] + bzrdir = os.path.join(dirname, 'bzr') # check if repo exists if not os.path.exists(bzrdir): self.progress('.. creating bzr repository') - self.run_program(['bzr', 'init-repo', '--no-trees', bzrdir]) + self.run_program([bzr, 'init-repo', '--no-trees', bzrdir]) if not os.path.exists(gitdir): self.progress('.. creating git repo') @@ -360,12 +383,12 @@ class Lorry(cliapp.Application): if not os.path.exists(branchdir): self.progress('.. doing initial bzr branch') self.run_program( - ['bzr', 'branch', '--quiet', '-Ossl.cert_reqs=none', + [bzr, 'branch', '--quiet', '-Ossl.cert_reqs=none', address, branchdir]) else: self.progress('.. updating bzr branch') self.run_program( - ['bzr', 'pull', '--quiet', '-Ossl.cert_reqs=none', + [bzr, 'pull', '--quiet', '-Ossl.cert_reqs=none', address], cwd=branchdir) @@ -375,7 +398,7 @@ class Lorry(cliapp.Application): branchdir = os.path.join(bzrdir, branch) self.progress('.. fast-exporting branch %s from bzr' % branch) exports[branch] = os.path.join(dirname, 'fast-export' + branch) - cmdline = ['bzr', 'fast-export', '--git-branch=' + branch, + cmdline = [bzr, 'fast-export', '--git-branch=' + branch, branchdir, exports[branch]] if os.path.exists(bzrmarks): cmdline.append('--marks=' + bzrmarks) diff --git a/tests/bzr-single-commit.setup b/tests/bzr-single-commit.setup index dcd70cf..0c28df2 100755 --- a/tests/bzr-single-commit.setup +++ b/tests/bzr-single-commit.setup @@ -20,6 +20,11 @@ set -e +# If bzr is not available and brz is, use brz instead +if ! command -v bzr >/dev/null && command -v brz >/dev/null; then + bzr() { brz "$@"; } +fi + # create the repository repo="$DATADIR/bzr-test-repo" mkdir "$repo" -- cgit v1.2.1