Update bzr plugin to use new start_commit hook.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 5 Apr 2008 03:34:08 +0000 (05:34 +0200)
committerJoey Hess <joey@kodama.kitenet.net>
Sat, 5 Apr 2008 18:30:22 +0000 (14:30 -0400)
etckeeper-bzr.py [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 4a51085..97a8689
@@ -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"])