Rev 1773: Remove unused code from logwalker, branchprops. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Tue Sep 2 00:31:03 BST 2008


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

------------------------------------------------------------
revno: 1773
revision-id: jelmer at samba.org-20080901233056-r6yx7gx05qpsw0wx
parent: jelmer at samba.org-20080901224532-pn6qr29t49wqjnhe
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Tue 2008-09-02 01:30:56 +0200
message:
  Remove unused code from logwalker, branchprops.
modified:
  branchprops.py                 branchprops.py-20061223204623-80lvm7pjrpsgk0dd-1
  changes.py                     changes.py-20080330205801-lh92uht2ztppvdcz-1
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  logwalker.py                   logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
  revmeta.py                     revmeta.py-20080901215045-n8a6arqybs9ez5hl-1
  tests/test_logwalker.py        test_logwalker.py-20060622141944-pkocc3rj8g62ukbi-1
  transport.py                   transport.py-20060406231150-b3472d06b3a0818d
=== modified file 'branchprops.py'
--- a/branchprops.py	2008-09-01 20:37:49 +0000
+++ b/branchprops.py	2008-09-01 23:30:56 +0000
@@ -54,30 +54,3 @@
 
         self._props_cache[path, revnum] = props
         return props
-
-    def get_changed_properties(self, path, revnum, skip_check=False):
-        """Get the contents of a Subversion file property.
-
-        Will use the cache.
-
-        :param path: Subversion path.
-        :param revnum: Subversion revision number.
-        :return: Contents of property or default if property didn't exist.
-        """
-        assert isinstance(revnum, int)
-        assert isinstance(path, str)
-        return logwalker.lazy_dict({}, self._real_get_changed_properties, path, revnum, skip_check)
-
-    def _real_get_changed_properties(self, path, revnum, skip_check):
-        if skip_check or self.log.get_change(path, revnum) is None:
-            return {}
-        current = self.get_properties(path, revnum)
-        if current == {}:
-            return {}
-        (prev_path, prev_revnum) = self.log.get_previous(path, revnum)
-        if prev_path is None and prev_revnum == -1:
-            previous = {}
-        else:
-            assert isinstance(prev_path, str)
-            previous = self.get_properties(prev_path, prev_revnum)
-        return properties.diff(current, previous)

=== modified file 'changes.py'
--- a/changes.py	2008-08-29 20:03:11 +0000
+++ b/changes.py	2008-09-01 23:30:56 +0000
@@ -22,7 +22,6 @@
 
 
 def find_prev_location(paths, branch_path, revnum):
-    assert isinstance(paths, dict)
     assert isinstance(branch_path, str)
     assert isinstance(revnum, int)
     if revnum == 0:

=== modified file 'fileids.py'
--- a/fileids.py	2008-09-01 22:34:27 +0000
+++ b/fileids.py	2008-09-01 23:30:56 +0000
@@ -121,8 +121,7 @@
         :param mapping: Mapping
         """
         renames = revmeta.get_fileid_map(mapping)
-        assert revmeta.paths is not None
-        changes = get_local_changes(revmeta.paths, revmeta.branch_path, mapping,
+        changes = get_local_changes(revmeta.get_paths(), revmeta.branch_path, mapping,
                     self.repos.get_layout(),
                     self.repos.generate_revision_id, find_children)
         if find_children is not None:

=== modified file 'logwalker.py'
--- a/logwalker.py	2008-09-01 22:45:32 +0000
+++ b/logwalker.py	2008-09-01 23:30:56 +0000
@@ -140,40 +140,6 @@
                      and action in ('A', 'R')))
         """, (revnum, path, path + "/*", path)).fetchone()[0]
 
