Rev 986: Use layout rather than scheme in a couple more places. in file:///data/jelmer/bzr-svn/layout/

Jelmer Vernooij jelmer at samba.org
Fri May 2 18:42:54 BST 2008


At file:///data/jelmer/bzr-svn/layout/

------------------------------------------------------------
revno: 986
revision-id: jelmer at samba.org-20080502174252-mc2retxh7ehcg56o
parent: jelmer at samba.org-20080502170505-30k337eigc6sy17y
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: layout
timestamp: Fri 2008-05-02 19:42:52 +0200
message:
  Use layout rather than scheme in a couple more places.
modified:
  __init__.py                    __init__.py-20051008155114-eae558e6cf149e1d
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  scheme.py                      scheme.py-20060516195850-95181aae6b272f9e
=== modified file '__init__.py'
--- a/__init__.py	2008-04-12 20:42:44 +0000
+++ b/__init__.py	2008-05-02 17:42:52 +0000
@@ -382,7 +382,7 @@
         if repository_wide:
             scheme = repos._get_property_scheme()
         else:
-            scheme = repos.get_scheme()
+            scheme = repos.get_mapping().scheme
         if set:
             schemestr = edit_commit_message("", 
                                             start_message=scheme_str(scheme))

=== modified file 'repository.py'
--- a/repository.py	2008-05-02 14:18:41 +0000
+++ b/repository.py	2008-05-02 17:42:52 +0000
@@ -219,6 +219,9 @@
     def _make_parents_provider(self):
         return CachingParentsProvider(self)
 
+    def get_layout(self):
+        return self.get_scheme()
+
     def get_scheme(self):
         """Determine the branching scheme to use for this repository.
 
@@ -271,8 +274,7 @@
         pb = ui.ui_factory.nested_progress_bar()
         try:
             scheme = guess_scheme_from_history(
-                self._log.iter_changes("", last_revnum, max(0, last_revnum-SCHEME_GUESS_SAMPLE_SIZE), pb=pb), last_revnum, 
-                branch_path)
+                self._log.iter_changes("", last_revnum, max(0, last_revnum-SCHEME_GUESS_SAMPLE_SIZE), pb=pb), last_revnum, branch_path)
         finally:
             pb.finished()
         mutter("Guessed branching scheme: %r" % scheme)
@@ -599,22 +601,22 @@
         return self._serializer.write_revision_to_string(
             self.get_revision(revision_id))
 
-    def iter_changes(self, branch_path, revnum, mapping, pb=None):
+    def iter_changes(self, branch_path, revnum, mapping=None, pb=None):
         """Iterate over all revisions backwards.
         
         :return: iterator that returns tuples with branch path, 
             changed paths, revision number, changed file properties and 
         """
         assert isinstance(branch_path, str)
-        assert mapping.is_branch(branch_path) or mapping.is_tag(branch_path), \
+        assert mapping is None or mapping.is_branch(branch_path) or mapping.is_tag(branch_path), \
                 "Mapping %r doesn't accept %s as branch or tag" % (mapping, branch_path)
 
         for (bp, paths, revnum, revprops) in self._log.iter_changes(branch_path, revnum, pb=pb):
             assert revnum > 0 or bp == ""
-            assert mapping.is_branch(bp) or mapping.is_tag(bp), "%r is not a valid path" % bp
+            assert mapping is None or mapping.is_branch(bp) or mapping.is_tag(bp), "%r is not a valid path" % bp
 
             if (paths.has_key(bp) and paths[bp][1] is not None and 
-                not (mapping.is_branch(paths[bp][1]) or mapping.is_tag(paths[bp][1]))):
+                not (mapping is None or mapping.is_branch(paths[bp][1]) or mapping.is_tag(paths[bp][1]))):
                 # Make it look like the branch started here if the mapping 
                 # doesn't support weird paths as branches
                 paths[bp] = ('A', None, -1)
@@ -630,7 +632,7 @@
                      
             yield (bp, paths, revnum, revprops)
 
-    def iter_reverse_branch_changes(self, branch_path, revnum, mapping, pb=None):
+    def iter_reverse_branch_changes(self, branch_path, revnum, mapping=None, pb=None):
         """Return all the changes that happened in a branch 
         until branch_path,revnum. 
 

=== modified file 'revids.py'
--- a/revids.py	2008-04-04 12:16:27 +0000
+++ b/revids.py	2008-05-02 17:42:52 +0000
@@ -26,6 +26,7 @@
 from errors import InvalidPropertyValue
 from mapping import (parse_revision_id, BzrSvnMapping, BzrSvnMappingv3FileProps,
                      SVN_PROP_BZR_REVISION_ID, parse_revid_property)
