Commits

ZyX_I committed c38f3bb

Started working on aurum://annotate, added hg.update

Comments (0)

Files changed (3)

ftplugin/aurumannotate.vim

+"▶1 
+scriptencoding utf-8
+execute frawor#Setup('0.0', {'@aurum': '0.0',
+            \            '@/mappings': '0.0',
+            \        '@/autocommands': '0.0',})
+"▶1 setup
+function s:F.setup()
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let ann=bvar.repo.functions.annotate(bvar.repo, bvar.rev, bvar.file)
+    echom string(ann)
+endfunction
+let s:filetype=expand('<sfile>:t:r')
+call s:_f.augroup.add('AuAnnotate', [['FileType', s:filetype, 0, s:F.setup]])
+call s:F.setup()
     "▶2 Команды
     call FraworLoad('@/commands')
     call FraworLoad('@/functions')
-    call FraworLoad('@/autocommands')
     let s:glogfunc={}
     call s:_f.command.add('AuGlog', s:glogfunc, {'nargs': '?'})
+    let s:annfunc={}
+    call s:_f.command.add('AuAnnotate', s:annfunc, {'nargs': '*'})
     "▶2 Autocommands
+    call FraworLoad('@/autocommands')
     let s:auefunc={}
     let s:auhidefunc={}
     let s:aubwfunc={}
 "▶1 Вторая загрузка — функции
 "▶2 hg
 execute s:_r.py.cmd 'import aurum'
+"▶3 hg.addchangesets :: repo, [cs] → _ + repo
+function s:F.hg.addchangesets(repo, css)
+    call map(copy(a:css), 'extend(a:repo.changesets, {v:val.hex : v:val})')
+    for cs in a:css
+        call map(cs.parents, 'a:repo.changesets[v:val]')
+        for parent in cs.parents
+            call add(a:repo.changesets[parent.hex].children, parent)
+        endfor
+    endfor
+endfunction
+"▶3 hg.update
+function s:F.hg.update(repo)
+    execute s:_r.py.cmd 'aurum.get_updates(vim.eval("a:repo.path"), '.
+                \                         'vim.eval("a:repo.tip_hex"))'
+    call remove(a:repo.cslist, -1)
+    let a:repo.cslist+=css
+    call a:repo.functions.addchangesets(a:repo, css)
+    let a:repo.work_hex=work_hex
+    let a:repo.tip_hex=tip_hex
+    let a:repo.work=a:repo.changesets[a:repo.work_hex]
+    let a:repo.tip=a:repo.changesets[a:repo.tip_hex]
+    return a:repo
+endfunction
 "▶3 hg.repo
 function s:F.hg.repo(path)
     if has_key(s:repos, a:path)
-        return s:repos[a:path]
+        let repo=s:repos[a:path]
+        return repo.functions.update(repo)
     endif
-    let repo={'path': a:path}
+    let repo={'functions': s:F.hg}
+    execute s:_r.py.cmd 'aurum.new_repo(vim.eval("a:path"))'
+    call repo.functions.addchangesets(repo, repo.cslist)
+    let repo.work=repo.changesets[repo.work_hex]
+    let repo.tip=repo.changesets[repo.tip_hex]
+    let repo.type='hg'
     let s:repos[a:path]=repo
-    execute s:_r.py.cmd 'aurum.new_repo(vim.eval("a:path"))'
-    call map(copy(repo.cslist), 'extend(repo.changesets, {v:val.hex : v:val})')
-    for cs in repo.cslist
-        let cs.parents=map(copy(cs.parents_hex), 'repo.changesets[v:val]')
-        let cs.children=map(copy(cs.children_hex), 'repo.changesets[v:val]')
-    endfor
-    let repo.work=repo.changesets[repo.work_hex]
-    let repo.type='hg'
-    let repo.functions=s:F.hg
     return repo
 endfunction
 "▶3 hg.getrevhex :: rev, repo → rev(hex)
                 \                      'vim.eval("a:file"))'
     return r
 endfunction
+"▶3 hg.annotate :: repo, rev, file → [cs]
+function s:F.hg.annotate(repo, rev, file)
+    execute s:_r.py.cmd 'aurum.annotate(vim.eval("a:repo.path"), '.
+                \                      'vim.eval("a:rev"), '.
+                \                      'vim.eval("a:file"))'
+    return r
+endfunction
 "▶2 comm
 "▶3 comm.hasrepo
 function s:F.comm.hasrepo(path)
 endfunction
 "▶3 auefunc
 let s:bufvars={}
+"▶4 comm.reporevfilesplit :: str → (repo, rev, file)
+function s:F.comm.reporevfilesplit(str)
+    let file=a:str
+    let repopath=matchstr(file, '\v^(\\.|[^\\:]+)')
+    let file=file[len(repopath)+1:]
+    let repo=s:F.comm.getrepo(substitute(repopath,'\v\\([\\:])','\1','g'))
+    let rev=matchstr(file, '\v^(\\.|[^\\:])+')
+    let file=file[len(rev)+1:]
+    let rev=substitute(rev, '\v\\([\\:])', '\1', 'g')
+    return [repo, rev, file]
+endfunction
+"▲4
 function s:auefunc.function()
     let file=substitute(expand('<amatch>'), '\V\^aurum://', '', '')
     let command=matchstr(file, '\v^\w+')
         let s:bufvars[bufnr('%')]={'repo': repo}
         setlocal filetype=aurumgraphlog buftype=nofile
     elseif command is# 'file'
