1. TortoiseHg
  2. TortoiseHg
  3. thg

Commits

Yuya Nishihara  committed 03439f6

manifestmodel: store subrepo ctx in tree node for easier lookup

  • Participants
  • Parent commits 07a6d0e
  • Branches default

Comments (0)

Files changed (1)

File tortoisehg/hgqt/manifestmodel.py

View file
  • Ignore whitespace
         self._fileiconprovider = QFileIconProvider()
         self._repo = repo
         self._rev = rev
-        self._subinfo = {}
 
         self._namefilter = namefilter
         assert util.all(c in 'MARSC' for c in statusfilter)
 
     def fileSubrepoCtx(self, index):
         """Return the subrepo context of the specified index"""
-        path = self.filePath(index)
-        if not path:
-            return None, path
-        for subpath in sorted(self._subinfo.keys())[::-1]:
-            if path.startswith(subpath + '/'):
-                return self._subinfo[subpath]['ctx'], path[len(subpath)+1:]
-        return None, path
+        if not index.isValid():
+            return None, ''
+
+        f = index.internalPointer()
+        e = f.parent
+        while e.parent and e.status != 'S':
+            e = e.parent
+        return e.ctx, f.path[len(e.path):].lstrip('/')
 
     def subrepoType(self, index):
         """Return the subrepo type the specified index"""
                 # to the status filter
                 abspath = os.path.join(ctx._repo.root, path)
                 if os.path.isdir(abspath):
-                    # Add the subrepo info to the _subinfo dictionary:
-                    # The value is the subrepo context, while the key is
-                    # the path of the subrepo relative to the topmost repo
                     if toproot:
                         # Note that we cannot use os.path.join() because we
                         # need path items to be separated by "/"
                     else:
                         toprelpath = path
                     toprelpath = util.pconvert(toprelpath)
-                    self._subinfo[toprelpath] = {'ctx': None}
                     srev = substate[1]
                     sub = ctx.sub(path)
                     if srev and isinstance(sub, subrepo.hgsubrepo):
                         srepo = sub._repo
                         if srev in srepo:
-                            sctx = srepo[srev]
-
-                            self._subinfo[toprelpath]['ctx'] = sctx
-
+                            e.ctx = sctx = srepo[srev]
                             # Add the subrepo contents to the tree
                             e = addrepocontentstotree(e, sctx, toprelpath)
 
             addfilestotree(roote, files, status, uncleanpaths)
             return roote
 
-        # Clear the _subinfo
-        self._subinfo = {}
         roote = _Entry()
         ctx = self._repo[self._rev]
 
 class _Entry(object):
     """Each file or directory"""
 
-    __slots__ = ('_name', '_parent', 'status', 'subkind', 'icon',
+    __slots__ = ('_name', '_parent', 'status', 'ctx', 'subkind', 'icon',
                  '_child', '_nameindex')
 
     def __init__(self, name='', parent=None):
         self._name = name
         self._parent = parent
         self.status = None
+        self.ctx = None
         self.subkind = None
         self.icon = None
         self._child = {}