Commits

ZyX_I  committed e7319fd

@aurum/drivers/mercurial: Added tags and bookmarks updating when repo.mutable.cslist is empty
Made rf-getcs() now not recreate changeset in this case

  • Participants
  • Parent commits 18ff4dd

Comments (0)

Files changed (2)

File plugin/aurum/drivers/mercurial.vim

         execute s:_r.py.cmd 'reload(aurum)'
     endif
 endif
+let s:nullrev=repeat('0', 40)
+"▶1 Messages
 let s:_messages={
             \ 'norepo': 'Repository %s not found',
             \ 'norev' : 'No revision %s in repository %s',
             \ 'destex': 'Cannot copy %s to %s: destination already exists',
             \ 'nhgiwr': 'File %s is either a directory or not writeable',
             \'reponwr': 'Unable to write to repository root (%s)',
-            \  'nocfg': 'Failed to get property %s of repository %s',
+            \  'nocfg': 'No such property of repository %s: %s',
+            \'failcfg': 'Failed to get property %s of repository %s',
             \'nlocbms': 'Bookmarks can’t be local',
             \'parsefail': 'Failed to parse changeset information',
             \ 'filefail': 'Failed to get file %s '.
             \ 'nogitrev': 'No git revision associated with revision %s '.
             \             'in repository %s',
         \}
-let s:nullrev=repeat('0', 40)
+"▶1 Options
 let s:_options={
-            \'hg_useshell': {'default': [],
-            \                 'filter':
-            \                   '(if type "" (|=split(@.@,''\L\+'')) any '.
-            \                    'list match /\v^\l+$/)'},
+            \'hg_useshell':  {'default': [],
+            \                  'filter':
+            \                    '(if type "" (|=split(@.@,''\L\+'')) any '.
+            \                     'list match /\v^\l+$/)'},
         \}
+            " \'hg_itercsnum': {'default': ((s:usepythondriver)?(0):(1000)),
+            " \                 'checker': 'range 0 inf'},
 "▶1 s:hypsites
 let s:hypsites=[]
 let s:bookmarks='repo.functions.getcsprop(repo, hex, "bookmarks")'
 endif
 "▶1 hg.getcs :: repo, rev → cs
 function s:hg.getcs(repo, rev)
-    if !empty(a:repo.mutable.cslist)
-        if type(a:rev)==type('') && has_key(a:repo.changesets, a:rev)
-            return a:repo.changesets[a:rev]
-        elseif type(a:rev)==type(0) && a:rev<a:repo.csnum
+    if type(a:rev)==type('') && has_key(a:repo.changesets, a:rev)
+        return a:repo.changesets[a:rev]
+    elseif type(a:rev)==type(0)
+        if !empty(a:repo.mutable.cslist) && a:rev<a:repo.csnum
             return a:repo.mutable.cslist[a:rev]
         endif
     endif
         let hex=a:rev
     else
         let hex=a:repo.functions.getrevhex(a:repo, a:rev)
+        if has_key(a:repo.changesets,hex)
+            return a:repo.changesets[hex]
+        endif
     endif
-    if has_key(a:repo.changesets, hex) && !empty(a:repo.mutable.cslist)
-        return a:repo.changesets[hex]
-    else
-        let cs=s:F.getcs(a:repo, hex)
-        let a:repo.changesets[cs.hex]=cs
-        return cs
-    endif
+    let cs=s:F.getcs(a:repo, hex)
+    let a:repo.changesets[cs.hex]=cs
+    return cs
 endfunction
 "▶1 hg.getwork :: repo → hex
 function s:hg.getwork(repo)
     return cslist[(rev1):(rev2)]
 endfunction
 "▶1 hg.updatechangesets :: repo → + repo
+"▶2 updatewithtagsdict
+function s:F.updatewithtagsdict(csmap, d)
+    for key in ['tags', 'bookmarks']
+        if has_key(a:d, key) && !empty(a:d[key])
+            let cd=a:d[key]
+            let expr='get(cd, v:key, [])'
+        else
+            let expr='[]'
+        endif
+        call map(copy(a:csmap), 'extend(v:val, {"'.key.'": '.expr.'})')
+    endfor
+endfunction
 "▶2 python
 if s:usepythondriver
     function s:F.getupdates(repo, start)
         endtry
         return d
     endfunction
-    "▶2 no python
+    function s:F.updatetags(repo)
+        if empty(a:repo.changesets)
+            return
+        endif
+        let d={}
+        try
+            execute s:_r.py.cmd 'aurum.get_tags(vim.eval("a:repo.path"))'
+        endtry
+        call s:F.updatewithtagsdict(a:repo.changesets, d)
+    endfunction
+"▶2 no python
 else
     function s:F.getupdates(repo, start)
         let r={}
         let a:repo.csnum=a:start+len(r.css)
         return r
     endfunction
