ZyX_I avatar ZyX_I committed 6fed342

@aurum/drivers/common/utils, @aurum/drivers/*:
Improved rf-readfile() in all drivers that use shell commands:
it should now correctly deal with binary files

Comments (0)

Files changed (4)

plugin/aurum/drivers/common/utils.vim

     endif
     return cmd
 endfunction
-"▶1 utils.run :: sh, hasnulls::Bool → [String] + shell
+"▶1 utils.run :: sh, hasnulls::0|1|2 → [String] + shell
 function s:utils.run(cmd, hasnulls, cdpath)
-    if a:hasnulls
+    if a:hasnulls==2 && !empty(&shellredir)
+        let tempfile=tempname()
+        let etempfile=shellescape(tempfile, 1)
+        let cmd=a:cmd
+        if stridx(&shellredir, '%s')!=-1
+            let cmd.=printf(&shellredir, etempfile)
+        else
+            let cmd.=&shellredir.etempfile
+        endif
+        if !empty(a:cdpath)
+            let cmd='cd '.shellescape(a:cdpath).' && '.cmd
+        endif
+        try
+            execute 'silent! !'.cmd
+            if !filereadable(tempfile)
+                return s:utils.run(a:cmd, 1, a:cdpath)
+            endif
+            return readfile(tempfile, 'b')
+        finally
+            if filereadable(tempfile)
+                call delete(tempfile)
+            endif
+        endtry
+    elseif a:hasnulls
         let savedlazyredraw=&lazyredraw
         set lazyredraw
         noautocmd tabnew
             noautocmd execute 'lcd' fnameescape(a:cdpath)
         endif
         " XXX this is not able to distinguish between output with and without 
-        " trailing newline
+        " trailing newline, and also is “smart” about lineendings
         noautocmd execute '%!'.a:cmd
         let r=getline(1, '$')
         noautocmd bwipeout!

plugin/aurum/drivers/git.vim

 endfunction
 "▶1 git.readfile :: repo, rev, file → [String]
 function s:git.readfile(repo, rev, file)
-    return s:F.git(a:repo, 'cat-file', ['blob', a:rev.':'.a:file], {}, 1,
+    return s:F.git(a:repo, 'cat-file', ['blob', a:rev.':'.a:file], {}, 2,
                 \  'filef', a:rev, a:file)
 endfunction
 "▶1 git.diff :: repo, rev, rev, files, opts → [String]

plugin/aurum/drivers/mercurial.vim

 endfunction
 else "▶2
 function s:hg.readfile(repo, rev, file)
-    return s:F.hg(a:repo, 'cat', ['--',a:file], {'rev': ''.a:rev}, 1,
+    return s:F.hg(a:repo, 'cat', ['--',a:file], {'rev': ''.a:rev}, 2,
                 \ 'file', a:file)
 endfunction
 endif

plugin/aurum/drivers/subversion.vim

 endfunction
 "▶1 svn.readfile :: repo, rev, file → [String]
 function s:svn.readfile(repo, rev, file)
-    return s:F.svn(a:repo, 'cat', ['--', a:file], {'revision': a:rev}, 1,
+    return s:F.svn(a:repo, 'cat', ['--', a:file], {'revision': a:rev}, 2,
                 \  'filef', a:rev, a:file)
 endfunction
 "▶1 svn.diff :: repo, rev, rev, files, opts → [String]
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.