diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-07-09 19:49:36 +0100 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-07-09 23:20:25 +0100 |
commit | 4fe8ec373ec8005fe34eb584e53fc8215e9bb995 (patch) | |
tree | c218e446b011baa637c068a4bd2f7d3042079b0d | |
parent | 63ecde7b965ccb19c5cbec15a2bae2e54a0de9d5 (diff) | |
download | lorry-4fe8ec373ec8005fe34eb584e53fc8215e9bb995.tar.gz |
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.
-rw-r--r-- | README | 6 | ||||
-rwxr-xr-x | lorry | 31 | ||||
-rwxr-xr-x | tests/bzr-single-commit.setup | 5 |
3 files changed, 35 insertions, 7 deletions
@@ -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 @@ -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" |