Commits

Yuya Nishihara committed f7097d0

manifestmodel: add support for fileset query

Currently it lacks GUI to display query type and error.

Comments (0)

Files changed (2)

tests/qt_manifestmodel_test.py

         self.assertTrue(m.indexFromPath('baz/box').isValid())
         self.assertFalse(m.indexFromPath('foo').isValid())
 
+    def test_name_filter_fileset(self):
+        m = self.new_model(0)
+        m.setNameFilter('relpath:foo')
+        self.assertFalse(m.indexFromPath('bar').isValid())
+        self.assertTrue(m.indexFromPath('foo').isValid())
+
+    def test_name_filter_invalid_path(self):
+        m = self.new_model(0)
+        m.setNameFilter('relpath:/foo')  # no "Abort: /foo not under root"
+        self.assertEqual(0, m.rowCount())
+
+    def test_name_filter_unparsable(self):
+        m = self.new_model(0)
+        m.setNameFilter('set:invalid_query(')  # no ParseError
+        self.assertEqual(0, m.rowCount())
+
     def test_name_filter_subrepo(self):
         m = self.new_model(3)
         m.setNameFilter('ba*')

tortoisehg/hgqt/manifestmodel.py

 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
-from mercurial import util
+from mercurial import error, util
 from mercurial import match as matchmod
 
 from tortoisehg.util import hglib
             reverse=reverse)
 
 
+# TODO: visual feedback to denote query type and error as in repofilter
 def _makematcher(repo, ctx, pat):
     cwd = ''  # always relative to repo root
     if not pat:
         return matchmod.always(repo.root, cwd)
-    pat = '**%s**' % pat
-    return matchmod.match(repo.root, cwd, [pat], default='relglob',
-                          auditor=repo.auditor, ctx=ctx)
+    if ':' not in pat and '*' not in pat:
+        # mimic partial string match
+        pat = '**%s**' % pat
+    try:
+        return matchmod.match(repo.root, cwd, [pat], default='relglob',
+                              auditor=repo.auditor, ctx=ctx)
+    except (error.Abort, error.ParseError):
+        # no match
+        return matchmod.exact(repo.root, cwd, [])
 
 
 def _maketree(e, path):