Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

manifestmodel: implement status filter

Changeset 4d01e3429b22

Parent ce4a25274848

by Yuya Nishihara

Changes to 3 files · Browse files at 4d01e3429b22 Showing diff from parent ce4a25274848 Diff from another changeset...

 
16
17
18
19
 
20
21
 
22
 
 
 
 
 
23
24
 
 
 
16
17
18
 
19
20
 
21
22
23
24
25
26
27
28
29
30
31
@@ -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
55
56
 
57
58
59
 
62
63
64
 
65
66
67
 
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
57
58
59
60
 
63
64
65
66
67
68
69
 
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@@ -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
14
15
 
16
17
18
 
30
31
32
 
33
34
35
 
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
89
 
96
97
98
 
99
100
 
 
 
 
 
 
 
 
 
 
 
 
101
 
 
 
102
103
104
 
13
14
15
16
17
18
19
 
31
32
33
34
35
36
37
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
113
114
115
116
117
 
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@@ -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: