Rev 2316: Find callers of list_files() and make sure the tree is always locked. in http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate

John Arbash Meinel john at arbash-meinel.com
Thu Feb 15 17:57:19 GMT 2007


At http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate

------------------------------------------------------------
revno: 2316
revision-id: john at arbash-meinel.com-20070215175610-171tue5qcl4zm6vf
parent: john at arbash-meinel.com-20070215171830-7xzy2cxja9g6vclm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Thu 2007-02-15 11:56:10 -0600
message:
  Find callers of list_files() and make sure the tree is always locked.
modified:
  bzrlib/benchmarks/bench_workingtree.py bench_workingtree.py-20060527061822-cxrgsa9ax2q4d82q-1
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/test_conflicts.py test_conflicts.py-20051006031059-e2dad9bbeaa5891f
-------------- next part --------------
=== modified file 'bzrlib/benchmarks/bench_workingtree.py'
--- a/bzrlib/benchmarks/bench_workingtree.py	2007-02-02 04:49:38 +0000
+++ b/bzrlib/benchmarks/bench_workingtree.py	2007-02-15 17:56:10 +0000
@@ -27,7 +27,11 @@
 
     def test_list_files_kernel_like_tree(self):
         tree = self.make_kernel_like_added_tree()
-        self.time(list, tree.list_files())
+        tree.lock_read()
+        try:
+            self.time(list, tree.list_files())
+        finally:
+            tree.unlock()
 
     def test_list_files_unknown_kernel_like_tree(self):
         tree = self.make_kernel_like_tree(link_working=True)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-02-01 23:48:08 +0000
+++ b/bzrlib/builtins.py	2007-02-15 17:56:10 +0000
@@ -1577,37 +1577,41 @@
         elif tree is None:
             tree = branch.basis_tree()
 
-        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
-            if fp.startswith(relpath):
-                fp = osutils.pathjoin(prefix, fp[len(relpath):])
-                if non_recursive and '/' in fp:
-                    continue
-                if not all and not selection[fc]:
-                    continue
-                if kind is not None and fkind != kind:
-                    continue
-                if verbose:
-                    kindch = entry.kind_character()
-                    outstring = '%-8s %s%s' % (fc, fp, kindch)
-                    if show_ids and fid is not None:
-                        outstring = "%-50s %s" % (outstring, fid)
-                    self.outf.write(outstring + '\n')
-                elif null:
-                    self.outf.write(fp + '\0')
-                    if show_ids:
+        tree.lock_read()
+        try:
+            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
+                if fp.startswith(relpath):
+                    fp = osutils.pathjoin(prefix, fp[len(relpath):])
+                    if non_recursive and '/' in fp:
+                        continue
+                    if not all and not selection[fc]:
+                        continue
+                    if kind is not None and fkind != kind:
+                        continue
+                    if verbose:
+                        kindch = entry.kind_character()
+                        outstring = '%-8s %s%s' % (fc, fp, kindch)
+                        if show_ids and fid is not None:
+                            outstring = "%-50s %s" % (outstring, fid)
+                        self.outf.write(outstring + '\n')
+                    elif null:
+                        self.outf.write(fp + '\0')
+                        if show_ids:
+                            if fid is not None:
+                                self.outf.write(fid)
+                            self.outf.write('\0')
+                        self.outf.flush()
+                    else:
                         if fid is not None:
-                            self.outf.write(fid)
-                        self.outf.write('\0')
-                    self.outf.flush()
-                else:
-                    if fid is not None:
-                        my_id = fid
-                    else:
-                        my_id = ''
-                    if show_ids:
-                        self.outf.write('%-50s %s\n' % (fp, my_id))
-                    else:
-                        self.outf.write(fp + '\n')
+                            my_id = fid
+                        else:
+                            my_id = ''
+                        if show_ids:
+                            self.outf.write('%-50s %s\n' % (fp, my_id))
+                        else:
+                            self.outf.write(fp + '\n')
+        finally:
+            tree.unlock()
 
 
 class cmd_unknowns(Command):
@@ -1712,12 +1716,16 @@
     @display_command
     def run(self):
         tree = WorkingTree.open_containing(u'.')[0]
-        for path, file_class, kind, file_id, entry in tree.list_files():
-            if file_class != 'I':
-                continue
-            ## XXX: Slightly inefficient since this was already calculated
-            pat = tree.is_ignored(path)
-            print '%-50s %s' % (path, pat)
+        tree.lock_read()
+        try:
+            for path, file_class, kind, file_id, entry in tree.list_files():
+                if file_class != 'I':
+                    continue
+                ## XXX: Slightly inefficient since this was already calculated
+                pat = tree.is_ignored(path)
+                print '%-50s %s' % (path, pat)
+        finally:
+            tree.unlock()
 
 
 class cmd_lookup_revision(Command):

=== modified file 'bzrlib/tests/test_conflicts.py'
--- a/bzrlib/tests/test_conflicts.py	2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/test_conflicts.py	2007-02-15 17:56:10 +0000
@@ -58,7 +58,9 @@
         file('hello.OTHER', 'w').write('hello world3')
         file('hello.sploo.BASE', 'w').write('yellow world')
         file('hello.sploo.OTHER', 'w').write('yellow world2')
+        tree.lock_read()
         self.assertEqual(len(list(tree.list_files())), 6)
+        tree.unlock()
         conflicts = tree.conflicts()
         self.assertEqual(len(conflicts), 2)
         self.assert_('hello' in conflicts[0].path)



More information about the bazaar-commits mailing list