Changeset 4d01e3429b22…
Parent ce4a25274848…
by
Changes to 3 files · Browse files at 4d01e3429b22 Showing diff from parent ce4a25274848 Diff from another changeset...
@@ -16,9 +16,16 @@ # HG changeset patch
# User test
# Date 0 0
-# Node ID afe200a5ace85bc58771d0a606eb624fba545238
+# Node ID 8651fa2fe75d6fdaec4a477fb29a88f7dc97a7e2
# Parent 5b65a3d842610f25b192d26e3dc9161ff53208d0
-remove baz/box
+remove baz/box, add zzz, modify bar
+diff --git a/bar b/bar
+--- a/bar
++++ b/bar
+@@ -0,0 +1,1 @@
++hello
diff --git a/baz/box b/baz/box
deleted file mode 100644
+diff --git a/zzz b/zzz
+new file mode 100644
|
@@ -54,6 +54,7 @@
def test_removed_should_be_listed():
m = newmodel(rev=1)
+ m.setStatusFilter('MARC')
assert m.indexFromPath('baz/box').isValid()
def test_status_role():
@@ -62,6 +63,7 @@ role=ManifestModel.StatusRole))
m = newmodel(rev=1)
+ m.setStatusFilter('MARC')
assert_equals('C', m.data(m.indexFromPath('foo'),
role=ManifestModel.StatusRole))
assert_equals('R', m.data(m.indexFromPath('baz/box'),
@@ -71,3 +73,53 @@ m = newmodel()
assert_equals(None, m.data(QModelIndex(),
role=ManifestModel.StatusRole))
+
+def test_status_filter_modified():
+ m = newmodel(rev=1)
+ m.setStatusFilter('M')
+ assert_not_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_equals(QModelIndex(), m.indexFromPath('zzz')) # added
+ assert_equals(QModelIndex(), m.indexFromPath('baz/box')) # removed
+ assert_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+def test_status_filter_added():
+ m = newmodel(rev=1)
+ m.setStatusFilter('A')
+ assert_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_not_equals(QModelIndex(), m.indexFromPath('zzz')) # added
+ assert_equals(QModelIndex(), m.indexFromPath('baz/box')) # removed
+ assert_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+def test_status_filter_removed():
+ m = newmodel(rev=1)
+ m.setStatusFilter('R')
+ assert_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_equals(QModelIndex(), m.indexFromPath('zzz')) # added
+ assert_not_equals(QModelIndex(), m.indexFromPath('baz/box')) # removed
+ assert_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+def test_status_filter_clean():
+ m = newmodel(rev=1)
+ m.setStatusFilter('C')
+ assert_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_equals(QModelIndex(), m.indexFromPath('zzz')) # added
+ assert_equals(QModelIndex(), m.indexFromPath('baz/box')) # removed
+ assert_not_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+def test_status_filter_change():
+ m = newmodel(rev=1)
+ m.setStatusFilter('C')
+ assert_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_not_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+ m.setStatusFilter('M')
+ assert_not_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_equals(QModelIndex(), m.indexFromPath('foo')) # clean
+
+def test_status_filter_multi():
+ m = newmodel(rev=1)
+ m.setStatusFilter('MC')
+ assert_not_equals(QModelIndex(), m.indexFromPath('bar')) # modified
+ assert_equals(QModelIndex(), m.indexFromPath('zzz')) # added
+ assert_equals(QModelIndex(), m.indexFromPath('baz/box')) # removed
+ assert_not_equals(QModelIndex(), m.indexFromPath('foo')) # clean
|
@@ -13,6 +13,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import *
+from mercurial import util
from tortoisehg.hgqt import qtlib
class ManifestModel(QAbstractItemModel):
@@ -30,6 +31,7 @@
self._repo = repo
self._rev = rev
+ self._statusfilter = 'MAC'
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
@@ -84,6 +86,21 @@ def columnCount(self, parent=QModelIndex()):
return 1
+ @pyqtSlot(str)
+ def setStatusFilter(self, status):
+ """Filter file tree by change status 'MARC'"""
+ status = str(status)
+ assert util.all(c in 'MARC' for c in status)
+ if self._statusfilter == status:
+ return # for performance reason
+ self._statusfilter = status
+ self._buildrootentry()
+
+ @property
+ def statusFilter(self):
+ """Return the current status filter"""
+ return self._statusfilter
+
@property
def _rootentry(self):
try:
@@ -96,9 +113,24 @@ """Rebuild the tree of files and directories"""
roote = _Entry()
ctx = self._repo[self._rev]
+
status = dict(zip(('M', 'A', 'R'),
- self._repo.status(ctx.parents()[0], ctx)[:3]))
+ (set(a) for a in self._repo.status(ctx.parents()[0],
+ ctx)[:3])))
+ uncleanpaths = status['M'] | status['A'] | status['R']
+ def pathinstatus(path):
+ """Test path is included by the status filter"""
+ if util.any(c in self._statusfilter and path in e
+ for c, e in status.iteritems()):
+ return True
+ if 'C' in self._statusfilter and path not in uncleanpaths:
+ return True
+ return False
+
for path in itertools.chain(ctx.manifest(), status['R']):
+ if not pathinstatus(path):
+ continue
+
e = roote
for p in path.split('/'):
if not p in e:
|
Loading...