hgkw/keyword.py
branchself_initializing_hook
changeset 84 f8f0296775ad
parent 83 05e50378c6e8
child 86 790aa37e93aa
--- a/hgkw/keyword.py	Tue Jan 09 16:17:30 2007 +0100
+++ b/hgkw/keyword.py	Wed Jan 10 16:27:46 2007 +0100
@@ -20,13 +20,12 @@
     Id:       basename,v csetid %Y-%m-%d %H:%M:%S %z shortname
     Header:   /path/to/basename,v csetid %Y-%m-%d %H:%M:%S %z shortname
 
-Install:
-    Copy keyword.py in hgext folder.
-
 Simple setup in hgrc:
 
     # enable extension
     hgext.keyword =
+    # or, if script not in hgext folder:
+    # hgext.keyword = /full/path/to/script
     
     # filename patterns for expansion are configured in this section
     [keyword]
@@ -35,7 +34,7 @@
 '''
 
 from mercurial import context, util
-import os.path, re
+import os.path, re, sys
 
 
 re_kw = re.compile(
@@ -130,8 +129,10 @@
 
     filelog.filelog = kwfilelog
     repo.__class__ = kwrepo
-    ui.setconfig('hooks',
-            'pretxncommit.keyword', 'python:hgext.keyword.pretxnkw')
+    # import keyword from pretxncommit hook even if it is not in hgext folder
+    sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
+    ui.setconfig('hooks', 'pretxncommit.keyword', 'python:%s.pretxnkw'
+            % os.path.splitext(os.path.basename(__file__))[0])
 
 
 def pretxnkw(ui, repo, hooktype, **args):
@@ -142,7 +143,6 @@
     #   from mercurial.i18n import _
     # some day
     from mercurial import cmdutil, commands
-    import sys
 
     if hooktype != 'pretxncommit':
         return True