Commits

ZyX_I committed 410cb06

Added grep function to non-python driver (untested)

Comments (0)

Files changed (3)

     endif
     call s:_r.cmdutils.checkrepo(repo)
     let revisions=copy(get(a:opts, 'rev', []))
-    call map(revisions, 'repo.functions.getrevhex(repo, v:val)')
+    " call map(revisions, 'repo.functions.getrevhex(repo, v:val)')
     let revrange=get(a:opts, 'revrange', [])
     while !empty(revrange)
         let [rev1, rev2; revrange]=revrange
             let revisions+=[cs1.hex]
             continue
         endif
-        " TODO Put only ancestors of cs1 or cs2 here
-        let revisions+=map(range(cs1.rev, cs2.rev),
-                    \      'repo.functions.getrevhex(repo, v:val)')
+        let revisions+=[[cs1.hex, cs2.hex]]
     endwhile
     let files=[]
     if a:0

plugin/aurum/drivers/mercurial.vim

                 \ 'stat1mis': 'You must specify first revision as well',
                 \ 'statfail': 'Failed to obtain status information: %s',
                 \  'annfail': 'Failed to annotate revision %s of file %s: %s',
+                \ 'grepfail': 'Search failed: %s',
             \})
 endif
 "▶1 s:hypsites
     return s:F.addtosection(a:repo, hgignore, 'glob', a:glob)
 endfunction
 "▶1 hg.grep :: repo, pattern, files, revisions, ignore_case → qflist
+" revisions :: [Either rev (rev, rev)]
 if s:usepythondriver "▶2
 function s:hg.grep(repo, pattern, files, revisions, ignore_case)
     let r=[]
     return r
 endfunction
 else "▶2
+"▶3 checknotmodifiedsince
+function s:F.checknotmodifiedsince(repo, rev, file, cache)
+    if a:cache isnot 0
+        let key=a:rev.':'.a:file
+        if has_key(a:cache, key)
+            return a:cache[key]
+        endif
+    endif
+    let status=a:repo.functions.status(a:rev, 0, [a:file])
+    let r=(index(status.clean, a:file)!=-1)
+    if a:cache isnot 0
+        let a:cache[key]=r
+    endif
+    return r
+endfunction
+"▲3
 function s:hg.grep(repo, pattern, files, revisions, ignore_case)
+    let cmd='grep '.join(map(copy(a:revisions),
+            \                '((type(v:val)=='.type([]).')?'.
+            \                   '("-r".shellescape(join(v:val, "..")), 1):'.
+            \                   '("-r".shellescape(v:val, 1)))')).' '
+    if a:ignore_case
+        let cmd.='--ignore-case '
+    endif
+    let cmd.='--line-number '
+    let cmd.='-- '.shellescape(a:pattern, 1).
+                \join(map(copy(a:files), 'shellescape(v:val, 1)'))
+    let lines=s:F.hg(a:repo, cmd, 1)
+    if v:shell_error
+        call s:_f.throw('grepfail', lines[0])
+    endif
+    let epath=escape(bvar.repo.path, ':\')
+    let r=[]
+    let cnmscache={}
+    for line in lines
+        let match=matchlist(line, '\v^(.{-})\:(0|[1-9]\d*)\:([1-9]\d*)\:(.*)$')
+        if empty(match)
+            call s:_f.throw('grepfail', line)
+        endif
+        let [file, rev, lnum, text]=match[1:4]
+        if s:F.checknotmodifiedsince(a:repo, rev, file, cnmscache)
+            let file=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, file))
+        else
+            let file='aurum://file:'.epath.':'.rev.':'.file
+        endif
+        let r+=[{'filename': file, 'lnum': lnum, 'text': text}]
+    endfor
+    return r
 endfunction
 endif
 "▶1 Post resource
         ui=CaptureUI()
         args=[ui, repo, pattern]
         args.extend(files)
+        revisions=["..".join(rev) if type(rev) is list else rev]
         kwargs={'rev': revisions, 'ignore_case': bool(ignore_case),
                 'line_number': True}
         run_in_dir(repo.root, commands.grep, *args, **kwargs)
                                                     exact=True))[6]
             status_cache[key]=r
             return r
+        epath=repo.root.replace('\\', '\\\\').replace(':', '\\:')
         for line in lines:
             m=grepre.match(line)
             if not m:
             if check_not_modified_since(rev, file):
                 file=os.path.join(repo.root, file)
             else:
-                file='aurum://file:'+\
-                        repo.root.replace('\\', '\\\\').replace(':', '\\:')+\
-                        ':'+rev+':'+file
+                file='aurum://file:'+epath+':'+rev+':'+file
             r_vim.append({'filename': file, 'lnum': int(lnum), 'text': line})
         vim.eval('extend(r, '+nonutf_dumps(r_vim)+')')
     except AurumError: