Rev 7: Add a MutableTree.hooks['start_commit'] hook. in http://bzr.arbash-meinel.com/plugins/update_copyright

John Arbash Meinel john at arbash-meinel.com
Fri Jan 8 21:03:08 GMT 2010


At http://bzr.arbash-meinel.com/plugins/update_copyright

------------------------------------------------------------
revno: 7
revision-id: john at arbash-meinel.com-20100108210257-5tv2til4gcul7sl0
parent: john at arbash-meinel.com-20100108205546-44sf89j4c0o4s25j
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: update_copyright
timestamp: Fri 2010-01-08 15:02:57 -0600
message:
  Add a MutableTree.hooks['start_commit'] hook.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2010-01-08 20:55:46 +0000
+++ b/__init__.py	2010-01-08 21:02:57 +0000
@@ -26,6 +26,7 @@
 from bzrlib import (
     commands,
     errors,
+    mutabletree, # I wish we could make the hook registration fully lazy
     option,
     )
 
@@ -59,6 +60,24 @@
 
 commands.register_command(cmd_update_copyright)
 
+def _update_copyright_start_commit_hook(tree):
+    """A hook that will update copyrights at commit time.
+
+    This is configured via "auto_update_copyright=True" in your configuration
+    files.
+    """
+    conf = tree.branch.get_config()
+    import pdb; pdb.set_trace()
+    auto_update = conf.get_user_option_as_bool('auto_update_copyright'):
+    if auto_update is None or not auto_update:
+        return
+    import update_copyright
+    update_copyright.update_tree_copyright(tree, None, only_changed=True)
+
+
+mutabletree.MutableTree.hooks.install_named_hook('start_commit',
+    _update_copyright_start_commit_hook, 'update-copyright')
+
 
 def load_tests(standard_tests, module, loader):
     standard_tests.addTests(loader.loadTestsFromModuleNames(

=== modified file 'update_copyright.py'
--- a/update_copyright.py	2010-01-08 20:55:46 +0000
+++ b/update_copyright.py	2010-01-08 21:02:57 +0000
@@ -76,7 +76,7 @@
               'updated': 0,
               'count': 0,
              }
-    tree.lock_write()
+    tree.lock_tree_write()
     try:
         basis_tree = tree.basis_tree()
         basis_tree.lock_read()



More information about the bazaar-commits mailing list