From fa84e9dcae169c7e6f9800572cb94bad2c09c51e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Apr 2008 05:34:08 +0200 Subject: Update bzr plugin to use new start_commit hook. --- etckeeper-bzr.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) mode change 100644 => 100755 etckeeper-bzr.py (limited to 'etckeeper-bzr.py') diff --git a/etckeeper-bzr.py b/etckeeper-bzr.py old mode 100644 new mode 100755 index 4a51085..97a8689 --- a/etckeeper-bzr.py +++ b/etckeeper-bzr.py @@ -1,28 +1,26 @@ #!/usr/bin/python -# bzr plugin that runs etckeeper pre-commit when necessary +# Bazaar plugin that runs etckeeper pre-commit when necessary -from bzrlib.branch import Branch +"""Runs etckeeper pre-commit when necessary.""" + +from bzrlib.mutabletree import MutableTree from bzrlib.errors import BzrError, NotLocalUrl import os import subprocess -def etckeeper_precommit_hook(local, master, old_revno, old_revid, - new_revno, new_revid, tree_delta, future_tree): - if local is None: - branch = master - else: - branch = local - try: - base = branch.bzrdir.root_transport.local_abspath(".") - except NotLocalUrl: - # No point in running etckeeper when committing to a remote branch - return - if not os.path.exists(os.path.join(base, ".etckeeper")): +def etckeeper_startcommit_hook(tree): + if not os.path.exists(tree.abspath(".etckeeper")): # Only run the commit hook when this is an etckeeper branch return - ret = subprocess.call(["etckeeper", "pre-commit", base]) + ret = subprocess.call(["etckeeper", "pre-commit", tree.abspath(".")]) if ret != 0: raise BzrError("etckeeper pre-commit failed") -Branch.hooks.install_hook('pre_commit', etckeeper_precommit_hook) -Branch.hooks.name_hook(etckeeper_precommit_hook, "etckeeper") +MutableTree.hooks.install_hook('start_commit', etckeeper_startcommit_hook) +MutableTree.hooks.name_hook(etckeeper_startcommit_hook, "etckeeper") + +if __name__ == "__main__": + from distutils.core import setup + setup(name="bzr-etckeeper", + package_dir={"bzrlib.plugins.etckeeper":__file__}, + py_modules=["bzrlib.plugins.etckeeper"]) -- cgit v1.2.3