+from scheme import BranchingScheme
 
 class RevidMap(object):
     def __init__(self, repos):
@@ -46,7 +47,8 @@
 
         return revid
 
-    def get_branch_revnum(self, revid, scheme):
+    def get_branch_revnum(self, revid, layout):
+        """Find the (branch, revnum) tuple for a revision id."""
         # Try a simple parse
         try:
             (uuid, branch_path, revnum, mapping) = parse_revision_id(revid)
@@ -60,52 +62,54 @@
         except InvalidRevisionId:
             pass
 
-        found = False
-        for entry_revid, branch, revno in self.discover_revids(scheme, 0, self.repos.get_latest_revnum()):
+        for entry_revid, branch, revno, mapping in self.discover_revids(layout, 0, self.repos.get_latest_revnum()):
             if revid == entry_revid:
-                found = True
-                break
-        if found:
-            return self.bisect_revid_revnum(revid, branch, revno, scheme)
+                return self.bisect_revid_revnum(revid, branch, revno)
         raise NoSuchRevision(revid)
 
-    def discover_revids(self, scheme, from_revnum, to_revnum):
-        for (branch, revno, _) in self.repos.find_branchpaths(scheme, from_revnum, to_revnum):
+    def discover_revids(self, layout, from_revnum, to_revnum):
+        for (branch, revno, _) in self.repos.find_branchpaths(layout, from_revnum, to_revnum):
             assert isinstance(branch, str)
             assert isinstance(revno, int)
             # Look at their bzr:revision-id-vX
             revids = set()
             try:
                 props = self.repos.branchprop_list.get_properties(branch, revno)
-                for line in props.get(SVN_PROP_BZR_REVISION_ID+str(scheme), "").splitlines():
-                    try:
-                        revids.add(parse_revid_property(line))
-                    except InvalidPropertyValue, ie:
-                        mutter(str(ie))
+                for propname, propvalue in props.items():
+                    if not propname.startswith(SVN_PROP_BZR_REVISION_ID):
+                        continue
+                    scheme = propname[len(SVN_PROP_BZR_REVISION_ID):]
+                    for line in propvalue.splitlines():
+                        try:
+                            revids.add((parse_revid_property(line), scheme))
+                        except InvalidPropertyValue, ie:
+                            mutter(str(ie))
             except svn.core.SubversionException, (_, svn.core.SVN_ERR_FS_NOT_DIRECTORY):
-                continue
+                    continue
 
             # If there are any new entries that are not yet in the cache, 
             # add them
-            for (entry_revno, entry_revid) in revids:
-                yield (entry_revid, branch, revno)
+            for ((entry_revno, entry_revid), scheme) in revids:
+                yield (entry_revid, branch, revno, BzrSvnMappingv3FileProps(BranchingScheme.find_scheme(scheme)))
 
-    def bisect_revid_revnum(self, revid, branch_path, max_revnum, scheme):
+    def bisect_revid_revnum(self, revid, branch_path, max_revnum):
         # Find the branch property between min_revnum and max_revnum that 
         # added revid
-        propname = SVN_PROP_BZR_REVISION_ID+str(scheme)
-        for (bp, changes, rev, revprops, changed_fileprops) in self.repos.iter_reverse_branch_changes(branch_path, max_revnum, scheme):
-            if not propname in changed_fileprops:
-                continue
-            try:
-                (entry_revno, entry_revid) = parse_revid_property(
-                    changed_fileprops[propname].splitlines()[-1])
-            except InvalidPropertyValue:
-                # Don't warn about encountering an invalid property, 
-                # that will already have happened earlier
-                continue
-            if entry_revid == revid:
-                return (bp, rev, BzrSvnMappingv3FileProps(scheme))
+        for (bp, changes, rev, revprops, changed_fileprops) in self.repos.iter_reverse_branch_changes(branch_path, max_revnum):
+            for propname, propvalue in changed_fileprops.items():
+                if not propname.startswith(SVN_PROP_BZR_REVISION_ID):
+                    continue
+                try:
+                    (entry_revno, entry_revid) = parse_revid_property(
+                        propvalue.splitlines()[-1])
+                except InvalidPropertyValue:
+                    # Don't warn about encountering an invalid property, 
+                    # that will already have happened earlier
+                    continue
+                if entry_revid == revid:
+                    scheme = BranchingScheme.find_scheme(propname[len(SVN_PROP_BZR_REVISION_ID):])
+                    assert scheme.is_tag(bp) or scheme.is_branch(bp)
+                    return (bp, rev, BzrSvnMappingv3FileProps(scheme))
 
         raise AssertionError("Revision id %s was added incorrectly" % revid)
 
@@ -126,7 +130,7 @@
         self.cache.insert_revid(revid, path, revnum, revnum, str(mapping.scheme))
         return revid
 
-    def get_branch_revnum(self, revid, scheme=None):
+    def get_branch_revnum(self, revid, layout):
         # Try a simple parse
         try:
             (uuid, branch_path, revnum, mapping) = parse_revision_id(revid)
@@ -156,21 +160,20 @@
                 return (branch_path, min_revnum, BzrSvnMappingv3FileProps(get_scheme(scheme)))
         except NoSuchRevision, e:
             last_revnum = self.actual.repos.get_latest_revnum()
-            if (last_revnum <= self.cache.last_revnum_checked(str(scheme))):
+            if (last_revnum <= self.cache.last_revnum_checked(str(layout))):
                 # All revision ids in this repository for the current 
-                # scheme have already been discovered. No need to 
+                # layout have already been discovered. No need to 
                 # check again.
                 raise e
             found = False
-            for entry_revid, branch, revno in self.actual.discover_revids(scheme, self.cache.last_revnum_checked(str(scheme)), last_revnum):
+            for entry_revid, branch, revno, mapping in self.actual.discover_revids(layout, self.cache.last_revnum_checked(str(layout)), last_revnum):
                 if entry_revid == revid:
                     found = True
-                self.cache.insert_revid(entry_revid, branch, 0, revno, 
-                            str(scheme))
+                self.cache.insert_revid(entry_revid, branch, 0, revno, str(mapping.scheme))
                 
-            # We've added all the revision ids for this scheme in the repository,
+            # We've added all the revision ids for this layout in the repository,
             # so no need to check again unless new revisions got added
-            self.cache.set_last_revnum_checked(str(scheme), last_revnum)
+            self.cache.set_last_revnum_checked(str(layout), last_revnum)
             if not found:
                 raise e
             (branch_path, min_revnum, max_revnum, scheme) = self.cache.lookup_revid(revid)
@@ -195,25 +198,25 @@
         create unique index if not exists scheme on revids_seen (scheme);
         """)
 
-    def set_last_revnum_checked(self, scheme, revnum):
+    def set_last_revnum_checked(self, layout, revnum):
         """Remember the latest revision number that has been checked
         for a particular scheme.
 
-        :param scheme: Branching scheme name.
+        :param layout: Repository layout.
         :param revnum: Revision number.
         """
-        self.cachedb.execute("replace into revids_seen (scheme, max_revnum) VALUES (?, ?)", (scheme, revnum))
+        self.cachedb.execute("replace into revids_seen (scheme, max_revnum) VALUES (?, ?)", (layout, revnum))
 
-    def last_revnum_checked(self, scheme):
+    def last_revnum_checked(self, layout):
         """Retrieve the latest revision number that has been checked 
         for revision ids for a particular branching scheme.
 
-        :param scheme: Branching scheme name.
+        :param layout: Repository layout.
         :return: Last revision number checked or 0.
         """
-        self.mutter("last revnum checked %r" % scheme)
+        self.mutter("last revnum checked %r" % layout)
         ret = self.cachedb.execute(
-            "select max_revnum from revids_seen where scheme = ?", (scheme,)).fetchone()
+            "select max_revnum from revids_seen where scheme = ?", (layout,)).fetchone()
         if ret is None:
             return 0
         return int(ret[0])

=== modified file 'scheme.py'
--- a/scheme.py	2008-03-30 21:43:54 +0000
+++ b/scheme.py	2008-05-02 17:42:52 +0000
@@ -22,25 +22,14 @@
 from errors import InvalidSvnBranchPath
 
 from base64 import urlsafe_b64decode, urlsafe_b64encode
+from layout import RepositoryLayout
 import bz2
 
-def is_valid_property_name(prop):
-    if not prop[0].isalnum() and not prop[0] in ":_":
-        return False
-    for c in prop[1:]:
-        if not c.isalnum() and not c in "-:._":
-            return False
-    return True
-
-
-class BranchingScheme(object):
+class BranchingScheme(RepositoryLayout):
     """ Divides SVN repository data up into branches. Since there
     is no proper way to do this, there are several subclasses of this class
     each of which handles a particular convention that may be in use.
     """
-    def __init__(self):
-        pass
-
     def is_branch(self, path):
         """Check whether a location refers to a branch.
         




More information about the bazaar-commits mailing list