Commits

ZyX_I  committed 7b8bde3

@%aurum/drivers/mercurial, @%aurum/log/templates: Initial phases support.
Still missing tests, aurum#phase() and phase segment.
Ref #44.

  • Participants
  • Parent commits f672b8d

Comments (0)

Files changed (6)

File autoload/aurum/drivers/mercurial.vim

     "▶3 Simple keys: rev, hex, branch, time, user
     let cs.rev    = str2nr(a:csdata[line])    | let line+=1
     let cs.hex    = a:csdata[line]            | let line+=1
+    let cs.phase  = a:csdata[line]            | let line+=1
     let cs.branch = s:F.unesc(a:csdata[line]) | let line+=1
     let cs.time   = str2nr(a:csdata[line])    | let line+=1
     let cs.user   = s:F.unesc(a:csdata[line]) | let line+=1
+    if empty(cs.phase)
+        let cs.phase='unknown'
+    endif
     "▶3 List keys: parents, tags, bookmarks, changes, removes
     for [char, key] in s:chars
         let cs[key]=[]
             execute s:py 'aurum.get_tags(vim.eval("a:repo.path"))'
         endtry
         call s:F.updatewithtagsdict(a:repo.changesets, d)
+        if a:repo.hasphases
+            try
+                execute s:py 'aurum.get_phases(vim.eval("a:repo.path"))'
+            endtry
+            " XXX empty() is here in order to prevent “using dictionary as 
+            "     a Number” error
+            call map(d.phasemap, 'has_key(a:repo.changesets, v:key) && '.
+                        \           'empty(extend(a:repo.changesets[v:key], '.
+                        \                        '{"phase": v:val}))')
+        endif
     endfunction
 "▶2 no python
 else
                 let r[key][name]=a:repo.mutable.cslist[rev].hex
             endfor
         endfor
+        if a:repo.hasphases
+            let r.phases=map(s:F.hg(a:repo, 'phase', [],
+                        \           {'rev': '0:'.(a:start-1)}, 0),
+                        \           'v:val[stridx(v:val, " ")+1:]')
+        endif
         let a:repo.csnum=a:start+len(r.css)
         return r
     endfunction
             call map(values(cd), 'sort(v:val)')
         endfor
         call s:F.updatewithtagsdict(revmap, d)
+        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:]})')
+        endif
     endfunction
 endif
 "▶2 hg.updatechangesets
             call sort(cs[key])
         endfor
     endfor
+    if has_key(d, 'phases')
+        let i=0
+        for phase in d.phases
+            let a:repo.mutable.cslist[i].phase=phase
+            let i+=1
+        endfor
+    endif
     let a:repo.mutable.cslist+=d.css
     call s:F.addchangesets(a:repo, d.css)
 endfunction
     if a:prop is# 'branch'
         return s:F.hg(a:repo, 'branch', [], {}, 0, 'b')[0]
     elseif a:prop is# 'tagslist' || a:prop is# 'brancheslist' ||
-                \               a:prop is# 'bookmarkslist'
+                \                   a:prop is# 'bookmarkslist'
         return map(copy(s:F.getkeylist(a:repo, a:prop[:-5])), 'v:val[0]')
     elseif a:prop is# 'url'
         let lines=s:F.hg(a:repo, 'showconfig', ['paths'], {}, 0, 'sc')[:-2]
     return repo
 endfunction
 else "▶2
+function s:F.trycmd(repo, cmd)
+    try
+        return !empty(s:F.hg(a:repo, 'help', [a:cmd], {}, 0))
+    catch
+        return 0
+    endtry
+endfunction
 function s:hg.repo(path)
     " TODO remove bookmark label type if it is not available
     let repo={'path': a:path, 'changesets': {}, 'mutable': {'cslist': []},
                 \'hypsites': deepcopy(s:hypsites),
                 \'initprops': ['rev', 'hex', 'parents', 'tags', 'bookmarks',
                 \              'branch', 'time', 'user', 'changes', 'removes',
-                \              'copies', 'renames', 'files', 'description']}
+                \              'copies', 'renames', 'files', 'description',
+                \              'phase']}
+    let repo.hasphases=s:F.trycmd(repo, 'phase')
+    if !s:F.trycmd(repo, 'bookmark')
+        call filter(repo.labeltypes, 'v:val isnot# "bookmark"')
+        let repo.hasbookmarks=0
+    else
+        let repo.hasbookmarks=1
+    endif
     return repo
 endfunction
 endif

