Rev 5: Make the plugin works again by locking the working tree. in file:///v/home/vila/.bazaar/plugins/grep/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Dec 14 14:58:56 GMT 2007


At file:///v/home/vila/.bazaar/plugins/grep/

------------------------------------------------------------
revno: 5
revision-id:v.ladeuil+lp at free.fr-20071214145856-6sjcgl3cpa9x88q7
parent: michael at ellerman.id.au-20060323132013-3ec31eb8319d9331
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: grep
timestamp: Fri 2007-12-14 15:58:56 +0100
message:
  Make the plugin works again by locking the working tree.
  
  * __init__.py: 
  Fix imports.
  (cmd_grep): Lock the working tree so that the plugin works again.
modified:
  __init__.py                    __init__.py-20060323100923-17d68e8a2f14f018
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2006-03-23 13:20:13 +0000
+++ b/__init__.py	2007-12-14 14:58:56 +0000
@@ -1,13 +1,15 @@
 #!/usr/bin/python
 """Grep through your working tree, but only files managed by bzr."""
 
-import bzrlib.commands
-from bzrlib.option import Option
-from bzrlib.builtins import tree_files
-from bzrlib.osutils import is_inside_any
-from subprocess import Popen, PIPE
-
-class cmd_grep(bzrlib.commands.Command):
+import subprocess
+
+from bzrlib import (
+    builtins,
+    commands,
+    osutils,
+    )
+
+class cmd_grep(commands.Command):
     """Grep through your working tree, but only files managed by bzr.
 
     By default this is a recursive grep, unless you specify --no-recurse.
@@ -22,12 +24,14 @@
     takes_args = ['pattern', 'file*']
     takes_options = ['no-recurse']
 
-    @bzrlib.commands.display_command
+    @commands.display_command
     def run(self, pattern, no_recurse=False, file_list=None):
         options, file_list = self._read_options(file_list)
 
-        tree, file_list = tree_files(file_list)
+        tree, file_list = builtins.tree_files(file_list)
+        tree.lock_read()
         inv = tree.read_working_inventory()
+        tree.unlock()
 
         cmd = ['xargs', '-0', 'grep', '-e', pattern]
         cmd.extend(options)
@@ -35,14 +39,14 @@
         #print cmd
         #print file_list
 
-        xargs = Popen(cmd, stdin=PIPE)
+        xargs = subprocess.Popen(cmd, stdin=subprocess.PIPE)
 
         for path, entry in inv.entries():
             if file_list:
                 if no_recurse:
                     if not path in file_list:
                         continue
-                elif not is_inside_any(file_list, path):
+                elif not osutils.is_inside_any(file_list, path):
                     continue
             xargs.stdin.write('%s\0' % path)
 
@@ -60,7 +64,6 @@
         files = []
         options = []
 
-
         while len(list) > 0:
             item = list.pop(0)
 
@@ -73,4 +76,4 @@
 
         return options, files
 
-bzrlib.commands.register_command(cmd_grep)
+commands.register_command(cmd_grep)



More information about the bazaar-commits mailing list