[PATCH 1 of 5] extdata: add extdatasource reader

Yuya Nishihara yuya at tcha.org
Sun Sep 25 11:39:14 EDT 2016


On Sat, 24 Sep 2016 17:34:20 -0500, Matt Mackall wrote:
> On Sat, 2016-09-24 at 10:17 +0900, Yuya Nishihara wrote:
> > On Thu, 22 Sep 2016 13:21:35 -0500, Matt Mackall wrote:
> > > 
> > > # HG changeset patch
> > > # User Matt Mackall <mpm at selenic.com>
> > > # Date 1473794045 18000
> > > #      Tue Sep 13 14:14:05 2016 -0500
> > > # Node ID 19bf2776dfe39befdc479253e1e7d030b41c08f9
> > > # Parent  5271ae66615207f39cc41d78f4541bc6f8ca6ff6
> > > extdata: add extdatasource reader
> > > 
> > > +def extdatasource(repo, source):
> > > +    """gather a map of rev -> value dict from the specified source
> > > +
> > > +    A source spec is treated as a URL, with a special case shell: type
> > > +    for parsing the output from a shell command.
> > > +
> > > +    The data is parsed as a series of newline-separated records where
> > > +    each record is a revision specifier optionally followed by a space
> > > +    and a freeform string value. If the revision is known locally, it
> > > +    is converted to a rev, otherwise the record is skipped.
> > > +
> > > +    Note that both key and value are treated as UTF-8 and converted to
> > > +    the local encoding. This allows uniformity between local and
> > > +    remote data sources.
> > > +    """
> > > +
> > > +    spec = repo.ui.config("extdata", source)
> > > +    if not spec:
> > > +        raise util.Abourt(_("unknown extdata source '%s'") % source)
> > > +
> > > +    try:
> > > +        # prepare for future expansion
> > > +        expand = spec % ()
> > > +    except TypeError:
> > > +        raise error.Abort(_("extdata doesn't support parameters yet"),
> > > +                          hint=_("use double % for escaping"))
> > Using '%' as a parameter symbol would be a bit unfortunate since URLs have
> > %HEX-escape syntax. How about using '$' or '{...}' ?
> 
> I picked it because it's how Firefox search URLs work. Was in my RFC.

It appears that Firefox uses '{}' these days. I remember '%' was used in
old Firefox (or maybe Netscape) though.

https://developer.mozilla.org/en/Add-ons/Creating_OpenSearch_plugins_for_Firefox

> > > +            os.chdir(cwd)
> > Temporary chdir() may cause problems in hgweb, which can be threaded.
> 
> True. But we've had the same problem with hooks for a decade.

Hooks are run by subprocess, so only child process will chdir to repo.root.


More information about the Mercurial-devel mailing list