File autoload/aurum/log/templates.vim

 let s:kwexpr.empty       = [0, '@@@']
 let s:kwexpr.hex         = [0, '@@@']
 let s:kwexpr.branch      = [0, '@@@', 'keep']
+let s:kwexpr.phase       = [0, '@@@', 'skip']
 let s:kwexpr.user        = [0, '@@@']
 let s:kwexpr.rev         = [0, '@@@', 'ignore']
 let s:kwexpr.time        = [0, 'strftime(@0@, @@@)', '%d %b %Y %H:%M']
             \'rev' : '\d\+',
             \'parents': '\v\x{12,}( \x{12,})?',
             \'children': '\v\x{12,}( \x{12,})*',
+            \'phase': '\v(public|draft|secret)',
         \}
 let s:kwreqseqkw=['hex', 'branch', 'user', 'rev', 'time', 'parents', 'children',
-            \     'tags', 'bookmarks', 'description', 'files', 'changes']
+            \     'tags', 'bookmarks', 'description', 'files', 'changes',
+            \     'phase']
 let s:kwreqs = {'stat': {'files': 1},
             \'renames': {'files': 1, 'renames': 1},
             \ 'copies': {'files': 1, 'copies': 1},
 "▶2 add.ke0 : Add single-line statement
 function s:add.ke0(addedif, expr, kw, arg, func)
     let func=a:func
-    let add2if=(a:kw is# 'branch' && a:arg.0 isnot# 'keep' && !a:addedif)
-    if add2if
+    let add2if=0
+    if a:kw is# 'branch' && a:arg.0 isnot# 'keep' && !a:addedif
+        let add2if=1
         let func+=['if a:cs.branch isnot# "default"']
+    elseif a:kw is# 'phase' && a:arg.0 isnot# 'keep' && !a:addedif
+        let add2if=1
+        let func+=['if a:cs.phase isnot# "public"']
     endif
     let func+=['let estr='.a:expr]
     "▶3 Determine condition on which suffix or prefix will be added
         let condition='!empty(estr)'
     elseif a:kw is# 'branch'
         let condition='estr isnot# "default"'
+    elseif a:kw is# 'phase'
+        let condition='estr isnot# "public"'
     elseif a:kw is# 'rev'
         let condition=0
     endif
         let func+=['let files=a:opts.csfiles[a:cs.hex]']
     endif
     let hasrevisions=get(a:repo, 'hasrevisions', 1)
+    let hasphases=get(a:repo, 'hasphases', 0)
     if get(a:opts, 'patch', 0) || get(a:opts, 'stat', 0)
         let filesarg=((hasfiles && !has_key(a:opts.ignorefiles, 'patch'))?
                     \   ('files'):
             elseif kw is# 'branch'
                 let addedif=1
                 let func+=['if a:cs.branch isnot# "default"']
+            elseif kw is# 'phase'
+                if !hasphases
+                    continue
+                else
+                    let addedif=1
+                    let func+=['if a:cs.phase isnot# "public"']
+                endif
             elseif kw is# 'rev' && !hasrevisions
                 continue
             endif
                 "▶2 Skip meta if required
                 if kw is# 'rev' && !hasrevisions && arg.0 isnot# 'keep'
                     continue
+                elseif kw is# 'phase' && !hasphases
+                    continue
                 endif
                 "▶2 Add requirements information
                 if has_key(s:kwreqs, kw)
     let r=[]
     let topgroups=[]
     let hasrevisions=get(a:repo, 'hasrevisions', 1)
+    let hasphases=get(a:repo, 'hasphases', 0)
     "▲2
     let r+=['syn match auLogFirstLineStart =\v^[^ ]*[@o][^ ]* = '.
                 \'skipwhite nextgroup=']
                     let hasmult=1
                 endif
                 if kw is# 'empty' || (kw is# 'rev' && !hasrevisions &&
-                            \         arg.0 isnot# 'keep')
+                            \         arg.0 isnot# 'keep') ||
+                            \        (kw is# 'phase' && !hasphases)
                     let r[-1]=substitute(r[-1], '\v\w+$', '', '')
                 elseif has_key(arg, 'synreg')
                     call s:F.addgroup(r, nlgroups, 'auLog_'.kw)
                     let r+=['syn match '.sname.' /\V'.escape(arg[0], '\/').'/ '.
                                 \'contained nextgroup=']
                 elseif (index(s:kwpempt, kw)!=-1 || kw is# 'branch' ||
-                            \                       kw is# 'rev') &&
+                            \                       kw is# 'rev'    ||
+                            \                       kw is# 'phase') &&
                             \(has_key(arg, 'pref') || has_key(arg, 'suf'))
                     " Case kw=='rev' with !repo.hasrevisions is caught in the 
                     " first branch

File autoload/aurum/repo.vim

 "▶1
-execute frawor#Setup('5.0', {'@/resources': '0.0',
+execute frawor#Setup('5.1', {'@/resources': '0.0',
             \                       '@/os': '0.0',
             \                  '@/options': '0.0',
             \          '@%aurum/lineutils': '0.0',
     endfor
     return {'addrevs': [cs], 'revisions': {}, 'repo': a:repo,
                 \'hasrevisions': get(a:repo, 'hasrevisions', 1),
+                \'hasphases': get(a:repo, 'hasphases', 0),
                 \'indegree': indegree, 'incremented': {cs.hex : 1},
                 \'next': s:F.ancestorsnext}
 endfunction

File doc/aurum.txt

          |aurum-repo.mutable|.
     4.1: Added csnum key to value returned by |aurum-repo.iterfuncs|.func().
     5.0: Removed _r.repo.update, .diffoptslst and .diffoptsstr.
+    5.1: Added repo.hasphases
 @aurum:
     0.1: Added |:AuBranch| and |:AuName|.
     0.2: Added |:AuOther|.

File misc/map-cmdline.csinfo

-changeset = ':\n{rev}\n{node}\n{branch|json}\n{date}\n{author|json}\n{parents}{tags}{bookmarks}{files}{file_dels}{file_copies}\t{desc|json}\n'
+changeset = ':\n{rev}\n{node}\n{phase}\n{branch|json}\n{date}\n{author|json}\n{parents}{tags}{bookmarks}{files}{file_dels}{file_copies}\t{desc|json}\n'
 parent    = 'P{node|json}\n'
 tag       = 'T{tag|json}\n'
 bookmark  = 'B{bookmark|json}\n'

File python/aurum.py

                'startrev': startrev,
                    'tags': tags_vim,
               'bookmarks': bookmarks_vim,})
+    if hasattr(tipcs, 'phase'):
+        vim_extend(val={'phases': [repo[rev].phasestr() for rev in range(startrev)]})
 
 def get_cs_tag_dict(l):
     r={}
     vim_extend(val={'tags': tags, 'bookmarks': bookmarks})
 
 @outermethod
+def get_phases(repo):
+    vim_extend(val={'phasemap': dict((lambda cs: (cs.hex(), cs.phasestr()))(repo[rev]) for rev in repo)})
+
+@outermethod
 def get_cs(repo, rev):
     cs=g_cs(repo, rev)
     vim_extend(var='cs', val=set_rev_dict(cs, {'rev': cs.rev()}))
                          'mutable': {'cslist': []},
                            'local': 1 if repo.local() else 0,
                       'labeltypes': ['tag', 'bookmark'],
+                       'hasphases': int(hasattr(repo[None], 'phase')),
              }
     if hasattr(repo, '__len__'):
         vim_repo['csnum']=len(repo)+1
         r=[f for f in cs]
     elif prop=='children':
         r=[ccs.hex() for ccs in cs.children()]
+    elif prop=='phase':
+        if hasattr(cs, 'phasestr'):
+            r=cs.phasestr()
+        else:
+            r='unknown'
     else:
         r=cs.__getattribute__(prop)()
     # XXX There is much code relying on the fact that after getcsprop