Commits

Yuya Nishihara  committed 1818b7a

manifestmodel: manage root ctx in the same way as subrepos

Now displayFile() does not need to handle main repository differently.

  • Participants
  • Parent commits 9a41a57

Comments (0)

Files changed (3)

File tests/qt_manifestmodel_test.py

 
     def test_rawfctx(self):
         m = self.new_model(5)
-        self.check_rawfctx(m, 'foo', None, 'foo')
-        self.check_rawfctx(m, 'sub', None, 'sub')
+        self.check_rawfctx(m, 'foo', 5, 'foo')
+        self.check_rawfctx(m, 'sub', 5, 'sub')
         self.check_rawfctx(m, 'sub/foo', 2, 'foo')
         self.check_rawfctx(m, 'sub/baz/bax', 2, 'baz/bax')
         self.check_rawfctx(m, 'sub/invalid', None, '')

File tortoisehg/hgqt/manifestdialog.py

     def displayFile(self):
         index = self._treeview.currentIndex()
         ctx, path = self._treemodel.fileSubrepoCtx(index)
-        if ctx is None:
-            ctx = self._repo[self._rev]
+        if not ctx:
+            return
         self._fileview.setContext(ctx)
         self._fileview.displayFile(path, self.status)
 

File tortoisehg/hgqt/manifestmodel.py

 
         return index.internalPointer().path
 
+    # TODO: this API is tricky; should be redesigned with fileview.setContext
     def fileSubrepoCtx(self, index):
-        """Return the subrepo context of the specified index"""
+        """Return the changectx of the specified index"""
         if not index.isValid():
             return None, ''
 
         f = index.internalPointer()
         e = f.parent
-        while e.parent and e.status != 'S':
+        while e and e.ctx is None:
             e = e.parent
+        assert e, 'root entry must have ctx'
         return e.ctx, f.path[len(e.path):].lstrip('/')
 
     def subrepoType(self, index):
                     e.status = 'C'
 
         # Add subrepos to the tree
-        def addrepocontentstotree(roote, ctx):
+        def addrepocontentstotree(roote):
+            ctx = roote.ctx
             for path, substate in ctx.substate.iteritems():
                 if not 'S' in self._statusfilter:
                     break
                     if srev and isinstance(sub, subrepo.hgsubrepo):
                         srepo = sub._repo
                         if srev in srepo:
-                            e.ctx = sctx = srepo[srev]
+                            e.ctx = srepo[srev]
                             # Add the subrepo contents to the tree
-                            e = addrepocontentstotree(e, sctx)
+                            e = addrepocontentstotree(e)
 
             # Add regular files to the tree
             status, uncleanpaths, files = getctxtreeinfo(ctx)
             return roote
 
         roote = _Entry()
-        ctx = self._repo[self._rev]
-
-        addrepocontentstotree(roote, ctx)
+        roote.ctx = self._repo[self._rev]
+        addrepocontentstotree(roote)
         roote.sort()
         return roote