[PATCH 1 of 9] Add a repo.lookuplist convenience function

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun Mar 2 13:01:23 CST 2008


# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1204481759 10800
# Node ID dd43ec3d30cd13f3925bd51006e0e2699f74ad8a
# Parent  305d4450036a9293eec7b3b057be34fd539f4538
Add a repo.lookuplist convenience function

It just calls repo.lookup on every element of a list of revisions
and returns the results.

diff -r 305d4450036a -r dd43ec3d30cd hgext/fetch.py
--- a/hgext/fetch.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/hgext/fetch.py	Sun Mar 02 15:15:59 2008 -0300
@@ -64,7 +64,7 @@ def fetch(ui, repo, source='default', **
         if opts['rev'] and not other.local():
             raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
         elif opts['rev']:
-            revs = [other.lookup(rev) for rev in opts['rev']]
+            revs = other.lookuplist(opts['rev'])
         modheads = repo.pull(other, heads=revs)
         return postincoming(other, modheads)
 
diff -r 305d4450036a -r dd43ec3d30cd hgext/gpg.py
--- a/hgext/gpg.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/hgext/gpg.py	Sun Mar 02 15:15:59 2008 -0300
@@ -211,7 +211,7 @@ def sign(ui, repo, *revs, **opts):
         opts['date'] = util.parsedate(date)
 
     if revs:
-        nodes = [repo.lookup(n) for n in revs]
+        nodes = repo.lookuplist(revs)
     else:
         nodes = [node for node in repo.dirstate.parents()
                  if node != hgnode.nullid]
diff -r 305d4450036a -r dd43ec3d30cd hgext/patchbomb.py
--- a/hgext/patchbomb.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/hgext/patchbomb.py	Sun Mar 02 15:15:59 2008 -0300
@@ -214,7 +214,7 @@ def patchbomb(ui, repo, *revs, **opts):
     def outgoing(dest, revs):
         '''Return the revisions present locally but not in dest'''
         dest = ui.expandpath(dest or 'default-push', dest or 'default')
-        revs = [repo.lookup(rev) for rev in revs]
+        revs = repo.lookuplist(revs)
         other = hg.repository(ui, dest)
         ui.status(_('comparing with %s\n') % dest)
         o = repo.findoutgoing(other)
diff -r 305d4450036a -r dd43ec3d30cd mercurial/commands.py
--- a/mercurial/commands.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/mercurial/commands.py	Sun Mar 02 15:15:59 2008 -0300
@@ -413,7 +413,7 @@ def bundle(ui, repo, fname, dest=None, *
     """
     revs = opts.get('rev') or None
     if revs:
-        revs = [repo.lookup(rev) for rev in revs]
+        revs = repo.lookuplist(revs)
     if opts.get('all'):
         base = ['null']
     else:
@@ -422,7 +422,7 @@ def bundle(ui, repo, fname, dest=None, *
         if dest:
             raise util.Abort(_("--base is incompatible with specifiying "
                                "a destination"))
-        base = [repo.lookup(rev) for rev in base]
+        base = repo.lookuplist(base)
         # create the right base
         # XXX: nodesbetween / changegroup* should be "fixed" instead
         o = []
@@ -1568,7 +1568,7 @@ def incoming(ui, repo, source="default",
     other = hg.repository(ui, source)
     ui.status(_('comparing with %s\n') % util.hidepassword(source))
     if revs:
-        revs = [other.lookup(rev) for rev in revs]
+        revs = other.lookuplist(revs)
     incoming = repo.findincoming(other, heads=revs, force=opts["force"])
     if not incoming:
         try:
@@ -1879,7 +1879,7 @@ def outgoing(ui, repo, dest=None, **opts
         ui.expandpath(dest or 'default-push', dest or 'default'), opts['rev'])
     cmdutil.setremoteconfig(ui, opts)
     if revs:
-        revs = [repo.lookup(rev) for rev in revs]
+        revs = repo.lookuplist(revs)
 
     other = hg.repository(ui, dest)
     ui.status(_('comparing with %s\n') % util.hidepassword(dest))
@@ -2022,7 +2022,7 @@ def pull(ui, repo, source="default", **o
     ui.status(_('pulling from %s\n') % util.hidepassword(source))
     if revs:
         try:
-            revs = [other.lookup(rev) for rev in revs]
+            revs = other.lookuplist(revs)
         except repo.NoCapability:
             error = _("Other repository doesn't support revision lookup, "
                       "so a rev cannot be specified.")
@@ -2068,7 +2068,7 @@ def push(ui, repo, dest=None, **opts):
     other = hg.repository(ui, dest)
     ui.status('pushing to %s\n' % util.hidepassword(dest))
     if revs:
-        revs = [repo.lookup(rev) for rev in revs]
+        revs = repo.lookuplist(revs)
     r = repo.push(other, opts['force'], revs=revs)
     return r == 0
 
diff -r 305d4450036a -r dd43ec3d30cd mercurial/hg.py
--- a/mercurial/hg.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/mercurial/hg.py	Sun Mar 02 15:15:59 2008 -0300
@@ -226,7 +226,7 @@ def clone(ui, source, dest=None, pull=Fa
                     raise util.Abort(_("src repository does not support revision "
                                        "lookup and so doesn't support clone by "
                                        "revision"))
-                revs = [src_repo.lookup(r) for r in rev]
+                revs = src_repo.lookuplist(rev)
 
             if dest_repo.local():
                 dest_repo.clone(src_repo, heads=revs, stream=stream)
diff -r 305d4450036a -r dd43ec3d30cd mercurial/repo.py
--- a/mercurial/repo.py	Sun Mar 02 13:52:34 2008 +0100
+++ b/mercurial/repo.py	Sun Mar 02 15:15:59 2008 -0300
@@ -34,3 +34,7 @@ class repository(object):
             raise NoCapability(_('cannot %s; remote repository does not '
                                  'support the %r capability') %
                                (purpose, name))
+
+    def lookuplist(self, keys):
+        '''lookup multiple keys'''
+        return [self.lookup(k) for k in keys]


More information about the Mercurial-devel mailing list