install reposetup hook right after loading the extension
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 06 Feb 2007 15:43:01 -0200
changeset 4064 5d9ede002453
parent 4063 96863fc3036a
child 4065 8ee983e3d461
install reposetup hook right after loading the extension
mercurial/commands.py
tests/test-extension
tests/test-extension.out
--- a/mercurial/commands.py	Tue Jan 30 20:37:58 2007 -0200
+++ b/mercurial/commands.py	Tue Feb 06 15:43:01 2007 -0200
@@ -3106,6 +3106,9 @@
         uisetup = getattr(mod, 'uisetup', None)
         if uisetup:
             uisetup(ui)
+        reposetup = getattr(mod, 'reposetup', None)
+        if reposetup:
+            hg.repo_setup_hooks.append(reposetup)
         cmdtable = getattr(mod, 'cmdtable', {})
         for t in cmdtable:
             if t in table:
@@ -3188,11 +3191,6 @@
                     if not repo:
                         repo = hg.repository(u, path=path)
                     u = repo.ui
-                    for name in external.itervalues():
-                        mod = sys.modules[name]
-                        if hasattr(mod, 'reposetup'):
-                            mod.reposetup(u, repo)
-                            hg.repo_setup_hooks.append(mod.reposetup)
                 except hg.RepoError:
                     if cmd not in optionalrepo.split():
                         raise
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extension	Tue Feb 06 15:43:01 2007 -0200
@@ -0,0 +1,42 @@
+#!/bin/sh
+# Test basic extension support
+
+cat > foobar.py <<EOF
+import os
+from mercurial import commands
+
+def uisetup(ui):
+    ui.write("uisetup called\\n")
+
+def reposetup(ui, repo):
+    ui.write("reposetup called for %s\\n" % os.path.basename(repo.root))
+
+def foo(ui, *args, **kwargs):
+    ui.write("Foo\\n")
+
+def bar(ui, *args, **kwargs):
+    ui.write("Bar\\n")
+
+cmdtable = {
+    "foo": (foo, [], "hg foo"),
+    "bar": (bar, [], "hg bar"),
+}
+
+commands.norepo += ' bar'
+EOF
+abspath=`pwd`/foobar.py
+
+hg init a
+cd a
+echo foo > file
+hg add file
+hg commit -m 'add file'
+
+echo '[extensions]' >> $HGRCPATH
+echo "foobar = $abspath" >> $HGRCPATH
+hg foo
+
+cd ..
+hg clone a b
+
+hg bar
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extension.out	Tue Feb 06 15:43:01 2007 -0200
@@ -0,0 +1,9 @@
+uisetup called
+reposetup called for a
+Foo
+uisetup called
+reposetup called for a
+reposetup called for b
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+uisetup called
+Bar