Commits

ZyX_I committed 1a061d5

@aurum/drivers/git: Made rf-grep() support filenames with newlines

  • Participants
  • Parent commits e893997

Comments (0)

Files changed (3)

File doc/aurum.txt

     file A was modified in both parents, then it is to be listed in 
     merge_cs.changes only if git was unable to merge changes and had to ask 
     user to do this).
-|aurum-rf-getchangesets| is always returning empty list.
+|aurum-rf-getchangesets| is not modifying |aurum-repo.cslist|.
 |aurum-rf-grep|
     Will either search working directory (if no revisions were given) or given 
     revisions (mercurial driver is searching all revisions if no revisions are 
     given). Unlike mercurial where matching line will be shown only if they 
     were found in first revision in range or in line that was added/modified 
     in given revision, with this function you will see all matches in all 
-    revisions (really it is calling “git grep” multiple times).
+    revisions.
+    Note: This function always uses extended regular expressions.
 |aurum-rf-annotate|
     Won’t output annotation of file in working directory, it is always 
     returning annotation of file at given revision.

File plugin/aurum/drivers/git.vim

                 \   'lbf', a:type, a:label, a:rev)
 endfunction
 "▶1 git.grep :: repo, files, revisions, ignorecase, wdfiles::Bool → qflist
+"▶2 parsegrep :: lines → [(file, lnum, String)]
 function s:F.parsegrep(lines)
-    return map(a:lines, 'split(v:val, "\n", 1)')
+    let r=[]
+    let contline=0
+    while !empty(a:lines)
+        let sp=split(remove(a:lines, 0), "\n", 1)
+        if contline
+            let r[-1][0].="\n".sp[0]
+            if len(sp)>1
+                let r[-1]+=sp[1:]
+                let contline=0
+            endif
+        elseif len(sp)==1
+            let contline=1
+            let r+=[sp]
+        else
+            let r+=[sp]
+        endif
+    endwhile
+    call map(r, '[v:val[0], str2nr(v:val[1]), v:val[2]]')
+    return r
 endfunction
+"▲2
 function s:git.grep(repo, pattern, files, revisions, ic, wdfiles)
     let args=['-e', a:pattern, '--']+a:files
     let kwargs={'full-name': 1, 'extended-regexp': 1, 'n': 1, 'z': 1}

File python/aurum.py

     except AurumError:
         pass
 
-grepre=re.compile('^(.*?):(0|[1-9]\d*):([1-9]\d*):(.*)$')
+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)
         if not revisions:
             revisions=None
         kwargs={'rev': revisions, 'ignore_case': bool(ignore_case),
-                'line_number': True, 'follow': True}
+                'line_number': True, 'follow': True, 'print0': True}
         run_in_dir(repo.root, commands.grep, *args, **kwargs)
         lines=ui._getCaptured()
         r_vim=[]