Commits

ZyX_I  committed ae47ed9

@%aurum/drivers/common/utils: _r.utils.getcmd() now accepts kwargs key values 0 and [...]
@%aurum/drivers/mercurial: Added repo.functions.phase()
Improved boolean arguments support in runcmd
Tests under wine are still failing
Ref #44

  • Participants
  • Parent commits 1094f0e

Comments (0)

Files changed (6)

File autoload/aurum/drivers/common/utils.vim

 "▶1
 scriptencoding utf-8
-execute frawor#Setup('0.0', {'@/resources': '0.0',
+execute frawor#Setup('0.1', {'@/resources': '0.0',
             \                       '@/os': '0.2'})
 let s:utils={}
 "▶1 utils.getcmd :: cmd, args, kwargs, esc → sh
+let s:prefexpr='repeat("-", 1+(len(v:val[0])>1)).v:val[0]." ="[len(v:val[0])>1]'
 function s:utils.getcmd(cmd, args, kwargs, esc)
     let cmd=a:cmd
     if !empty(a:kwargs)
         let cmd.=' '.join(map(filter(items(a:kwargs), 'v:val[1] isnot 0'),
                 \             '((v:val[1] is 1)?'.
                 \               '(repeat("-", 1+(len(v:val[0])>1)).v:val[0]):'.
-                \               '(repeat("-", 1+(len(v:val[0])>1)).v:val[0].'.
-                \                              '" ="[len(v:val[0])>1].'.
-                \                              'shellescape(v:val[1],a:esc)))'))
+                \             '((v:val[1] is 0)?'.
+                \               '(""):'.
+                \             '((type(v:val[1])=='.type([]).')?'.
+                \               '(join(map(copy(v:val[1]), '.
+                \                         '"\"".'.s:prefexpr.'."\".'.
+                \                           'shellescape(v:val,    a:esc)"))):'.
+                \               '('.s:prefexpr.'.'.
+                \                           'shellescape(v:val[1], a:esc)))))'
+                \            ))
     endif
     if !empty(a:args)
         let cmd.=' '.join(map(copy(a:args), 'shellescape(v:val, a:esc)'))

File autoload/aurum/drivers/mercurial.vim

 scriptencoding utf-8
 execute frawor#Setup('0.2', {'@%aurum/drivers/common/hypsites': '0.0',
             \                                   '@%aurum/repo': '5.0',
-            \                   '@%aurum/drivers/common/utils': '0.0',
+            \                   '@%aurum/drivers/common/utils': '0.1',
             \                                       '@/python': '0.0',
             \                                           '@/os': '0.0',
             \                                      '@/options': '0.0',})
             \             '(importing GitHandler threw ImportError)',
             \ 'nogitrev': 'No git revision associated with revision %s '.
             \             'in repository %s',
+            \ 'uknphase': 'Unknown phase: %s. Known phases: %s.',
         \}
 "▶1 Options
 let s:_options={
         endfor
     endfor
 endfunction
-"▶2 runcmd :: repo, attr, args, kwargs → + ?
-function s:F.runcmd(repo, attr, args, kwargs)
+"▶2 runcmd :: repo, attr, args, kwargs[, bkwargs] → + ?
+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:py 'aurum.call_cmd(vim.eval("a:repo.path"), '.
                 \               'vim.eval("a:attr"), '.
+                \               ((a:0)?(string(a:1)):('None')).', '.
                 \               '*vim.eval("a:args"), '.
                 \               '**vim.eval("a:kwargs"))'
 endfunction
         if a:repo.hasphases
             call map(s:F.hg(a:repo, 'phase', [], {'rev': ':'}, 0),
                         \'has_key(revmap, v:key) && '.
-                        \   'extend(revmap[v:key], '.
-                        \          '{"phase": v:val[stridx(v:val, " ")+1:]})')
+                        \   'empty(extend(revmap[v:key], '.
+                        \                '{"phase": '.
+                        \                     'v:val[stridx(v:val, " ")+1:]}))')
         endif
     endfunction
 endif
 endfunction
 "▶1 hg.branch :: repo, branchname, force → + FS
 function s:hg.branch(repo, branch, force)
-    return s:F.runcmd(a:repo, 'branch', [a:branch], a:force ? {'force': 1} : {})
+    return s:F.runcmd(a:repo, 'branch', [a:branch], {'force': !!a:force})
 endfunction
 "▶1 hg.label :: repo, type, label, rev, force, local → + FS
 function s:hg.label(repo, type, label, rev, force, local)
     let kwargs={}
-    if a:force
-        let kwargs.force=1
-    endif
+    let kwargs.force=(!!a:force)
     if a:type is# 'tag'
         if a:local
             let kwargs.local=1
     endif
     return s:F.runcmd(a:repo, a:type, [a:label], kwargs)
 endfunction
+"▶1 hg.phase :: repo, rev, phase[, force] → + FS
+let s:phaselist=['public', 'draft', 'secret']
+let s:phaseliststr=join(s:phaselist, ', ')
+function s:hg.phase(repo, rev, phase, ...)
+    let kwargs={}
+    let kwargs.force=(a:0 && a:1)
+    if index(s:phaselist, a:phase)==-1
+        call s:_f.throw('uknphase', a:phase, s:phaseliststr)
+    endif
+    for phase in s:phaselist
+        " XXX something inside mercurial expects
+        let kwargs[phase]=(a:phase is# phase)
+    endfor
+    let kwargs.rev=[a:rev]
+    return s:F.runcmd(a:repo, 'phase', [], kwargs, s:phaselist)
+endfunction
 "▶1 hg.update :: repo, rev, force
 if s:usepythondriver "▶2
 function s:hg.update(repo, rev, force)
 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} : {})