-        let repopath=matchstr(file, '\v^(\\.|[^\\:]+)')
-        let file=file[len(repopath)+1:]
-        let repo=s:F.comm.getrepo(substitute(repopath,'\v\\([\\:])','\1','g'))
-        let rev=matchstr(file, '\v^(\\.|[^\\:])+')
-        let file=file[len(rev)+1:]
-        let rev=substitute(rev, '\v\\([\\:])', '\1', 'g')
+        let [repo, rev, file]=s:F.comm.reporevfilesplit(file)
         setlocal buftype=nofile
         call setline('.', repo.functions.readfile(repo, rev, file))
+    elseif command is# 'annotate'
+        let [repo, rev, file]=s:F.comm.reporevfilesplit(file)
+        let s:bufvars[bufnr('%')]={'repo': repo, 'rev': rev, 'file': file}
+        setlocal filetype=aurumannotate buftype=nofile
     endif
 endfunction
 "▶3 auhidefunc
     let buf=+expand('<abuf>')
     unlet s:bufvars[buf]
 endfunction
+"▶3 annfunc
+function s:annfunc.function(...)
+    let repo=s:F.comm.getrepo(get(a:000, 0, 1))
+endfunction
 "▶3 Post aurum resource
 call s:_f.postresource('aurum', {'bufvars': s:bufvars}, 1)
 "▶1
         repositories[path]=hg.repository(ui, path)
     return repositories[path]
 
+def set_rev_dict(cs, cs_vim):
+    cs_vim['hex']=cs.hex()
+    cs_vim['time']=int(cs.date()[0])
+    cs_vim['description']=cs.description()
+    cs_vim['user']=cs.user()
+    try:
+        branch=cs.branch()
+        cs_vim['branch']=branch
+        cs_vim['tags']=cs.tags()
+        cs_vim['bookmarks']=cs.bookmarks()
+    except AttributeError:
+        pass
+    for parent in cs.parents():
+        cs_vim['parents'].append(parent.hex())
+    for file in cs.files():
+        cs_vim['files'].append(file)
+
+def get_updates(path, oldtip):
+    repo=get_repo(path)
+    cs=repo[oldtip]
+    tipcs=repo['tip']
+    if tipcs is cs:
+        return
+    curcsnum=cs.rev()
+    cscount=tipcs.rev()+1
+    css_vim=[]
+    while curcsnum<=cscount:
+        cs_vim={'rev': curcsnum,
+            'parents': [],
+           'children': [],
+              'files': [],}
+        set_rev_dict(repo[curcsnum], cs_vim)
+        css_vim.append(cs_vim)
+        curcsnum+=1
+    vim.eval('extend(l:, {"css": '+json.dumps(css_vim)+', '+
+                         '"tip_hex": "'+tipcs.hex()+'", '+
+                         '"work_hex": "'+repo['.'].hex()+'"})')
+
 def new_repo(path):
     repo=get_repo(path)
     repo_vim={}
     cscount=repo['tip'].rev()+1
+    repo_vim['path']=path
     repo_vim['cscount']=cscount
     repo_vim['changesets']={}
     repo_vim['cslist']=[{'rev': i,
-                 'parents_hex': [],
-                'children_hex': [],
+                     'parents': [],
+                    'children': [],
                        'files': [],} for i in range(0, cscount+1)]
     repo_vim['work_hex']=repo['.'].hex()
+    repo_vim['tip_hex']=repo['tip'].hex()
     curcsnum=0
     while curcsnum<=cscount:
-        cs=repo[curcsnum]
-        cs_vim=repo_vim['cslist'][curcsnum]
-        cs_vim['hex']=cs.hex()
-        cs_vim['time']=int(cs.date()[0])
-        cs_vim['description']=cs.description()
-        cs_vim['user']=cs.user()
-        try:
-            branch=cs.branch()
-            cs_vim['branch']=branch
-            cs_vim['tags']=cs.tags()
-            cs_vim['bookmarks']=cs.bookmarks()
-        except AttributeError:
-            pass
-        for parent in cs.parents():
-            cs_vim['parents_hex'].append(parent.hex())
-            repo_vim['cslist'][parent.rev()]['children_hex'].append(cs_vim['hex'])
-        for file in cs.files():
-            cs_vim['files'].append(file)
+        set_rev_dict(repo[curcsnum], repo_vim['cslist'][curcsnum])
         curcsnum+=1
     vim.eval('extend(repo, '+json.dumps(repo_vim)+')')
 
 def get_file(path, rev, filepath):
-    repo=get_repo(path)
-    fctx=repo[rev].filectx(filepath)
+    fctx=get_repo(path)[rev].filectx(filepath)
     vim.eval('extend(l:, {"r": '+
             json.dumps(
                 [line.replace("\0", "\n") for line in fctx.data().split("\n")])+
                    '})')
 
+def annotate(path, rev, filepath):
+    ann=get_repo(path)[rev].filectx(filepath).annotate()
+    vim.eval('extend(l:, {"r": ['+
+                             ", ".join(['"'+line[0].hex()+'"' for line in ann])+
+                               ']})')
+