<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 22, 2016 at 11:21 AM, Matt Mackall <span dir="ltr"><<a href="mailto:mpm@selenic.com" target="_blank">mpm@selenic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Matt Mackall <<a href="mailto:mpm@selenic.com">mpm@selenic.com</a>><br>
# Date 1473794045 18000<br>
# Tue Sep 13 14:14:05 2016 -0500<br>
# Node ID 19bf2776dfe39befdc479253e1e7d0<wbr>30b41c08f9<br>
# Parent 5271ae66615207f39cc41d78f4541b<wbr>c6f8ca6ff6<br>
extdata: add extdatasource reader<br>
<br>
This adds basic support for extdata, a way to add external data<br>
sources for revsets and templates. An extdata data source is simply a<br>
list of lines of the form:<br>
<br>
<revision identifier>[<space><freeform text>]\n<br>
<br>
An extdata source is configured thusly:<br>
<br>
[extdata]<br>
name = <a url or path><br></blockquote><div><br></div><div>I like "extdata" for internal terminology but I have hesitations about using an abbreviation in the user-facing config. How about [externaldata]? Or perhaps something more generic like [datasource(s)]?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
urls of the form shell: are launch shell commands to generate data.<br>
<br>
diff -r 5271ae666152 -r 19bf2776dfe3 mercurial/scmutil.py<br>
--- a/mercurial/scmutil.py Wed Sep 21 17:05:27 2016 -0400<br>
+++ b/mercurial/scmutil.py Tue Sep 13 14:14:05 2016 -0500<br>
@@ -29,6 +29,7 @@<br>
phases,<br>
revset,<br>
similar,<br>
+ url,<br>
util,<br>
)<br>
<br>
@@ -1418,3 +1419,66 @@<br>
return<br>
<br>
self._queue.put(fh, block=True, timeout=None)<br>
+<br>
+def extdatasources(repo):<br>
+ sources = set()<br>
+ for k, v in repo.ui.configitems("extdata")<wbr>:<br>
+ sources.add(k)<br>
+ return sources<br>
+<br>
+def extdatasource(repo, source):<br>
+ """gather a map of rev -> value dict from the specified source<br>
+<br>
+ A source spec is treated as a URL, with a special case shell: type<br>
+ for parsing the output from a shell command.<br>
+<br>
+ The data is parsed as a series of newline-separated records where<br>
+ each record is a revision specifier optionally followed by a space<br>
+ and a freeform string value. If the revision is known locally, it<br>
+ is converted to a rev, otherwise the record is skipped.<br>
+<br>
+ Note that both key and value are treated as UTF-8 and converted to<br>
+ the local encoding. This allows uniformity between local and<br>
+ remote data sources.<br>
+ """<br>
+<br>
+ spec = repo.ui.config("extdata", source)<br>
+ if not spec:<br>
+ raise util.Abourt(_("unknown extdata source '%s'") % source)<br>
+<br>
+ try:<br>
+ # prepare for future expansion<br>
+ expand = spec % ()<br>
+ except TypeError:<br>
+ raise error.Abort(_("extdata doesn't support parameters yet"),<br>
+ hint=_("use double % for escaping"))<br>
+<br>
+ data = {}<br>
+ if spec.startswith("shell:"):<br>
+ # external commands should be run relative to the repo root<br>
+ cmd = spec[6:]<br>
+ cwd = os.getcwd()<br>
+ os.chdir(repo.root)<br>
+ try:<br>
+ src = util.popen(cmd)<br>
+ finally:<br>
+ os.chdir(cwd)<br>
+ else:<br>
+ # treat as a URL or file<br>
+ src = url.open(repo.ui, spec)<br>
+<br>
+ try:<br>
+ for l in src.readlines():<br>
+ if " " in l:<br>
+ k, v = l.strip().split(" ", 1)<br>
+ else:<br>
+ k, v = l.strip(), ""<br>
+<br>
+ k = encoding.tolocal(k)<br>
+ if k in repo:<br>
+ # we ignore data for nodes that don't exist locally<br>
+ data[repo[k].rev()] = encoding.tolocal(v)<br>
+ finally:<br>
+ src.close()<br>
+<br>
+ return data<br>
______________________________<wbr>_________________<br>
Mercurial-devel mailing list<br>
<a href="mailto:Mercurial-devel@mercurial-scm.org">Mercurial-devel@mercurial-scm.<wbr>org</a><br>
<a href="https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel" rel="noreferrer" target="_blank">https://www.mercurial-scm.org/<wbr>mailman/listinfo/mercurial-<wbr>devel</a><br>
</blockquote></div><br></div></div>