Commits

ZyX_I committed 4407697

@aurum/drivers/mercurial: Added “hg_useshell” option (untested). Closes #5

Comments (0)

Files changed (3)

     added to the aurum.
     Values of this option are checked before |aurum-repo.hypsites|.
 
+The following options are driver-specific:
+
+hg_useshell                                              *g:aurum_hg_useshell*
+    List (either true list or string with values separated by anything that is 
+    not a lowercase letter) of Mercurial commands that are to be called 
+    without using Mercurial Python API.
+
+    Functions supporting this option: |rf-commit|, |rf-update|, |rf-move| 
+    (uses "rename" mercurial command), |rf-copy|, |rf-forget|, |rf-remove|, 
+    |rf-add|, |rf-branch|, |rf-label| (uses "tag" or "bookmark" Mercurial 
+    commands). Every function except |rf-move| and |rf-label| uses Mercurial 
+    command identical to its name.
+
 ==============================================================================
 5. Globs                                                         *aurum-globs*
 

plugin/aurum/drivers/mercurial.vim

     execute frawor#Setup('0.1', {      '@/python': '0.0',
                 \                   '@aurum/repo': '1.0',
                 \                          '@/os': '0.0',
+                \                     '@/options': '0.0',
                 \   '@aurum/drivers/common/utils': '0.0',
                 \'@aurum/drivers/common/hypsites': '0.0',}, 0)
     finish
             \ 'stat1mis': 'You must specify first revision as well',
         \}
 let s:nullrev=repeat('0', 40)
+let s:_options={
+            \'hg_useshell': {'default': [],
+            \                 'filter':
+            \                   '(if type "" (|=split(@.@,''\L\+'')) any '.
+            \                    'list match /\v^\l+$/)'},
+        \}
 "▶1 s:hypsites
 let s:hypsites=[]
 let s:gitrev='((!empty(cs.bookmarks))?'.
     return 'hg -R '.shellescape(a:repo.path, a:4).' '.
                 \call(s:_r.utils.getcmd, a:000, {})
 endfunction
+"▶1 runshellcmd :: repo, attr, args, kwargs → + ?
+function s:F.runshellcmd(repo, attr, args, kwargs, ...)
+    let e=(a:0 && a:1)
+    let args=copy(a:args)
+    if !empty(args)
+        call insert(args, '--')
+    endif
+    return s:_r.utils.printm(s:F.hg(a:repo, a:attr, args, a:kwargs, e)[:-2+e])
+endfunction
 "▶1 hg :: repo, cmd, args, kwargs, esc, msgid[, throwarg1[, …]] → [String]
 function s:F.hg(repo, cmd, args, kwargs, hasnulls, ...)
     let cmd=s:F.hgcmd(a:repo, a:cmd, a:args, a:kwargs, a:hasnulls)
         endfor
     endfor
 endfunction
+"▶2 runcmd :: repo, attr, args, kwargs → + ?
+function s:F.runcmd(repo, attr, args, kwargs)
+    if index(s:_f.getoption('hg_useshell'), a:attr)!=-1
+        return s:F.runshellcmd(a:repo, a:attr, a:args, a:kwargs)
+    endif
+    execute s:_r.py.cmd 'aurum.call_cmd(vim.eval("a:repo.path"), '.
+                \                      'vim.eval("a:attr"), '.
+                \                      '*vim.eval("a:args"), '.
+                \                      '**vim.eval("a:kwargs"))'
+endfunction
 "▲2
 else "▶1
 "▶2 addchangesets :: repo, [cs] → _ + repo
                 \                         '''\v^(.{-})\ +(\d+)\:\x{12}'')[1:2]')
 endfunction
 "▲2
+let s:F.runcmd=s:F.runshellcmd
 endif
 "▶1 hg.updatechangesets :: repo → + repo
 "▶2 python
 endfunction
 endif
 "▶1 hg.commit :: repo, message[, files[, user[, date[, closebranch[, force]]]]]
-if s:usepythondriver "▶2
-function s:hg.commit(repo, message, ...)
-    let args  =  'text=vim.eval("a:message"), '.
-                \join(map(['files', 'user', 'date', 'close_branch'],
-                \         'v:val."=".(empty(a:000[v:key])?'.
-                \                       '"None":'.
-                \                       '"vim.eval(''a:".(v:key+1)."'')")'),
-                \     ', ')
-    try
-        execute s:_r.py.cmd 'aurum.commit(vim.eval("a:repo.path"), '.args.')'
-    endtry
-endfunction
-else "▶2
 function s:hg.commit(repo, message, ...)
     let kwargs={}
     let usingfile=0
         endif
     endif
     try
-        call s:F.runcmd(a:repo, 'commit', args, kwargs, 0)
+        call s:F.runcmd(a:repo, 'commit', args, kwargs)
     finally
         if usingfile && filereadable(tmpfile)
             call delete(tmpfile)
         endif
     endtry
 endfunction
-endif
 "▶1 hg.update :: repo, rev, force
 if s:usepythondriver "▶2
 function s:hg.update(repo, rev, force)
     call s:_f.throw('nocfg', a:prop, a:repo.path)
 endfunction
 endif
-"▶1 runcmd :: repo, attr, args, kwargs → + ?
-if s:usepythondriver "▶2
-function s:F.runcmd(repo, attr, args, kwargs)
-    execute s:_r.py.cmd 'aurum.call_cmd(vim.eval("a:repo.path"), '.
-                \                      'vim.eval("a:attr"), '.
-                \                      '*vim.eval("a:args"), '.
-                \                      '**vim.eval("a:kwargs"))'
-endfunction
-else "▶2
-function s:F.runcmd(repo, attr, args, kwargs, ...)
-    let e=(a:0 && a:1)
-    let args=copy(a:args)
-    if !empty(args)
-        call insert(args, '--')
-    endif
-    return s:_r.utils.printm(s:F.hg(a:repo, a:attr, args, a:kwargs, e)[:-2+e])
-endfunction
-endif
 "▶1 hg.move :: repo, force, source, target → + FS
 function s:hg.move(repo, force, ...)
     return s:F.runcmd(a:repo, 'rename', a:000, a:force ? {'force': 1} : {})
     except AurumError:
         pass
 
-def commit(path, text, user=None, date=None, files=None, close_branch=False):
-    try:
-        repo=g_repo(path)
-        if not hasattr(repo, 'commit'):
-            vim_throw('comuns', repo.path)
-        args=[PrintUI(), repo]
-        kwargs={'close_branch': close_branch, 'message': text}
-        if files:
-            args.extend(files)
-            kwargs['addremove']=True
-        if date:
-            kwargs['date']=date
-        if user:
-            kwargs['user']=user
-        run_in_dir(repo.root, commands.commit, *args, **kwargs)
-    except AurumError:
-        pass
-
 def update(path, rev='tip', force=False):
     try:
         repo=g_repo(path)