# HG changeset patch
# User Matt Mackall <m...@selenic.com>
# Date 1474293900 18000
#      Mon Sep 19 09:05:00 2016 -0500
# Node ID 9c8847df32a0c5045e60aded2e03a9c97507f909
# Parent  19bf2776dfe39befdc479253e1e7d030b41c08f9
extdata: add revset support for extdata

This inserts extdata into the revset function support. Planned
extensions of extdata support arguments, so this is the most
appropriate place for it.

Unfortunately, the registrar framework is not a good fit here. First,
setting an appropriate load point is still an unsolved problem (we
want the code to live in revset.py, but that module may never be loaded).
Second, registered methods become global and the data sources are likely to be
repo-specific. This won't work well in a context like hgwebdir.

diff -r 19bf2776dfe3 -r 9c8847df32a0 mercurial/revset.py
--- a/mercurial/revset.py       Tue Sep 13 14:14:05 2016 -0500
+++ b/mercurial/revset.py       Mon Sep 19 09:05:00 2016 -0500
@@ -432,6 +432,14 @@
             return fn(repo, subset, b, order)
         return fn(repo, subset, b)
 
+    # avoid import cycle
+    from . import scmutil
+
+    # check external data sources (can't override built-ins)
+    if f in scmutil.extdatasources(repo):
+        extdata = scmutil.extdatasource(repo, f)
+        return baseset([r for r in subset if r in extdata])
+
     keep = lambda fn: getattr(fn, '__doc__', None) is not None
 
     syms = [s for (s, fn) in symbols.items() if keep(fn)]
diff -r 19bf2776dfe3 -r 9c8847df32a0 tests/test-revset.t
--- a/tests/test-revset.t       Tue Sep 13 14:14:05 2016 -0500
+++ b/tests/test-revset.t       Mon Sep 19 09:05:00 2016 -0500
@@ -3540,6 +3540,31 @@
   1
   3
 
+test extdata revset support
+
+  $ echo "[extdata]" >> .hg/hgrc
+  $ echo "filedata = file:extdata.txt" >> .hg/hgrc
+  $ echo "shelldata = shell:cat extdata.txt | grep 2" >> .hg/hgrc
+  $ echo "2" > extdata.txt
+  $ echo "3" >> extdata.txt
+
+  $ hg log -qr "filedata()"
+  2:842c8a27ccf2
+  3:b7e1eaa35f23
+  $ hg log -qr "shelldata()"
+  2:842c8a27ccf2
+
+we don't fix up relative file URLs, but we do run shell commands in repo root
+
+  $ mkdir sub
+  $ cd sub
+  $ hg log -qr "filedata()"
+  abort: error: No such file or directory
+  [255]
+  $ hg log -qr "shelldata()"
+  2:842c8a27ccf2
+  $ cd ..
+
 test error message of bad revset
   $ hg log -r 'foo\\'
   hg: parse error at 3: syntax error in revset 'foo\\'
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to