Rev 430: Start working on revision id map. in file:///home/jelmer/bzr-svn/customrevids/
Jelmer Vernooij
jelmer at samba.org
Thu May 17 00:01:22 BST 2007
At file:///home/jelmer/bzr-svn/customrevids/
------------------------------------------------------------
revno: 430
revision-id: jelmer at samba.org-20070516230120-uuh3vny3euhn152h
parent: jelmer at samba.org-20070516134309-1kmi1dajlhf8rf01
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: customrevids
timestamp: Thu 2007-05-17 00:01:20 +0100
message:
Start working on revision id map.
added:
BRANCH.TODO branch.todo-20070516183134-f9xjfbsv6x6u6x2t-1
tests/test_revids.py test_revids.py-20070516230044-d7x872cqi7xb4eow-1
modified:
repository.py repository.py-20060306123302-1f8c5069b3fe0265
revids.py revids.py-20070416220458-36vfa0730cchevp1-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
=== added file 'BRANCH.TODO'
--- a/BRANCH.TODO 1970-01-01 00:00:00 +0000
+++ b/BRANCH.TODO 2007-05-16 23:01:20 +0000
@@ -0,0 +1,14 @@
+- keep revision id cache:
+(revid, path, revnum, scheme)
+
+- Repository.generate_revision_id() should return
+- Branch.generate_revision_id()
+- Repository.parse_revision_id() looks up custom revision ids
+- Branch.parse_revision_id() looks up custom revision ids
+ - Try to parse revision id. If:
+ - UUID matches
+ - path,revnum combination is in the branches' history
+ return path,revnum combination
+ - Check the bzr:revision-id-vX property in the
+ the latest revision in which this branch existed. If it
+ contains the revision, return it
=== added file 'tests/test_revids.py'
--- a/tests/test_revids.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_revids.py 2007-05-16 23:01:20 +0000
@@ -0,0 +1,34 @@
+# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# 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
+
+from bzrlib.errors import NoSuchRevision
+from bzrlib.repository import Repository
+
+from revids import RevidMap
+from tests import TestCaseWithSubversionRepository
+
+class TestRevidMap(TestCaseWithSubversionRepository):
+ def test_create(self):
+ repos_url = self.make_client("a", "dc")
+ repos = Repository.open(repos_url)
+ revidmap = RevidMap(repos)
+
+ def test_lookup_revid_nonexistant(self):
+ repos_url = self.make_client("a", "dc")
+ repos = Repository.open(repos_url)
+ revidmap = RevidMap(repos)
+ self.assertRaises(NoSuchRevision, lambda: revidmap.lookup_revid("bla"))
+
=== modified file 'repository.py'
--- a/repository.py 2007-05-16 13:43:09 +0000
+++ b/repository.py 2007-05-16 23:01:20 +0000
@@ -372,7 +372,7 @@
raise NotImplementedError(self.fileid_involved_by_set)
def generate_revision_id(self, revnum, path):
- """Generate a unambiguous revision id.
+ """Generate an unambiguous revision id.
:param revnum: Subversion revision number.
:param path: Branch path.
=== modified file 'revids.py'
--- a/revids.py 2007-05-16 13:43:09 +0000
+++ b/revids.py 2007-05-16 23:01:20 +0000
@@ -22,6 +22,11 @@
import urllib
+try:
+ import sqlite3
+except ImportError:
+ from pysqlite2 import dbapi2 as sqlite3
+
def escape_svn_path(x):
if isinstance(x, unicode):
x = x.encode("utf-8")
@@ -71,3 +76,28 @@
return "%s%s:%s:%s:%d" % (REVISION_ID_PREFIX, scheme, uuid, \
escape_svn_path(path.strip("/")), revnum)
+
+class RevidMap(object):
+ """Revision id mapping store.
+
+ Stores mapping from revid -> (path, revnum, scheme)
+ """
+ def __init__(self, repos, cache_db=None):
+ self.repos = repos
+ if cache_db is None:
+ self.cachedb = sqlite3.connect(":memory:")
+ else:
+ self.cachedb = cache_db
+ self.cachedb.executescript("""
+ create table if not exists revmap (revid text, path text, revnum integer, scheme text);
+ create index if not exists revid on revmap (revid);
+ """)
+ self.cachedb.commit()
+
+ def lookup_revid(self, revid):
+ for branch, revnum, scheme in self.cachedb.execute("select path, revnum, scheme from revmap where revid='%s'" % revid):
+ return branch, revnum, scheme
+
+ # FIXME: Find revid in the branch
+
+ raise NoSuchRevision(self.repos, revid)
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2007-04-14 18:00:15 +0000
+++ b/tests/__init__.py 2007-05-16 23:01:20 +0000
@@ -264,6 +264,7 @@
'test_push',
'test_radir',
'test_repos',
+ 'test_revids',
'test_scheme',
'test_transport',
'test_tree',
More information about the bazaar-commits
mailing list