Commits

ZyX_I committed b611c39

aurum.py: Made grep() use \0-separated output instead of colon+NL separated one

Comments (0)

Files changed (2)

 |aurum-rf-status|:
     For non-python driver this function does not support names containing 
     newlines.
+|aurum-rf-grep|
+    For non-python driver filenames that look like {smth}:{num>=0}:{num>0} are 
+    not supported and will lead to invalid results.
 Python driver was not tested under windows (wine) at all.
 
 Git:
         target=self._buffers[-1] if self._buffers else self._captured
         target.extend([str(a) for a in args])
 
-    def _getCaptured(self):
+    def _getCaptured(self, verbatim=False):
+        if verbatim:
+            return "".join(self._captured)
         r=[s.replace("\0", "\n") for s in ("".join(self._captured)).split("\n")]
         self._captured=[]
         return r
     except AurumError:
         pass
 
-grepre=re.compile('^(.*?)\0(0|[1-9]\d*)\0([1-9]\d*)\0(.*)$')
 def grep(path, pattern, files, revisions=None, ignore_case=False, wdfiles=True):
     try:
         repo=g_repo(path)
         kwargs={'rev': revisions, 'ignore_case': bool(ignore_case),
                 'line_number': True, 'follow': True, 'print0': True}
         run_in_dir(repo.root, commands.grep, *args, **kwargs)
-        lines=ui._getCaptured()
+        items=(ui._getCaptured(verbatim=True)).split("\0")
+        # XXX grep uses "\0" as a terminator, thus last line ends with "\0"
+        items.pop()
         r_vim=[]
         status_cache={}
         def check_not_modified_since(rev, file):
                                                     exact=True))[6]
             status_cache[key]=r
             return r
-        for line in lines:
-            m=grepre.match(line)
-            if not m:
-                continue
-            (file, rev, lnum, text)=m.groups()
+        while items:
+            file=items.pop(0)
+            rev=items.pop(0)
+            lnum=int(items.pop(0))
+            text=items.pop(0)
             if wdfiles and check_not_modified_since(rev, file):
                 file=os.path.join(repo.root, file)
             else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.