-    def path_added(self, path, from_revnum, to_revnum):
-        """Determine whether a path was recently added. 
-        
-        It returns the latest revision number before to_revnum in which the 
-        path was added or replaced, or None if the path was neither added nor
-        replaced after from_revnum but before to_revnum.
-        """
-        assert from_revnum < to_revnum
-        return self.cachedb.execute("""
-            select max(rev) from changed_path
-            where rev > ? and rev <= ?
-            and (?=path or ? glob (path || '/*'))
-            and action in ('A', 'R')
-        """, (from_revnum, to_revnum, path, path)).fetchone()[0]
-    
-    def get_change(self, path, revnum):
-        return self.cachedb.execute("""
-            select action, copyfrom_path, copyfrom_rev
-            from changed_path
-            where path=? and rev=?
-        """, (path, revnum)).fetchone()
-
-    def get_previous(self, path, revnum):
-        """Determine the change that created the given path or its
-        nearest ancestor, in order to determine where it came from."""
-        return self.cachedb.execute("""
-            select path, action, copyfrom_path, copyfrom_rev
-            from changed_path
-            where rev=? and action in ('A', 'R')
-            and (path=? or path='' or ? glob (path || '/*'))
-            order by path desc
-            limit 1
-        """, (revnum, path, path)).fetchone()
-
     def get_revision_paths(self, revnum):
         """Return all history information for a given revision number.
         
@@ -187,16 +153,6 @@
             paths[p.encode("utf-8")] = (act, cf, cr)
         return paths
     
-    def changes_path(self, path, revnum):
-        """Check whether a path was changed in a particular revision:
-
-        :param path: path to check for
-        :param revnum: revision number to fetch
-        """
-        if path == '':
-            return self.cachedb.execute("select count(*) from changed_path where rev=?", (revnum,)).fetchone()[0] > 0
-        return self.cachedb.execute("select count(*) from changed_path where rev=? and (path=? or path glob (? || '/*'))", (revnum, path, path)).fetchone()[0] > 0
-
     def insert_path(self, rev, path, action, copyfrom_path=None, copyfrom_rev=-1):
         """Insert new history information into the cache.
         
@@ -327,7 +283,7 @@
                 else:
                     pb.update("determining changes", from_revnum-revnum, from_revnum)
             assert revnum > 0 or path == "", "Inconsistent path,revnum: %r,%r" % (revnum, path)
-            revpaths = self._get_revision_paths(revnum)
+            revpaths = self.get_revision_paths(revnum)
 
             if ascending:
                 next = (path, revnum+1)
@@ -352,56 +308,13 @@
             assert isinstance(path, str)
             assert isinstance(revnum, int)
 
-    def get_previous(self, path, revnum):
-        """Return path,revnum pair specified pair was derived from.
-
-        :param path:  Path to check
-        :param revnum:  Revision to check
-        """
-        assert revnum >= 0
-        self.fetch_revisions(revnum)
-        self.mutter("get previous %r:%r", path, revnum)
-        if path == "":
-            if revnum == 0:
-                return (None, -1)
-            return (path, revnum - 1)
-        row = self.cache.get_previous(path, revnum)
-        if row is None:
-            return (path, revnum-1)
-        (branch_path, action, copyfrom_path, copyfrom_rev) = row
-        branch_path = branch_path.encode('utf-8')
-        if copyfrom_path is not None:
-            copyfrom_path = copyfrom_path.encode('utf-8')
-        assert path == branch_path or path.startswith(branch_path + "/")
-        if copyfrom_rev == -1:
-            assert path == branch_path
-            return (None, -1) # newly added
-        return (copyfrom_path + path[len(branch_path):], copyfrom_rev)
-
-    def _get_revision_paths(self, revnum):
+    def get_revision_paths(self, revnum):
         if revnum == 0:
             return {'': ('A', None, -1)}
         self.fetch_revisions(revnum)
 
         return self.cache.get_revision_paths(revnum)
 
-    def get_change(self, path, revnum):
-        """Return action,copyfrom_path,copyfrom_revnum tuple for given
-        path, or None if no modification occurred in given revision.
-
-        :param path:  Path to check
-        :param revnum:  Revision to check
-        """
-        assert revnum >= 0
-        self.fetch_revisions(revnum)
-        
-        self.mutter("get previous %r:%r", path, revnum)
-        if revnum == 0:
-            if path == "":
-                return ('A', None, -1)
-            return None
-        return self.cache.get_change(path, revnum)
-
     def revprop_list(self, revnum):
         self.mutter('revprop list: %d' % revnum)
         self.fetch_revisions(revnum)
@@ -425,10 +338,6 @@
         self.cache.commit()
         return revprops
 
