[PATCH 1 of 3] add branchmap repository (and wire) command and capability

Dirkjan Ochtman dirkjan at ochtman.nl
Thu May 21 07:21:06 CDT 2009


Thanks for working on this. I have some nits & notes...

On 21/05/2009 09:41, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager<cryo at cyanite.org>
> # Date 1242889818 -7200
> # Node ID aa08c8294220bf4f5b8702c9353c6c13a64d73c2
> # Parent  6062c6362b2e318fbc731d3aa1211b662d70c191
> add branchmap repository (and wire) command and capability
>
> diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
> --- a/mercurial/hgweb/protocol.py
> +++ b/mercurial/hgweb/protocol.py
> @@ -5,7 +5,7 @@
>   # This software may be used and distributed according to the terms of the
>   # GNU General Public License version 2, incorporated herein by reference.
>
> -import cStringIO, zlib, tempfile, errno, os, sys
> +import cStringIO, zlib, tempfile, errno, os, sys, urllib
>   from mercurial import util, streamclone
>   from mercurial.node import bin, hex
>   from mercurial import changegroup as changegroupmod
> @@ -17,6 +17,7 @@
>   __all__ = [
>      'lookup', 'heads', 'branches', 'between', 'changegroup',
>      'changegroupsubset', 'capabilities', 'unbundle', 'stream_out',
> +   'branchmap',
>   ]
>
>   HGTYPE = 'application/mercurial-0.1'
> @@ -37,6 +38,14 @@
>       req.respond(HTTP_OK, HGTYPE, length=len(resp))
>       yield resp
>
> +def branchmap(repo, req):
> +    branches = repo.branchmap()
> +    heads = ['%s %s' % (urllib.quote(b), " ".join([hex(x) for x in branches[b]])) \
> +             for b in branches]

I think this would be better as a straight for; it's just to complex to 
keep it as a list comprehension, and the line continuation doesn't help 
the readability (particularly with the nested comprehension).

> +    resp = "\n".join(heads)
> +    req.respond(HTTP_OK, HGTYPE, length=len(resp))
> +    yield resp
> +
>   def branches(repo, req):
>       nodes = []
>       if 'nodes' in req.form:
> @@ -97,7 +106,7 @@
>       yield z.flush()
>
>   def capabilities(repo, req):
> -    caps = ['lookup', 'changegroupsubset']
> +    caps = ['lookup', 'changegroupsubset', 'branchmap']
>       if repo.ui.configbool('server', 'uncompressed', untrusted=True):
>           caps.append('stream=%d' % repo.changelog.version)
>       if changegroupmod.bundlepriority:
> diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py
> --- a/mercurial/httprepo.py
> +++ b/mercurial/httprepo.py
> @@ -145,6 +145,19 @@
>           except:
>               raise error.ResponseError(_("unexpected response:"), d)
>
> +    def branchmap(self):
> +        d = self.do_read("branchmap")
> +        try:
> +            branchmap = {}
> +            for branchpart in d.splitlines():
> +                branchheads = branchpart.split(' ')
> +                branchname = urllib.unquote(branchheads[0])
> +                branchheads = [bin(x) for x in branchheads[1:]]
> +                branchmap[branchname] = branchheads
> +            return branchmap
> +        except:
> +            raise error.ResponseError(_("unexpected response:"), d)
> +
>       def branches(self, nodes):
>           n = " ".join(map(hex, nodes))
>           d = self.do_read("branches", nodes=n)
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -18,7 +18,7 @@
>   propertycache = util.propertycache
>
>   class localrepository(repo.repository):
> -    capabilities = set(('lookup', 'changegroupsubset'))
> +    capabilities = set(('lookup', 'changegroupsubset', 'branchmap'))
>       supported = set('revlogv1 store fncache'.split())
>
>       def __init__(self, baseui, path=None, create=0):
> @@ -360,6 +360,9 @@
>
>           return partial
>
> +    def branchmap(self):
> +        return self._branchheads()
> +

This part doesn't make much sense to me. Could we just rename the method 
instead?

>       def _branchheads(self):
>           tip = self.changelog.tip()
>           if self.branchcache is not None and self._branchcachetip == tip:
> diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
> --- a/mercurial/sshrepo.py
> +++ b/mercurial/sshrepo.py
> @@ -8,7 +8,7 @@
>   from node import bin, hex
>   from i18n import _
>   import repo, util, error
> -import re
> +import urllib, re
>
>   class remotelock(object):
>       def __init__(self, repo):
> @@ -166,6 +166,19 @@
>           except:
>               self.abort(error.ResponseError(_("unexpected response:"), d))
>
> +    def branchmap(self):
> +        d = self.call("branchmap")
> +        try:
> +            branchmap = {}
> +            for branchpart in d.splitlines():
> +                branchheads = branchpart.split(' ')
> +                branchname = urllib.unquote(branchheads[0])
> +                branchheads = [bin(x) for x in branchheads[1:]]
> +                branchmap[branchname] = branchheads
> +            return branchmap
> +        except:
> +            raise error.ResponseError(_("unexpected response:"), d)
> +
>       def branches(self, nodes):
>           n = " ".join(map(hex, nodes))
>           d = self.call("branches", nodes=n)
> diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py
> --- a/mercurial/sshserver.py
> +++ b/mercurial/sshserver.py
> @@ -9,7 +9,7 @@
>   from i18n import _
>   from node import bin, hex
>   import streamclone, util, hook
> -import os, sys, tempfile
> +import os, sys, tempfile, urllib
>
>   class sshserver(object):
>       def __init__(self, ui, repo):
> @@ -64,6 +64,11 @@
>               success = 0
>           self.respond("%s %s\n" % (success, r))
>
> +    def do_branchmap(self):
> +        h = self.repo.branchmap()
> +        hs = ['%s %s' % (urllib.quote(b), " ".join([hex(x) for x in h[b]])) for b in h]

Looks like > 80 chars. Do the for thing here, as well, I guess?

> +        self.respond("\n".join(hs))
> +
>       def do_heads(self):
>           h = self.repo.heads()
>           self.respond(" ".join(map(hex, h)) + "\n")
> @@ -77,7 +82,7 @@
>           capabilities: space separated list of tokens
>           '''
>
> -        caps = ['unbundle', 'lookup', 'changegroupsubset']
> +        caps = ['unbundle', 'lookup', 'changegroupsubset', 'branchmap']
>           if self.ui.configbool('server', 'uncompressed'):
>               caps.append('stream=%d' % self.repo.changelog.version)
>           self.respond("capabilities: %s\n" % (' '.join(caps),))

Cheers,

Dirkjan


More information about the Mercurial-devel mailing list