Expand aliases during hg pull to allow pulling from multiple repos
authorGregory Szorc <gps@mozilla.com>
Thu, 25 Jul 2013 19:49:26 -0700
changeset 36 6121cfdb8eec79a4df3f3f0cb1865d2e7bee1097
parent 35 741341c5d5cd2d3002826f51222ec62003276420
child 37 aa2d2b35b388eb900896352345760bd6574cb007
push id20
push usergszorc@mozilla.com
push dateFri, 26 Jul 2013 02:54:28 +0000
Expand aliases during hg pull to allow pulling from multiple repos
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -111,32 +111,31 @@ import datetime
 import errno
 import os
 import re
 import shutil
 import sys
 
 from operator import methodcaller
 
-import mercurial.commands as commands
-
 from mercurial.i18n import _
 from mercurial.commands import (
     push,
 )
 from mercurial.error import (
     RepoError,
 )
 from mercurial.localrepo import (
     repofilecache,
 )
 from mercurial.node import (
     hex,
 )
 from mercurial import (
+    commands,
     cmdutil,
     demandimport,
     encoding,
     extensions,
     hg,
     util,
 )
 
@@ -498,16 +497,27 @@ def buginfo(ui, repo, *bugs, **opts):
         ui.write('\n')
 
 
 def critic_hook(ui, repo, node=None, **opts):
     critique(ui, repo, node=node, **opts)
     return 0
 
 
+def pullexpand(orig, ui, repo, source, **opts):
+    """Wraps built-in pull command to expand aliases to multiple sources."""
+    for tree, uri in resolve_trees_to_uris([source]):
+        result = orig(ui, repo, uri or tree, **opts)
+
+        if result:
+            return result
+
+    return 0
+
+
 class remoterefs(dict):
     """Represents a remote refs file."""
 
     def __init__(self, repo):
         dict.__init__(self)
         self._repo = repo
 
         try:
@@ -537,16 +547,18 @@ class remoterefs(dict):
 def extsetup(ui):
     global bz_available
     try:
         extensions.find('bzexport')
         bz_available = True
     except KeyError:
         pass
 
+    extensions.wrapcommand(commands.table, 'pull', pullexpand)
+
 
 def reposetup(ui, repo):
     """Custom repository implementation.
 
     Our custom repository class tracks remote tree references so users can
     reference specific revisions on remotes.
     """