-    def changes_path(self, path, revnum):
-        self.fetch_revisions(revnum)
-        return self.cache.changes_path(path, revnum)
-
     def fetch_revisions(self, to_revnum=None, pb=None):
         """Fetch information about all revisions in the remote repository
         until to_revnum.
@@ -485,7 +394,7 @@
         self.cache.commit()
 
 
-def struct_revpaths_to_tuples(changed_paths):
+def strip_slashes(changed_paths):
     assert isinstance(changed_paths, dict)
     revpaths = {}
     for k, (action, copyfrom_path, copyfrom_rev) in changed_paths.items():
@@ -557,7 +466,7 @@
                 if revnum == 0 and changed_paths is None:
                     revpaths = {"": ('A', None, -1)}
                 elif isinstance(changed_paths, dict):
-                    revpaths = struct_revpaths_to_tuples(changed_paths)
+                    revpaths = strip_slashes(changed_paths)
                 else:
                     revpaths = {}
                 if todo_revprops is None:
@@ -571,7 +480,7 @@
                     revision="Revision number %d" % from_revnum)
             raise
 
-    def _get_revision_paths(self, revnum):
+    def get_revision_paths(self, revnum):
         """Obtain dictionary with all the changes in a particular revision.
 
         :param revnum: Subversion revision number
@@ -583,7 +492,7 @@
             return {'': ('A', None, -1)}
 
         try:
-            return struct_revpaths_to_tuples(
+            return strip_slashes(
                 self._transport.iter_log([""], revnum, revnum, 1, True, True, False, []).next()[0])
         except SubversionException, (_, num):
             if num == ERR_FS_NO_SUCH_REVISION:
@@ -591,12 +500,6 @@
                     revision="Revision number %d" % revnum)
             raise
 
