Commits

Anonymous committed 9623ea3

display file data (diffs) again but cache them

  • Participants
  • Parent commits f831799
  • Branches cache

Comments (0)

Files changed (5)

File tortoisehg/hgqt/filelistview.py

 
     def layoutChanged(self):
         'file model has new contents'
-        #print "HgFileListView.layoutChanged() begin, time=", time.time()
+	print "[filelistview|layoutChanged] enter time=", time.time(), "self=", self
         index = self.currentIndex()
-        #print "HgFileListView.layoutChanged() #1, time=", time.time()
         count = len(self.model())
-        #print "[layoutChanged] index.row()=", index.row(), "index.column()=", index.column(), "count=", count
-        #print "HgFileListView.layoutChanged() #2, time=", time.time()
-        if index.row() >= 0:
-            self.clearSelection()
-            self.clearDisplay.emit()
-        #print "HgFileListView.layoutChanged() end, time=", time.time()
+        if index.row() == -1:
+            # index is changing, onRowChange() called for us
+            self.selectRow(0)
+        elif index.row() >= count:
+            if count:
+                # index is changing, onRowChange() called for us
+                self.selectRow(count-1)
+            else:
+                self.clearDisplay.emit()
+        else:
+            # redisplay previous row
+            self.onRowChange(index)
+	print "[filelistview|layoutChanged] leave time=", time.time(), "self=", self
+
 
     def onRowChange(self, index, *args):
-        #print "HgFileListView.onRowChange()"
+    	print "[filelistview|onRowChange] enter time=", time.time()
         if index is None:
             index = self.currentIndex()
         data = self.model().dataFromIndex(index)
+	print "[filelistview|onRowChange] data=", data
         if data:
             self.fileSelected.emit(hglib.tounicode(data['path']), data['status'])
         else:
             self.clearDisplay.emit()
+    	print "[filelistview|onRowChange] leave time=", time.time()
 
     def resizeEvent(self, event):
         if self.model() is not None:

File tortoisehg/hgqt/fileview.py

 import os
 import difflib
 import re
+import time
+import binascii
+import tortoisehg.util.cache
 
 from mercurial import error, util
 
         else:
             self.actionAnnMode.setChecked(True)
 
+
     def setContext(self, ctx, ctx2=None):
+        print "[fileview|setContext] ctx=", ctx, "ctx2=", ctx2, "enter time=", time.time()
+
         self._ctx = ctx
         self._ctx2 = ctx2
         self.sci.setTabWidth(ctx._repo.tabwidth)
         self.actionPrevDiff.setEnabled(False)
 
     def displayFile(self, filename=None, status=None):
+        print "[fileview|displayFile] enter time=", time.time()
         if isinstance(filename, (unicode, QString)):
             filename = hglib.fromunicode(filename)
             status = hglib.fromunicode(status)
         self._diffs = []
         if filename is None:
             self.restrictModes(False, False, False)
+            print "[fileview|displayFile] leave1 time=", time.time()
             return
 
         if self._ctx2:
             ctx2 = self._ctx.p1()
         else:
             ctx2 = self._ctx.p2()
-        fd = filedata.FileData(self._ctx, ctx2, filename, status)
+        print "[fileview|displayFile] *0 time=", time.time()
+        cache_key = tortoisehg.util.cache.gen_cache_key(ctx2, self._ctx, filename, status);
+        print "[fileview|displayFile] cache_key=", cache_key
+        print "[fileview|displayFile] *1 time=", time.time()
+
+        if cache_key:
+            cache = tortoisehg.util.cache.the_cache
+            cache.lock()
+            try:
+                fd = cache.get(cache_key)
+                cache_hit = True
+            except KeyError:
+                fd = filedata.FileData(self._ctx, ctx2, filename, status)
+                cache.set(cache_key, fd)
+                cache_hit = False
+            cache.unlock()
+
+        else:
+            fd = filedata.FileData(self._ctx, ctx2, filename, status)
+
+        if cache_key:
+            if cache_hit:
+                print "[fileview|displayFile] [hit!] *2 time=", time.time()
+            else:
+                print "[fileview|displayFile] [MISS] *2 time=", time.time()
+        else:
+                print "[fileview|displayFile] [not cached] *2 time=", time.time()
 
         if fd.elabel:
             self.extralabel.setText(fd.elabel)
             self.sci.setMarginWidth(1, 0)
             self.blk.setVisible(False)
             self.restrictModes(False, False, False)
+            print "[fileview|displayFile] leave2 time=", time.time()
             return
 
         candiff = bool(fd.diff)
                 self.blk.setVisible(self._mode != DiffMode)
                 self.sci.setAnnotationEnabled(self._mode == AnnMode)
 
