Fix bug in revid caching.
[jelmer/subvertpy.git] / logwalker.py
index 48e5921d77148e238f4a51865159846299966b26..e85bcbf5fc639b5ef7d8e8818958c05c077ec778 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""Cache of the Subversion history log."""
 
-from bzrlib.errors import NoSuchRevision, BzrError, NotBranchError
-from bzrlib.progress import DummyProgress
-from bzrlib.trace import mutter
-from bzrlib.ui import ui_factory
+from bzrlib.errors import NoSuchRevision
+import bzrlib.ui as ui
 
 import os
 
@@ -27,12 +26,7 @@ import svn.core
 
 import base64
 
-try:
-    import sqlite3
-except ImportError:
-    from pysqlite2 import dbapi2 as sqlite3
-
-shelves = {}
+from cache import sqlite3
 
 def _escape_commit_message(message):
     """Replace xml-incompatible control characters."""
@@ -100,11 +94,10 @@ class LogWalker(object):
         """
         to_revnum = max(self.last_revnum, to_revnum)
 
-        pb = ui_factory.nested_progress_bar()
+        pb = ui.ui_factory.nested_progress_bar()
 
         def rcvr(orig_paths, rev, author, date, message, pool):
             pb.update('fetching svn revision info', rev, to_revnum)
-            paths = {}
             if orig_paths is None:
                 orig_paths = {}
             for p in orig_paths:
@@ -158,7 +151,7 @@ class LogWalker(object):
 
         path = path.strip("/")
 
-        while revnum > 0:
+        while revnum >= 0:
             revpaths = self.get_revision_paths(revnum, path)
 
             if revpaths != {}:
@@ -175,7 +168,7 @@ class LogWalker(object):
                     revnum = revpaths[path][2]
                     path = revpaths[path][1]
                     continue
-            revnum-=1
+            revnum -= 1
 
     def get_revision_paths(self, revnum, path=None):
         """Obtain dictionary with all the changes in a particular revision.
@@ -207,11 +200,15 @@ class LogWalker(object):
         :param revnum: Revision number.
         :returns: Tuple with author, log message and date of the revision.
         """
-        assert revnum >= 1
+        assert revnum >= 0
+        if revnum == 0:
+            return (None, None, None)
         if revnum > self.saved_revnum:
             self.fetch_revisions(revnum)
         (author, message, date) = self.db.execute("select author, message, date from revision where revno="+ str(revnum)).fetchone()
-        return (author, _escape_commit_message(base64.b64decode(message)), date)
+        if message is not None:
+            message = _escape_commit_message(base64.b64decode(message))
+        return (author, message, date)
 
     def find_latest_change(self, path, revnum, recurse=False):
         """Find latest revision that touched path.