-    def changes_path(self, path, revnum):
-        return self._get_revision_paths(revnum).has_key(path)
-
-    def get_change(self, path, revnum):
-        return self._get_revision_paths(revnum).get(path)
-        
     def find_children(self, path, revnum):
         """Find all children of path in revnum.
 
@@ -625,32 +528,3 @@
         finally:
             self._transport.connections.add(conn)
         return results
-
-    def get_previous(self, path, revnum):
-        """Return path,revnum pair specified pair was derived from.
-
-        :param path:  Path to check
-        :param revnum:  Revision to check
-        """
-        assert revnum >= 0
-        if revnum == 0:
-            return (None, -1)
-
-        try:
-            paths = struct_revpaths_to_tuples(self._transport.iter_log([path], revnum, revnum, 1, True, False, False, []).next()[0])
-        except SubversionException, (_, num):
-            if num == ERR_FS_NO_SUCH_REVISION:
-                raise NoSuchRevision(branch=self, 
-                    revision="Revision number %d" % revnum)
-            raise
-
-        if not path in paths:
-            return (None, -1)
-
-        if paths[path][2] == -1:
-            if paths[path][0] in ('A', 'R'):
-                return (None, -1)
-            return (path, revnum-1)
-
-        return (paths[path][1], paths[path][2])
-

=== modified file 'revmeta.py'
--- a/revmeta.py	2008-09-01 22:34:27 +0000
+++ b/revmeta.py	2008-09-01 23:30:56 +0000
@@ -24,7 +24,7 @@
     def __init__(self, repository, branch_path, revnum, paths, revprops, changed_fileprops=None, consider_fileprops=True):
         self.repository = repository
         self.branch_path = branch_path
-        self.paths = paths
+        self._paths = paths
         self.revnum = revnum
         self.revprops = revprops
         self._changed_fileprops = changed_fileprops
@@ -34,6 +34,11 @@
     def __repr__(self):
         return "<RevisionMetadata for revision %d in repository %s>" % (self.revnum, self.repository.uuid)
 
+    def get_paths(self):
+        if self._paths is None:
+            self._paths = self.repository._log.get_revision_paths(self.revnum)
+        return self._paths
+
     def get_revision_id(self, mapping):
         return self.repository.get_revmap().get_revision_id(self.revnum, self.branch_path, mapping, 
                                                             self.revprops, self.get_changed_fileprops())
@@ -42,7 +47,7 @@
         return self.repository.branchprop_list.get_properties(self.branch_path, self.revnum)
 
     def get_previous_fileprops(self):
-        prev = changes.find_prev_location(self.paths, self.branch_path, self.revnum)
+        prev = changes.find_prev_location(self.get_paths(), self.branch_path, self.revnum)
         if prev is None:
             return {}
         (prev_path, prev_revnum) = prev
@@ -50,9 +55,7 @@
 
     def get_changed_fileprops(self):
         if self._changed_fileprops is None:
-            if self.paths is None:
-                self._changed_fileprops = self.repository.branchprop_list.get_changed_properties(self.branch_path, self.revnum)
-            elif self.branch_path in self.paths:
+            if self.branch_path in self.get_paths():
                 self._changed_fileprops = properties.diff(self.get_fileprops(), self.get_previous_fileprops())
             else:
                 self._changed_fileprops = {}

=== modified file 'tests/test_logwalker.py'
--- a/tests/test_logwalker.py	2008-08-30 23:45:11 +0000
+++ b/tests/test_logwalker.py	2008-09-01 23:30:56 +0000
@@ -448,56 +448,6 @@
 
         self.assertEqual(("trunk", 1), walker.get_previous("trunk", 2))
 
-    def test_get_previous_added(self):
-        repos_url = self.make_repository("a")
-
-        cb = self.get_commit_editor(repos_url)
-        t = cb.add_dir("trunk")
-        t.add_file("trunk/afile").modify()
-        cb.close()
-
-        cb = self.get_commit_editor(repos_url)
-        t = cb.open_dir("trunk")
-        t.open_file("trunk/afile").modify()
-        t.change_prop("myprop", "mydata")
-        cb.close()
-
-        walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
-
-        self.assertEqual((None, -1), walker.get_previous("trunk", 1))
-
-    def test_get_previous_copy(self):
-        repos_url = self.make_repository("a")
-
-        cb = self.get_commit_editor(repos_url)
-        t = cb.add_dir("trunk")
-        t.add_file("trunk/afile")
-        cb.close()
-
-        cb = self.get_commit_editor(repos_url)
-        cb.add_dir("anotherfile", "trunk")
-        cb.close()
-
-        walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
-
-        self.assertEqual(("trunk", 1), walker.get_previous("anotherfile", 2))
-
-    def test_get_previous_replace(self):
-        repos_url = self.make_repository("a")
-
-        cb = self.get_commit_editor(repos_url)
-        cb.add_dir("trunk")
-        cb.close()
-
-        cb = self.get_commit_editor(repos_url)
-        cb.delete("trunk")
-        cb.add_dir("trunk")
-        cb.close()
-
-        walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
-
-        self.assertEqual((None, -1), walker.get_previous("trunk", 2))
-
     def test_find_children_empty(self):
         repos_url = self.make_repository("a")
 
@@ -721,10 +671,3 @@
         self.assertEquals(42, self.cache.path_added("foo", 41, 43))
         self.assertEquals(None, self.cache.path_added("foo", 42, 43))
         self.assertEquals(None, self.cache.path_added("foo", 44, 49))
-
-    def test_get_change(self):
-        self.cache.insert_path(41, "foo", "A", "bla", 32)
-        self.cache.insert_path(42, "foo", "A")
-        self.assertEquals(("A", None, -1), self.cache.get_change("foo", 42))
-        self.assertEquals(("A", "bla", 32), self.cache.get_change("foo", 41))
-

=== modified file 'transport.py'
--- a/transport.py	2008-08-30 03:08:49 +0000
+++ b/transport.py	2008-09-01 23:30:56 +0000
@@ -281,10 +281,7 @@
             def next(self):
                 self.semaphore.acquire()
                 ret = self.pending.pop(0)
-                if ret is None:
-                    self.transport.add_connection(self.conn)
-                elif isinstance(ret, Exception):
-                    self.transport.add_connection(self.conn)
+                if isinstance(ret, Exception):
                     raise ret
                 return ret
 
@@ -303,6 +300,7 @@
                 finally:
                     self.pending.append(Exception("Some exception was not handled"))
                     self.semaphore.release()
+                    self.transport.add_connection(self.conn)
 
         if paths is None:
             newpaths = None




More information about the bazaar-commits mailing list