+    return s:F.runcmd(a:repo, 'rename', a:000, {'force': (!!a:force)})
 endfunction
 "▶1 hg.copy :: repo, force, source, target → + FS
 function s:hg.copy(repo, force, ...)
-    return s:F.runcmd(a:repo, 'copy', a:000, a:force ? {'force': 1} : {})
+    return s:F.runcmd(a:repo, 'copy', a:000, {'force': (!!a:force)})
 endfunction
 "▶1 hg.add :: repo, file → + FS
 function s:hg.add(repo, ...)

File doc/aurum.txt

     Functions supporting this option: |aurum-rf-commit|, |aurum-rf-update|, 
     |aurum-rf-move| (uses "rename" mercurial command), |aurum-rf-copy|, 
     |aurum-rf-forget|, |aurum-rf-remove|, |aurum-rf-add|, |aurum-rf-branch|, 
-    |aurum-rf-label| (uses "tag" or "bookmark" Mercurial commands). Every 
-    function except |aurum-rf-move| and |aurum-rf-label| uses Mercurial 
-    command identical to its name.
+    |aurum-rf-label| (uses "tag" or "bookmark" Mercurial commands), 
+    |aurum-rf-phase|. Every function except |aurum-rf-move| and 
+    |aurum-rf-label| uses Mercurial command identical to its name.
 
 git_maxitercsnum                                    *g:aurum_git_maxitercsnum*
     Unsigned (non-negative) integer, must be less then a number of arguments 
 *aurum-rf-githex* exists and produces git sha1 out of repository object and 
     mercurial revision specification. This function is present only when using 
     python version of driver.
+*aurum-rf-phase* exists and changes phase of the given changeset when called 
+    with repository, mercurial revision specification and one of phase names 
+    (public, draft, secret). Optionally accepts boolean as the fourth argument 
+    (equivalent to “hg phase --force”).
 Python driver was not tested under windows (wine) at all.
 
 ------------------------------------------------------------------------------
     0.1: Added OpenAny and AnnotateAny mappings.
 @%aurum/drivers/common/hypsites:
     0.1: Added dict.hlines key (see version 0.4 of @aurum).
+@%aurum/drivers/common/utils:
+    0.1: _r.utils.getcmd() now accepts kwargs key values 0 and [...]
 
 vim: ft=help:tw=78

File python/aurum.py

         vim_throw('nocfg', repo.path, prop)
 
 @outermethod
-def call_cmd(repo, attr, *args, **kwargs):
+def call_cmd(repo, attr, bkwargs, *args, **kwargs):
+    if bkwargs:
+        for kw in bkwargs:
+            if kw in kwargs:
+                kwargs[kw]=bool(int(kwargs[kw]))
     if 'force' in kwargs:
-        kwargs['force']=bool(kwargs['force'])
+        kwargs['force']=bool(int(kwargs['force']))
     else:
         kwargs['force']=False
     if 'bundle' not in kwargs:

File test/cmd-log-templates.in

 :ST $renames#->#
 :ST $copies
 :ST $copies#->#
+:R let g:repo=aurum#repository()
+:silent! call repo.functions.phase(repo, '-4', 'public', 1)
+:        call repo.functions.phase(repo, '-3', 'draft',  1)
+:        call repo.functions.phase(repo, '-2', 'secret', 1)
+:ST $phase
+:ST $phase#keep#$empty
 :source addmessages.vim

File test/cmd-log-templates.ok

 |  
 o  
 |  
+{{{1 $phase
+@  secret
+|  
+o    secret
+|\   
+o |  draft
+| |  
+| o  
+|/   
+o  
+|  
+o  
+|  
+o  
+|  
+o  
+|  
+o  
+|  
+o    
+|\   
+o \    
+|\ \   
+| | o    
+| | |\   
+| | o \    
+| | |\ \   
+| | | | | o  
+| | | | |/   
+| +-----o  
+| | | |    
+| +-----o  
+| | | |    
+| o | |  
+| | | |  
+o | | |    
+|\ \ \ \   
+| | o | |  
+| |/ / /   
+| o---+  
+|  / /   
+| | o  
+| |/   
+| o  
+|/   
+o  
+|  
+o  
+|  
+o  
+|  
+o  
+|  
+o  
+|  
+{{{1 $phase#keep#$empty
+@  secret
+|  
+o    secret
+|\   
+o |  draft
+| |  
+| o  public
+|/   
+o  public
+|  
+o  public
+|  
+o  public
+|  
+o  public
+|  
+o  public
+|  
+o    public
+|\   
+o \    public
+|\ \   
+| | o    public
+| | |\   
+| | o \    public
+| | |\ \   
+| | | | | o  public
+| | | | |/   
+| +-----o  public
+| | | |    
+| +-----o  public
+| | | |    
+| o | |  public
+| | | |  
+o | | |    public
+|\ \ \ \   
+| | o | |  public
+| |/ / /   
+| o---+  public
+|  / /   
+| | o  public
+| |/   
+| o  public
+|/   
+o  public
+|  
+o  public
+|  
+o  public
+|  
+o  public
+|  
+o  public
+|