Patchwork [2,of,7] revset: add experimental support for extdata

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 1, 2017, noon
Message ID <2c9054ec242d781c0bda.1506859213@mimosa>
Download mbox | patch
Permalink /patch/24332/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 1, 2017, noon
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506851400 -3600
#      Sun Oct 01 10:50:00 2017 +0100
# Node ID 2c9054ec242d781c0bda1d0d0ab0b26b5b93f012
# Parent  4bcad24c850624811d6f4d1aa6d982c01270d2fd
revset: add experimental support for extdata

This is minimal and non-controversial implementation of extdata() revset.
Originally extdata sources were exposed to the symbol namespace, but I've
changed it to a plain function for simplicity.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -786,6 +786,17 @@  def contentdivergent(repo, subset, x):
     contentdivergent = obsmod.getrevs(repo, 'contentdivergent')
     return subset & contentdivergent
 
+@predicate('extdata(source)', safe=False, weight=100)
+def extdata(repo, subset, x):
+    """Changesets in the specified extdata source. (EXPERIMENTAL)"""
+    # i18n: "extdata" is a keyword
+    args = getargsdict(x, 'extdata', 'source')
+    source = getstring(args.get('source'),
+                       # i18n: "extdata" is a keyword
+                       _('extdata takes at least 1 string argument'))
+    data = scmutil.extdatasource(repo, source)
+    return subset & baseset(data)
+
 @predicate('extinct()', safe=True)
 def extinct(repo, subset, x):
     """Obsolete changesets with obsolete descendants only.
diff --git a/tests/test-extdata.t b/tests/test-extdata.t
new file mode 100644
--- /dev/null
+++ b/tests/test-extdata.t
@@ -0,0 +1,56 @@ 
+  $ hg init repo
+  $ cd repo
+  $ for n in 0 1 2 3; do
+  >   echo $n > $n
+  >   hg ci -qAm $n
+  > done
+
+test revset support
+
+  $ cat <<'EOF' >> .hg/hgrc
+  > [extdata]
+  > filedata = file:extdata.txt
+  > shelldata = shell:cat extdata.txt | grep 2
+  > EOF
+  $ cat <<'EOF' > extdata.txt
+  > 2
+  > 3
+  > EOF
+
+  $ hg log -qr "extdata(filedata)"
+  2:f6ed99a58333
+  3:9de260b1e88e
+  $ hg log -qr "extdata(shelldata)"
+  2:f6ed99a58333
+
+test weight of extdata() revset
+
+  $ hg debugrevspec -p optimized "extdata(filedata) & 3"
+  * optimized:
+  (andsmally
+    (func
+      (symbol 'extdata')
+      (symbol 'filedata'))
+    (symbol '3'))
+  3
+
+test bad extdata() revset source
+
+  $ hg log -qr "extdata()"
+  hg: parse error: extdata takes at least 1 string argument
+  [255]
+  $ hg log -qr "extdata(unknown)"
+  abort: unknown extdata source 'unknown'
+  [255]
+
+we don't fix up relative file URLs, but we do run shell commands in repo root
+
+  $ mkdir sub
+  $ cd sub
+  $ hg log -qr "extdata(filedata)"
+  abort: error: No such file or directory
+  [255]
+  $ hg log -qr "extdata(shelldata)"
+  2:f6ed99a58333
+
+  $ cd ..