+    function s:F.updatetags(repo)
+        if empty(a:repo.changesets)
+            return
+        endif
+        let revmap={}
+        call map(copy(a:repo.changesets), 'extend(revmap, {v:val.rev : v:val})')
+        let d={}
+        for key in ['tags', 'bookmarks']
+            try
+                let list=s:F.getkeylist(a:repo, key)
+            catch
+                continue
+            endtry
+            let d[key]={}
+            let cd=d[key]
+            call map(copy(list), 'has_key(cd, v:val[1])?'.
+                        \           'add(cd[v:val[1]], v:val[0]):'.
+                        \           'extend(cd, {v:val[1] : [v:val[0]]})')
+            call map(values(cd), 'sort(v:val)')
+        endfor
+        call s:F.updatewithtagsdict(revmap, d)
+    endfunction
 endif
 "▶2 hg.updatechangesets
 " TODO test updating in cases of rollback
 function s:hg.updatechangesets(repo, ...)
     if !(a:0 && a:1) && empty(a:repo.mutable.cslist)
-        return
+        return s:F.updatetags(a:repo)
     endif
     let d={}
     let start=len(a:repo.mutable.cslist)-2
         execute s:_r.py.cmd 'aurum.get_repo_prop(vim.eval("a:repo.path"), '.
                     \                           'vim.eval("a:prop"))'
     endtry
-    return a:repo[a:prop]
+    return d[a:prop]
 endfunction
 else "▶2
 function s:hg.getrepoprop(repo, prop)
         elseif has_key(confs, 'default')
             return confs.default
         endif
+    else
+        call s:_f.throw('nocfg', a:repo.path, a:prop)
     endif
-    call s:_f.throw('nocfg', a:prop, a:repo.path)
+    call s:_f.throw('failcfg', a:prop, a:repo.path)
 endfunction
 endif
 "▶1 pushpull :: cmd, repo, force[, URL[, rev]] → + ?

File python/aurum.py

     vim.eval('extend(a:repo, {"csnum": '+str(len(repo)+1)+'})')
     vim.eval('extend(d, '+utf_dumps(d_vim)+')')
 
+def get_cs_tag_dict(l):
+    r={}
+    for hex, tag in l:
+        if hex in r:
+            r[hex].append(tag)
+        else:
+            r[hex]=[tag]
+    for key in r:
+        r[key].sort()
+    return r
+
+@outermethod
+def get_tags(repo):
+    tags=get_cs_tag_dict([(repo[val].hex(), key) for key, val
+                          in repo.tags().items()])
+    bookmarks={}
+    if hasattr(repo, 'listkeys'):
+        bookmarks=get_cs_tag_dict([(val, key) for key, val
+                                   in repo.listkeys('bookmarks').items()])
+    return vim.eval('extend(d, '+utf_dumps({'tags': tags,
+                                       'bookmarks': bookmarks})+')')
+
 @outermethod
 def get_cs(repo, rev):
     cs=g_cs(repo, rev)
     if dirty and filepath in dirty:
         vim.command('let r=1')
 
+repo_props={
+            'tagslist': lambda repo: repo.tags().keys(),
+        'brancheslist': lambda repo: repo.branchmap().keys(),
+       'bookmarkslist': lambda repo: repo.listkeys('bookmarks').keys()
+                                        if hasattr(repo, 'listkeys') else [],
+                 'url': lambda repo: repo.ui.config('paths', 'default-push') or
+                                     repo.ui.config('paths', 'default'),
+        }
 @outermethod
 def get_repo_prop(repo, prop):
-    r=None
-    if prop=='tagslist':
-        r=repo.tags().keys()
-    elif prop=='brancheslist':
-        r=repo.branchmap().keys()
-    elif prop=='bookmarkslist':
-        if hasattr(repo, 'listkeys'):
-            r=repo.listkeys('bookmarks').keys()
+    if prop in repo_props:
+        r=repo_props[prop](repo)
+        if r is None:
+            vim_throw('failcfg', prop, repo.path)
         else:
-            r=[]
-    elif prop=='url':
-        r=repo.ui.config('paths', 'default-push')
-        if r is None:
-            r=repo.ui.config('paths', 'default')
-    if r is None:
-        vim_throw('nocfg', prop, repo.path)
+            vim.eval('extend(d, {"'+prop+'": '+utf_dumps(r)+'})')
     else:
-        vim.eval('extend(a:repo, {"'+prop+'": '+utf_dumps(r)+'})')
+        vim_throw('nocfg', repo.path, prop)
 
 @outermethod
 def call_cmd(repo, attr, *args, **kwargs):