[PATCH remotenames-ext] topic: added filter options for remote bookmarks

Kulikovsky Dmitry crazy.format at gmail.com
Fri Sep 8 15:55:12 UTC 2017


# HG changeset patch
# User Dmitry Kulikovsky <dkulikovsky at fb.com>
# Date 1504882133 -3600
#      Fri Sep 08 15:48:53 2017 +0100
# Node ID a252749c2c391c3c22d8bdc745be26673a60054b
# Parent  5289a6772ae59a8da42c75c508152997fcc1bb1a
topic: added filter options for remote bookmarks

Summary:
added simple regex filter options for remote bookmarks.
New options are:
 includefilter - include only expression
 excludefilter - regex to filter out unwanted bookmarks
Should be placed in hgrc.
If hg failed to compile regexp expression it will crush with error.
Works only with remote bookmarks, doesn't affect local.
Added corresponding test, as a separate file.

Test Plan:
 - run-tests.py test-remotenames-bookmarks-filter.t
 - make tests
 - local tests with bookmarks

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -1330,6 +1330,15 @@
     repo = repo.unfiltered()
     useformatted = repo.ui.formatted()
 
+    opts = {}
+    incfilter = ui.config('remotenames', 'includefilter')
+    exfilter = ui.config('remotenames', 'excludefilter')
+    if incfilter:
+        opts.update({'include': ['re:'+incfilter]})
+    if exfilter:
+        opts.update({'exclude': ['re:'+exfilter]})
+    m = scmutil.match(repo[None], [], opts)
+
     for name in sorted(ns.listnames(repo)):
         nodes = ns.nodes(repo, name)
         if not nodes:
@@ -1339,6 +1348,9 @@
         ctx = repo[node]
         fm.startitem()
 
+        if not m(name):
+            continue
+
         if not ui.quiet:
             fm.plain('   ')
 
diff --git a/tests/test-remotenames-bookmarks-filter.t b/tests/test-remotenames-bookmarks-filter.t
new file mode 100644
--- /dev/null
+++ b/tests/test-remotenames-bookmarks-filter.t
@@ -0,0 +1,73 @@
+  > echo "[extensions]" >> $HGRCPATH
+  > echo "remotenames=`dirname $TESTDIR`/remotenames.py" >> $HGRCPATH
+
+  > mkcommitwithbookmark()
+  > {
+  >    echo $1 > $1
+  >    hg bookmark "bookmark-$1"
+  >    hg add $1
+  >    hg ci -m "add $1"
+  > }
+
+Test that remotenames works on a repo without any names file
+
+  $ hg init alpha
+  $ cd alpha
+  $ mkcommitwithbookmark a-alpha
+  $ mkcommitwithbookmark b-alpha
+  $ cd ../
+  $ cp -R alpha beta
+  $ hg clone alpha gamma
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd gamma
+  $ sed -e "/\[paths\]/a beta = $TESTTMP/beta" .hg/hgrc > hgrc.tmp
+  $ cp hgrc.tmp .hg/hgrc
+
+All repositories are set and now there are bookmarks from all servers
+
+  $ hg pull beta
+  pulling from $TESTTMP/beta (glob)
+  searching for changes
+  no changes found
+  $ hg bookmarks --remote
+     beta/bookmark-a-alpha     0:40333174d575
+     beta/bookmark-b-alpha     1:906ccf7c7dfa
+     default/bookmark-a-alpha  0:40333174d575
+     default/bookmark-b-alpha  1:906ccf7c7dfa
+
+Check include and exclude filters
+
+  $ echo "[remotenames]" >> .hg/hgrc
+
+Backup current hgrc to simplify upcoming tests
+
+  $ cp .hg/hgrc hgrc.bak
+
+Run series of test for includefilter and excludefilter
+  $ echo "includefilter=.*a-alpha.*" >> .hg/hgrc
+  $ hg bookmarks --remote
+     beta/bookmark-a-alpha     0:40333174d575
+     default/bookmark-a-alpha  0:40333174d575
+
+  $ cp hgrc.bak .hg/hgrc
+  $ echo "excludefilter=.*a-alpha.*" >> .hg/hgrc
+  $ hg bookmarks --remote
+     beta/bookmark-b-alpha     1:906ccf7c7dfa
+     default/bookmark-b-alpha  1:906ccf7c7dfa
+
+Test failing filters
+
+Backup current hgrc
+  $ cp hgrc.bak .hg/hgrc
+  $ echo "includefilter=abc[" >> .hg/hgrc
+  $ hg bookmarks --remote
+  abort: invalid pattern (re): abc[
+  [255]
+
+Restore previous hgrc file and add broken filter for excludefilter
+  $ cp hgrc.bak .hg/hgrc
+  $ echo "excludefilter=abc(" >> .hg/hgrc
+  $ hg bookmarks --remote
+  abort: invalid pattern (re): abc(
+  [255]


More information about the Mercurial-devel mailing list