+        print "[fileview|displayFile] *3 time=", time.time()
         if self._mode == DiffMode:
             self.sci.setMarginWidth(1, 0)
             lexer = lexers.get_diff_lexer(self)
             self.sci.setFont(qtlib.getfont('fontlog').font())
             self.sci.setMarginWidth(1, 0)
             self.blk.setVisible(False)
+            print "[fileview|displayFile] leave3 time=", time.time()
             return
         elif fd.contents:
             lexer = lexers.get_lexer(filename, fd.contents, self)
             if self._mode == AnnMode:
                 self.sci._updateannotation(self._ctx, filename)
         else:
+            print "[fileview|displayFile] leave4 time=", time.time()
             return
+        print "[fileview|displayFile] *4 time=", time.time()
 
         # Recover the last scroll position
         # Make sure that lastScrollPosition never exceeds the amount of
             self.timer.start()
         self.actionNextDiff.setEnabled(bool(self._diffs))
         self.actionPrevDiff.setEnabled(bool(self._diffs))
+        print "[fileview|displayFile] leave5 time=", time.time()
 
     #
     # These four functions are used by Shift+Cursor actions in revdetails

File tortoisehg/hgqt/revdetails.py

 # of the GNU General Public License, incorporated herein by reference.
 
 import os
+import time
 
 from mercurial import commands, util
 
     def __init__(self, repo, parent):
         QWidget.__init__(self, parent)
 
-	print "RevDetailsWidget: repo=", repo, " repo[None]=", repo[None]
+        print "[revdetails|RevDetailsWidget] repo=", repo, " repo[None]=", repo[None]
         self.repo = repo
         self.ctx = repo[None]
         self.splitternames = []
             self._actions[name] = act
             self.addAction(act)
 
+
     def onRevisionSelected(self, rev):
         'called by repowidget when repoview changes revisions'
-	#print "onRevisionSelected() rev=", rev
+        print "[revdetails|onRevisionSelected] enter rev=", rev, " time=", time.time()
         self.ctx = ctx = self.repo.changectx(rev)
+
         self.revpanel.set_revision(rev)
         self.revpanel.update(repo = self.repo)
         self.message.setHtml('<pre>%s</pre>'
         self.actionShowAllMerge.setEnabled(len(ctx.parents()) == 2)
         self.fileview.setContext(ctx)
         self.filelist.setContext(ctx)
+        print "[revdetails|onRevisionSelected] leave rev=", rev, " time=", time.time()
 
     @pyqtSlot()
     def _updatedeschtmlizer(self):

File tortoisehg/hgqt/thgrepo.py

             c) return a patchctx if changeid is an absolute patch path
             '''
 
-            #print "thgrepository.changectx() changeid=", changeid      # zzz
-
             # Mercurial's standard changectx() (rather, lookup())
             # implies that tags and branch names live in the same namespace.
             # This code throws patch names in the same namespace, but as
             time0 = time.time()
             parent = self.parents()[whichparent]
             pn = parent.node()
+            cache_key = tortoisehg.util.cache.gen_cache_key(parent, self)
             if not pn:
                 pn = '\0'
             sn = self.node()
             if not sn:
                 sn = '\0'
-            cache_key = binascii.hexlify(pn) + "::" + binascii.hexlify(sn)
+            cache_key_old = binascii.hexlify(pn) + "::" + binascii.hexlify(sn)
+            assert cache_key == cache_key_old or cache_key == None and (not parent.node() or not self.node())
 
             cache = tortoisehg.util.cache.the_cache
             cache.lock()
             local_count = _count
             _count += 1
-            cache_hit = None
+            cache_hit = False
             cache_len = len(cache)
             if parent.node() and self.node():
                 try:
             else:
                 r = self._repo.status(parent.node(), self.node())[:3]
 
-            if cache_hit:
-                hitmiss = "hit!"
-            else:
-                hitmiss = "MISS"
-
-            print "[changesToParent", str(local_count), hitmiss + "]", \
+            hitmiss = "hit" if cache_hit else "MISS"
+            print "[thgrepo|changesToParent", str(local_count), hitmiss + "]", \
             binascii.hexlify(pn) + "::" + binascii.hexlify(sn), "time:", \
             time.time() - time0
 

File tortoisehg/util/cache.py

 import pickle
 import shelve
 import threading
+import binascii
+
+
+def gen_cache_key(parent_ctx, self_ctx, path = None, status = None):
+
+    pn = parent_ctx.node()
+    sn = self_ctx.node()
+
+    if not pn or not sn:
+        return None
+
+    cache_key = binascii.hexlify(pn) + "::" + binascii.hexlify(sn)
+
+    if path:
+        cache_key += ":"
+        cache_key += path
+
+    if status:
+        cache_key += ":"
+        cache_key += status
+
+    return cache_key
+
 
 
 class cache: