Rev 1593: Pass project to branch/tag test functions. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk

Jelmer Vernooij jelmer at samba.org
Fri Aug 22 06:02:13 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/trunk

------------------------------------------------------------
revno: 1593
revision-id: jelmer at samba.org-20080822050207-w3saao46uodaoirp
parent: jelmer at samba.org-20080822023227-k5zchktih1feom17
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Fri 2008-08-22 07:02:07 +0200
message:
  Pass project to branch/tag test functions.
modified:
  layout.py                      layout.py-20080323165407-y9qw8nx4oykvoe1k-1
  mapping3/__init__.py           __init__.py-20080502174630-9324zh25kka98vlw-1
  mapping3/scheme.py             scheme.py-20060516195850-95181aae6b272f9e
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  tests/test_branch.py           test_branch.py-20060508162215-74ffeb5d608f8e20
  tests/test_scheme.py           test_scheme.py-20060621221855-va2xabhlxpmc9llx-1
=== modified file 'layout.py'
--- a/layout.py	2008-08-02 14:44:01 +0000
+++ b/layout.py	2008-08-22 05:02:07 +0000
@@ -52,23 +52,25 @@
         """
         raise NotImplementedError
 
-    def is_branch(self, path):
+    def is_branch(self, path, project=None):
         """Check whether a specified path points at a branch."""
         try:
-            (type, _, bp, rp) = self.parse(path)
+            (type, proj, bp, rp) = self.parse(path)
         except NotBranchError:
             return False
-        if type == "branch" and rp == "":
+        if (type == "branch" and rp == "" and 
+            (project is None or proj == project)):
             return True
         return False
 
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         """Check whether a specified path points at a tag."""
         try:
-            (type, _, bp, rp) = self.parse(path)
+            (type, proj, bp, rp) = self.parse(path)
         except NotBranchError:
             return False
-        if type == "tag" and rp == "":
+        if (type == "tag" and rp == "" and
+            (project is None or proj == project)):
             return True
         return False
 

=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py	2008-08-05 00:14:32 +0000
+++ b/mapping3/__init__.py	2008-08-22 05:02:07 +0000
@@ -32,7 +32,7 @@
 # Number of revisions to evaluate when guessing the branching scheme
 SCHEME_GUESS_SAMPLE_SIZE = 2000
 
-def expand_branch_pattern(begin, todo, check_path, get_children):
+def expand_branch_pattern(begin, todo, check_path, get_children, project=None):
     """Find the paths in the repository that match the expected branch pattern.
 
     :param begin: List of path elements currently opened.
@@ -42,6 +42,10 @@
     """
     mutter('expand branches: %r, %r', begin, todo)
     path = "/".join(begin)
+    if (project is not None and 
+        not project.startswith(path) and 
+        not path.startswith(project)):
+        return []
     # If all elements have already been handled, just check the path exists
     if len(todo) == 0:
         if check_path(path):
@@ -50,7 +54,8 @@
             return []
     # Not a wildcard? Just expand next bits
     if todo[0] != "*":
-        return expand_branch_pattern(begin+[todo[0]], todo[1:], check_path, get_children)
+        return expand_branch_pattern(begin+[todo[0]], todo[1:], check_path, 
+                                     get_children, project)
     children = get_children(path)
     if children is None:
         return []
@@ -63,7 +68,8 @@
                 # Last path element, so return directly
                 ret.append("/".join(begin+[c]))
             else:
-                ret += expand_branch_pattern(begin+[c], todo[1:], check_path, get_children)
+                ret += expand_branch_pattern(begin+[c], todo[1:], check_path, 
+                                             get_children, project)
     finally:
         pb.finished()
     return ret
@@ -82,7 +88,7 @@
             type = "branch"
         return (type, proj, bp, rp)
 
-    def _get_root_paths(self, revnum, verify_fn, project="", pb=None):
+    def _get_root_paths(self, revnum, verify_fn, project=None, pb=None):
         def check_path(path):
             return self.repository.transport.check_path(path, revnum) == NODE_DIR
         def find_children(path):
@@ -99,14 +105,14 @@
             if pb is not None:
                 pb.update("finding branches", idx, len(self.scheme.branch_list))
             for bp in expand_branch_pattern([], pattern.split("/"), check_path,
-                    find_children):
-                if verify_fn(bp):
+                    find_children, project):
+                if verify_fn(bp, project):
                     yield "", bp, bp.split("/")[-1]
 
-    def get_branches(self, revnum, project="", pb=None):
+    def get_branches(self, revnum, project=None, pb=None):
         return self._get_root_paths(revnum, self.scheme.is_branch, project, pb)
 
-    def get_tags(self, revnum, project="", pb=None):
+    def get_tags(self, revnum, project=None, pb=None):
         return self._get_root_paths(revnum, self.scheme.is_tag, project, pb)
 
     def get_tag_path(self, name, project=""):

=== modified file 'mapping3/scheme.py'
--- a/mapping3/scheme.py	2008-08-04 16:57:09 +0000
+++ b/mapping3/scheme.py	2008-08-22 05:02:07 +0000
@@ -32,7 +32,7 @@
     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 is_branch(self, path):
+    def is_branch(self, path, project=None):
         """Check whether a location refers to a branch.
         
         :param path: Path to check.
@@ -91,7 +91,7 @@
 
         raise UnknownBranchingScheme(name)
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         """Check whether the specified path is the parent directory of branches.
         The path may not be a branch itself.
         
@@ -100,7 +100,7 @@
         """
         raise NotImplementedError
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         """Check whether the specified path is the parent directory of tags.
         The path may not be a tag itself.
         
@@ -109,7 +109,7 @@
         """
         raise NotImplementedError
 
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         """Check whether the specified path is a tag 
         according to this branching scheme.
 
@@ -166,7 +166,7 @@
     def __str__(self):
         return "list-%s" % prop_name_quote(bz2.compress("".join(map(lambda x:x+"\n", self.branch_list))))
             
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         """See BranchingScheme.is_tag()."""
         return False
 
@@ -179,7 +179,7 @@
                 return False
         return True
 
-    def is_branch(self, path):
+    def is_branch(self, path, project=None):
         """See BranchingScheme.is_branch()."""
         parts = path.strip("/").split("/")
         for pattern in self.split_branch_list:
@@ -193,7 +193,8 @@
         parts = path.strip("/").split("/")
         for pattern in self.split_branch_list:
             if self._pattern_cmp(parts[:len(pattern)], pattern):
-                return ("", "/".join(parts[:len(pattern)]), 
+                return ("/".join(parts[:len(pattern)]), 
+                        "/".join(parts[:len(pattern)]), 
                         "/".join(parts[len(pattern):]))
         raise InvalidSvnBranchPath(path, self)
 
@@ -203,11 +204,11 @@
     def to_lines(self):
         return self.branch_list
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         # ListBranchingScheme doesn't have tags
         return False
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         parts = path.strip("/").split("/")
         for pattern in self.split_branch_list:
             if len(parts) == len(pattern):
@@ -223,11 +224,13 @@
     def __init__(self):
         ListBranchingScheme.__init__(self, [""])
 
-    def is_branch(self, path):
+    def is_branch(self, path, project=None):
         """See BranchingScheme.is_branch()."""
-        return path.strip("/") == ""
+        if project is None or project == "":
+            return path.strip("/") == ""
+        return False
 
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         return False
 
     def unprefix(self, path):
@@ -241,10 +244,10 @@
     def __repr__(self):
         return "%s()" % self.__class__.__name__
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         return False
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         return False
 
 
@@ -278,9 +281,13 @@
             else:
                 return urlutils.join(project, "branches", name)
 
-    def is_branch(self, path):
+    def is_branch(self, path, project=None):
         """See BranchingScheme.is_branch()."""
         parts = path.strip("/").split("/")
+
+        if project is not None and project != "/".join(parts[0:self.level]):
+            return False
+
         if len(parts) == self.level+1 and parts[self.level] == "trunk":
             return True
 
@@ -289,9 +296,13 @@
 
         return False
 
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         """See BranchingScheme.is_tag()."""
         parts = path.strip("/").split("/")
+
+        if project is not None and project != "/".join(parts[0:self.level]):
+            return False
+
         if len(parts) == self.level+2 and \
            (parts[self.level] == "tags"):
             return True
@@ -323,15 +334,15 @@
     def __repr__(self):
         return "%s(%d)" % (self.__class__.__name__, self.level)
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         parts = path.strip("/").split("/")
         if len(parts) <= self.level:
             return True
-        return self.is_branch(path+"/trunk")
+        return self.is_branch(path+"/trunk", project)
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         parts = path.strip("/").split("/")
-        return self.is_tag(path+"/aname")
+        return self.is_tag(path+"/aname", project)
 
 
 
@@ -353,11 +364,11 @@
             raise BzrError("NoBranchingScheme should be used")
         ListBranchingScheme.__init__(self, [self.path])
 
-    def is_branch(self, path):
+    def is_branch(self, path, project=None):
         """See BranchingScheme.is_branch()."""
         return self.path == path.strip("/")
 
-    def is_tag(self, path):
+    def is_tag(self, path, project=None):
         """See BranchingScheme.is_tag()."""
         return False
 
@@ -381,12 +392,12 @@
     def __repr__(self):
         return "%s(%r)" % (self.__class__.__name__, self.path)
 
-    def is_branch_parent(self, path):
+    def is_branch_parent(self, path, project=None):
         if not "/" in self.path:
             return False
-        return self.is_branch(path+"/"+self.path.split("/")[-1])
+        return self.is_branch(path+"/"+self.path.split("/")[-1], project=None)
 
-    def is_tag_parent(self, path):
+    def is_tag_parent(self, path, project=None):
         return False
 
 

=== modified file 'repository.py'
--- a/repository.py	2008-08-08 23:53:12 +0000
+++ b/repository.py	2008-08-22 05:02:07 +0000
@@ -605,7 +605,8 @@
     def add_revision(self, rev_id, rev, inv=None, config=None):
         raise NotImplementedError(self.add_revision)
 
-    def generate_revision_id(self, revnum, path, mapping, revprops=None, changed_fileprops=None):
+    def generate_revision_id(self, revnum, path, mapping, revprops=None, 
+                             changed_fileprops=None):
         """Generate an unambiguous revision id. 
         
         :param revnum: Subversion revision number.
@@ -626,7 +627,8 @@
 
         return self.get_revmap().get_revision_id(revnum, path, mapping, revprops, changed_fileprops)
 
-    def lookup_revision_id(self, revid, layout=None, ancestry=None):
+    def lookup_revision_id(self, revid, layout=None, ancestry=None, 
+                           project=None):
         """Parse an existing Subversion-based revision id.
 
         :param revid: The revision id.
@@ -639,7 +641,7 @@
         # If there is no entry in the map, walk over all branches:
         if layout is None:
             layout = self.get_layout()
-        return self.get_revmap().get_branch_revnum(revid, layout)
+        return self.get_revmap().get_branch_revnum(revid, layout, project)
 
     def get_inventory_xml(self, revision_id):
         """See Repository.get_inventory_xml()."""
@@ -833,7 +835,8 @@
             pb.finished()
         return tags
 
-    def find_branchpaths(self, layout, from_revnum=0, to_revnum=None):
+    def find_branchpaths(self, layout, from_revnum=0, to_revnum=None, 
+                         project=None):
         """Find all branch paths that were changed in the specified revision 
         range.
 
@@ -853,14 +856,16 @@
             for (paths, i, revprops) in self._log.iter_changes([""], from_revnum, to_revnum):
                 pb.update("finding branches", i, to_revnum)
                 for p in sorted(paths.keys()):
-                    if layout.is_branch(p) or layout.is_tag(p):
+                    if (layout.is_branch(p, project) or 
+                        layout.is_tag(p, project)):
                         if paths[p][0] in ('R', 'D') and p in created_branches:
                             ret.append((p, created_branches[p], False))
                             del created_branches[p]
 
                         if paths[p][0] in ('A', 'R', 'M'): 
                             created_branches[p] = i
-                    elif layout.is_branch_parent(p) or layout.is_tag_parent(p):
+                    elif (layout.is_branch_parent(p, project) or 
+                          layout.is_tag_parent(p, project)):
                         if paths[p][0] in ('R', 'D'):
                             k = created_branches.keys()
                             for c in k:
@@ -874,10 +879,10 @@
                                 try:
                                     for c in self.transport.get_dir(p, i)[0].keys():
                                         n = p+"/"+c
-                                        if layout.is_branch(n) or layout.is_tag(n):
+                                        if layout.is_branch(n, project) or layout.is_tag(n, project):
                                             created_branches[n] = i
-                                        elif (layout.is_branch_parent(n) or 
-                                              layout.is_tag_parent(n)):
+                                        elif (layout.is_branch_parent(n, project) or 
+                                              layout.is_tag_parent(n, project)):
                                             parents.append(n)
                                 except SubversionException, (_, errors.ERR_FS_NOT_DIRECTORY):
                                     pass
@@ -903,15 +908,16 @@
         return SvnCommitBuilder(self, branch, parents, config, timestamp, 
                 timezone, committer, revprops, revision_id)
 
-    def find_fileprop_branches(self, layout, from_revnum, to_revnum):
+    def find_fileprop_branches(self, layout, from_revnum, to_revnum, 
+                               project=None):
         reuse_policy = self.get_config().get_reuse_revisions()
         if reuse_policy == "removed-branches":
-            for (branch, revno, _) in self.find_branchpaths(layout, from_revnum, 
-                                                            to_revnum):
+            for (branch, revno, _) in self.find_branchpaths(layout, 
+                from_revnum, to_revnum, project):
                 yield (branch, revno)
         elif reuse_policy in ("other-branches", "none"):
             revnum = self.get_latest_revnum()
-            for (project, branch, nick) in layout.get_branches(revnum):
+            for (project, branch, nick) in layout.get_branches(revnum, project):
                 yield (branch, revnum)
         else:
             assert False

=== modified file 'revids.py'
--- a/revids.py	2008-08-03 16:57:08 +0000
+++ b/revids.py	2008-08-22 05:02:07 +0000
@@ -47,7 +47,7 @@
 
         return revid
 
-    def get_branch_revnum(self, revid, layout):
+    def get_branch_revnum(self, revid, layout, project=None):
         """Find the (branch, revnum) tuple for a revision id."""
         # Try a simple parse
         try:
@@ -62,14 +62,14 @@
         except InvalidRevisionId:
             pass
 
-        for entry_revid, branch, revno, mapping in self.discover_revids(layout, 0, self.repos.get_latest_revnum()):
+        for entry_revid, branch, revno, mapping in self.discover_revids(layout, 0, self.repos.get_latest_revnum(), project):
             if revid == entry_revid:
                 (bp, revnum, scheme) = self.bisect_revid_revnum(revid, branch, 0, revno)
                 return (bp, revnum, BzrSvnMappingv3FileProps(scheme))
         raise NoSuchRevision(self, revid)
 
-    def discover_revids(self, layout, from_revnum, to_revnum):
-        for (branch, revno) in self.repos.find_fileprop_branches(layout, from_revnum, to_revnum):
+    def discover_revids(self, layout, from_revnum, to_revnum, project=None):
+        for (branch, revno) in self.repos.find_fileprop_branches(layout, from_revnum, to_revnum, project):
             assert isinstance(branch, str)
             assert isinstance(revno, int)
             # Look at their bzr:revision-id-vX
@@ -144,7 +144,7 @@
 
         return revid
 
-    def get_branch_revnum(self, revid, layout):
+    def get_branch_revnum(self, revid, layout, project=None):
         # Try a simple parse
         try:
             (uuid, branch_path, revnum, mapping) = parse_revision_id(revid)
@@ -175,14 +175,14 @@
                 return (branch_path, min_revnum, BzrSvnMappingv3FileProps(get_scheme(scheme)))
         except NoSuchRevision, e:
             last_revnum = self.actual.repos.get_latest_revnum()
-            last_checked = self.cache.last_revnum_checked(repr(layout))
+            last_checked = self.cache.last_revnum_checked(repr((layout, project)))
             if (last_revnum <= last_checked):
                 # All revision ids in this repository for the current 
                 # layout have already been discovered. No need to 
                 # check again.
                 raise e
             found = False
-            for entry_revid, branch, revno, mapping in self.actual.discover_revids(layout, last_checked, last_revnum):
+            for entry_revid, branch, revno, mapping in self.actual.discover_revids(layout, last_checked, last_revnum, project):
                 if entry_revid == revid:
                     found = True
                 if entry_revid not in self.revid_seen:
@@ -191,15 +191,15 @@
                 
             # 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(repr(layout), last_revnum)
+            self.cache.set_last_revnum_checked(repr((layout, project)), last_revnum)
             if not found:
                 raise e
             (branch_path, min_revnum, max_revnum, scheme) = self.cache.lookup_revid(revid)
             assert min_revnum <= max_revnum
             assert isinstance(branch_path, str)
 
-        (branch_path, revnum, scheme) = self.actual.bisect_revid_revnum(revid, branch_path, min_revnum,
-                                               max_revnum)
+        (branch_path, revnum, scheme) = self.actual.bisect_revid_revnum(revid, 
+            branch_path, min_revnum, max_revnum)
         self.cache.insert_revid(revid, branch_path, revnum, revnum, str(scheme))
         return (branch_path, revnum, BzrSvnMappingv3FileProps(scheme))
 

=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py	2008-08-02 23:41:33 +0000
+++ b/tests/test_branch.py	2008-08-22 05:02:07 +0000
@@ -103,6 +103,7 @@
         dc.close()
 
         b = Branch.open(repos_url + "/trunk")
+        self.assertEquals("", b.project)
         self.assertEquals(b.repository.generate_revision_id(1, "tags/foo", b.repository.get_mapping()), b.tags.lookup_tag("foo"))
 
     def test_tag_lookup_nonexistant(self):

=== modified file 'tests/test_scheme.py'
--- a/tests/test_scheme.py	2008-08-03 14:54:12 +0000
+++ b/tests/test_scheme.py	2008-08-22 05:02:07 +0000
@@ -347,6 +347,10 @@
         self.assertFalse(scheme.is_branch("/trunk/"))
         self.assertFalse(scheme.is_branch("/foo/trunk"))
         self.assertTrue(scheme.is_branch("/foo/bar/trunk"))
+        self.assertTrue(scheme.is_branch("/foo/bar/trunk", "foo/bar"))
+        self.assertFalse(scheme.is_branch("/foo/bar/trunk", "fool/bar"))
+        self.assertTrue(scheme.is_branch("/foo/bar/branches/bla", "foo/bar"))
+        self.assertFalse(scheme.is_branch("/foo/bar/branches/bla", "fool/bar"))
         self.assertFalse(scheme.is_branch("/branches/trunk"))
         self.assertTrue(scheme.is_branch("/bar/branches/trunk"))
 




More information about the bazaar-commits mailing list