Rev 30: Start working on a few more bits. Like _get_tracked_paths in lp:~jameinel/+junk/file_locking
John Arbash Meinel
john at arbash-meinel.com
Tue Sep 22 22:00:57 BST 2009
At lp:~jameinel/+junk/file_locking
------------------------------------------------------------
revno: 30
revision-id: john at arbash-meinel.com-20090922210047-315k7gvcdy1fqndw
parent: john at arbash-meinel.com-20090922204611-kmrtvpe5oyjs73zm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Tue 2009-09-22 16:00:47 -0500
message:
Start working on a few more bits. Like _get_tracked_paths
to go from the list of tracked ids => paths in the current tree.
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py 2009-09-22 20:46:11 +0000
+++ b/file_lock.py 2009-09-22 21:00:47 +0000
@@ -430,6 +430,42 @@
def track(self, path):
"""Start tracking the given path."""
+ def _get_tracked_paths(self):
+ """Find the set of paths that are tracked."""
+ ls = self._get_lock_store()
+ paths = []
+ for file_id in ls._locking_info._tracked_ids:
+ try:
+ paths.append(self._wt.id2path(file_id))
+ except errors.NoSuchId:
+ # It may be in 'trunk' but not in a branch, etc.
+ continue
+ return paths
+
+ def tracked_at(self, paths):
+ """Return the locations where things are being tracked (if any).
+
+ If a directory is marked as being tracked, then all paths underneath
+ that dir are effectively tracked at that level.
+
+ TODO: Consider what to do if you have multiple levels of tracking. eg I
+ have the path 'foo/bar/baz' and all 3 have been identified for
+ tracking. If I ask for the 'tracked_at' value, should I return all
+ 3?
+ Should a lock at 'foo/' prevent locking 'foo/bar'? Should a lock at
+ 'foo/baz' prevent a lock at 'foo'? Should taking the 'foo' lock
+ internally automatically take both 'foo/bar' and 'foo/bar/baz?'
+
+ :param paths: A list of paths to check
+ :return: A dict mapping supplied path => containing file-id where a
+ lock is being tracked.
+ """
+ ls = self._get_lock_store()
+ if ls is None:
+ return dict.fromkeys(paths, None)
+ trackers = dict.fromkeys(paths, None)
+ return trackers
+
def is_tracked(self, path):
"""For the given path, is it considered 'tracked'?"""
=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py 2009-09-22 20:46:11 +0000
+++ b/tests/test_file_lock.py 2009-09-22 21:00:47 +0000
@@ -321,21 +321,26 @@
self.assertFalse(manager2.have_lock('b'))
self.assertFalse(manager2.have_lock('b/c'))
- def test_is_tracked(self):
+ def test__get_tracked_paths(self):
+ tree, manager = self.make_simple_tree_and_manager('tree')
+ manager.initialize_lock_store(self.get_transport('lock-store'))
+ ls = manager._lock_store
+ ls._locking_info.track('file-id')
+ ls._locking_info.track('dir-id')
+ ls._locking_info.track('not-in-this-tree-id')
+ self.assertEqual(['adir', 'afile'],
+ sorted(manager._get_tracked_paths()))
+
+ def test_tracked_at(self):
tree, manager = self.make_simple_tree_and_manager('tree')
# If we have no locking store configured, then obviously it isn't
# tracked yet
- self.assertFalse(manager.is_tracked('file-id'))
- self.assertFalse(manager.is_tracked('dir-id'))
- self.assertFalse(manager.is_tracked('subfile-id'))
+ self.assertEqual({'afile': None, 'adir': None, 'adir/subfile': None},
+ manager.tracked_at(['afile', 'adir', 'adir/subfile']))
manager.initialize_lock_store(self.get_transport('lock-store'))
# Still not tracked
- self.assertFalse(manager.is_tracked('file-id'))
- manager.track('adir')
-
- def test_is_locked(self):
- tree, manager = self.make_simple_tree_and_manager('tree')
- self.assertFalse(manager.is_locked('file-id'))
+ self.assertEqual({'afile': None, 'adir': None, 'adir/subfile': None},
+ manager.tracked_at(['afile', 'adir', 'adir/subfile']))
class TestFileLockStore(tests.TestCaseWithMemoryTransport):
More information about the bazaar-commits
mailing list