ZyX_I avatar ZyX_I committed 0ec9b79

Added partially working :AuGlog command

Comments (0)

Files changed (4)

+syntax: glob
+python/*.pyc
+*aurum.txt* Plugin for dealing with source files under mercurial control
+==============================================================================
+CONTENTS                                                      *aurum-contents*
+    1. Intro                                             *aurum-intro*
+    2. Functionality provided                            *aurum-functionality*
+        2.1. Commands                                    *aurum-commands*
+        2.2. Functions                                   *aurum-functions*
+        2.3. Variables                                   *aurum-variables*
+    3. Options                                           *aurum-options*
+
+==============================================================================
+1. Intro                                                         *aurum-intro*
+
+Plugin requires some additional plugins:
+  — vimpluginloader
+(with their dependencies).
+==============================================================================
+2. Functionality provided                                *aurum-functionality*
+
+
+------------------------------------------------------------------------------
+2.1. Commands                                                 *aurum-commands*
+
+
+------------------------------------------------------------------------------
+2.2. Functions                                               *aurum-functions*
+
+
+------------------------------------------------------------------------------
+2.3. Variables                                               *aurum-variables*
+
+
+==============================================================================
+3. Options                                                     *aurum-options*
+
+
+
+vim: ft=help:tw=78
+"▶1 Начало
+scriptencoding utf-8
+if (exists("s:g._pluginloaded") && s:g._pluginloaded) ||
+            \exists("g:aurumOptions.DoNotLoad")
+    finish
+"▶1 Первая загрузка
+elseif !exists("s:g._pluginloaded")
+    "▶2 Объявление переменных
+    execute load#Setup('0.0', "au", "Au", "Au")
+    call map(['hg', 'comm', 'graph', 'glog'], 'extend(s:F, {v:val : {}})')
+    lockvar 1 s:F
+    "▶2 Функции
+    let s:g._load.functions=[
+                \['getrepo', 'hg.repo', {}],
+            \]
+    " "▶2 Словарные функции
+    " let s:g._load.dictfunctions=[
+    "             \[%-VISIBLE_NAME-%, %-INNER_FUNCTION-%, %-CHECK_MODEL-%],
+    "         \]
+    "▶2 Команды
+    let s:g._load.commands={
+                \'Glog': {
+                \        "func": 'comm.glog',
+                \       "nargs": '?',
+                \},
+            \}
+    " "▶2 Привязки
+    " let s:g._load.mappings={
+    "             \%-MAP_NAME-%: {
+    "             \   'function': %-INNER_FUNCTION-%,
+    "             \    'default': %-DEFAULT_KEYS-%,
+    "             \       'type': %-MAP_MODE-%,
+    "             \},
+    "         \}
+    "▶2 Регистрация дополнения
+    let s:g._load.requires=[["load", '0.0'],
+                \           ["stuf", '0.5']]
+    let s:g._load.preload=[["os", "autoload"]]
+    let s:g._load.reginfo=s:F.plug.load.registerplugin(s:g._load)
+    call extend(s:F.main, s:g._load.reginfo.functions)
+    finish
+endif
+"▶1 Вторая загрузка
+let s:g._pluginloaded=1
+unlet s:g._load
+let s:g.repos={}
+"▶2 Настройки
+let s:g.defaultOptions={
+            \"PythonVersion":    2,
+        \}
+let s:g.c={}
+let s:g.c.options={
+            \"PythonVersion":    ["in", [2, 3]],
+        \}
+"▶2 Выводимые сообщения
+let s:g.p={
+            \"emsg": {
+            \   'nopython': 'Unable to load python interface',
+            \    'nopycmd': 'Python command does not exist for some reason',
+            \},
+            \"etype": {
+            \     'notimp': 'NotImplemented',
+            \        'int': 'InternalError',
+            \}
+        \}
+"▶1 Вторая загрузка — функции
+" "▶2 Внешние дополнения
+" let s:F.plug.%-PLUGNAME-%=s:F.plug.load.getfunctions("%-PLUGNAME-%")
+"▶2 main: eerror, destruct, option
+function s:F.main.destruct()
+    unlet s:g s:F
+    return 1
+endfunction
+"▶2 hg
+"▶3 hg.pycmd
+let s:g.py={}
+let s:g.py.version=s:F.main.option("PythonVersion")
+let s:g.py.features=['python', 'python3']
+call insert(s:g.py.features, remove(s:g.py.features, s:g.py.version-2))
+for s:g.py.feature in s:g.py.features
+    if has(s:g.py.feature) || has(s:g.py.feature.'/dyn')
+        let s:g.py.cmd=s:g.py.feature[:1].s:g.py.feature[6:]
+        try
+            if !exists(':'.s:g.py.cmd)
+                call s:F.main.eerror('', 'int', 1, ['nopycmd'])
+            endif
+            execute s:g.py.cmd 'import vim'
+            lockvar! s:g.py.cmd
+            break
+        catch
+            unlet s:g.py.cmd
+        endtry
+    endif
+endfor
+unlet s:g.py.features
+if !has_key(s:g.py, 'cmd')
+    call s:F.main.eerror('', 'notimp', 1, ['nopython'])
+endif
+
+let s:g.py.importdir=os#JoinPath(expand('<sfile>:p:h:h'), 'python')
+execute s:g.py.cmd "import sys, vim"
+execute s:g.py.cmd "sys.path.append(vim.eval('s:g.py.importdir'))"
+execute s:g.py.cmd "import aurum"
+"▶3 hg.repo
+function s:F.hg.repo(path)
+    if has_key(s:g.repos, a:path)
+        return s:g.repos[a:path]
+    endif
+    let repo={}
+    let s:g.repos[a:path]=repo
+    execute s:g.py.cmd "aurum.new_repo(vim.eval('a:path'))"
+    for cs in values(repo.changesets)
+        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]
+    return repo
+endfunction
+"▶2 graph
+"▶3 graph.inscol
+function s:F.graph.inscol(graph, col)
+    let col=a:col
+    let llen=len(a:graph.grid[0])
+    if col<0
+        let col=llen+col+1
+    endif
+    call map(a:graph.grid, 'insert(v:val, 0, '.col.')')
+    if col==llen || col==0
+        call map(a:graph.connections, 'insert(v:val, "0000", '.col.')')
+    else
+        " up, down, left, right
+        call map(a:graph.connections,
+                    \'insert(v:val, '.
+                    \  '"00".v:val['.(col-1).'][2].v:val['.col.'][3], '.col.')')
+    endif
+    return a:graph
+endfunction
+"▶3 graph.insline
+function s:F.graph.insline(graph, line)
+    let line=a:line
+    let clen=len(a:graph.grid)
+    if line<0
+        let line=clen+line+1
+    endif
+    call insert(a:graph.grid, repeat([0], clen), line)
+    if line==0
+        call insert(a:graph.connections, repeat(["0000"], clen))
+    elseif line==clen
+        call insert(a:graph.connections, repeat(["0000"], clen), clen-1)
+    else
+        call insert(a:graph.connections, repeat(["0000"], clen), line)
+        let [prevcon, inscon]=a:graph.connections[(line-1):(line)]
+        let insline=a:graph.lines[line]
+        let llen=len(a:graph.grid[0])
+        let i=0
+        while i<llen
+            let element=repeat(prevcon[i][0], 2)."00"
+            let inscon[i]=element
+            let insline[i]=element
+            let i+=1
+        endwhile
+    endif
+endfunction
+"▶3 graph.connect
+function s:F.graph.connect(graph, pos)
+endfunction
+"▶2 glog
+"▶3 glog.utfedges
+function s:F.glog.utfedges(seen, hex, parents_hex)
+    let nodeidx=index(a:seen, a:hex)
+    if nodeidx==-1
+        let nodeidx=len(a:seen)
+        call add(a:seen, a:hex)
+    endif
+    let knownparents=[]
+    let newparents=[]
+    for parent_hex in a:parents_hex
+        call add(((index(a:seen, parent_hex)==-1)?
+                    \   (newparents):
+                    \   (knownparents)),
+                    \parent_hex)
+    endfor
+    let ncols=len(a:seen)
+    call remove(a:seen, nodeidx)
+    call extend(a:seen, newparents, nodeidx)
+    let edges=map(knownparents, '['.nodeidx.', index(a:seen, v:val)]')
+    if !empty(newparents)
+        call add(edges, [nodeidx, nodeidx])
+        if len(newparents)>1
+            call add(edges, [nodeidx, nodeidx+1])
+        endif
+    endif
+    let nmorecols=len(a:seen)-ncols
+    return [nodeidx, edges, ncols, nmorecols]
+endfunction
+"▶3 glog.fix_long_right_edges
+function s:F.glog.fix_long_right_edges(edges)
+    call map(a:edges, '((v:val[1]>v:val[0])?([v:val[0], v:val[1]+1]):(v:val))')
+endfunction
+"▶3 glog.get_nodeline_edges_tail
+function s:F.glog.get_nodeline_edges_tail(node_index, p_node_index, n_columns,
+            \                             n_columns_diff, p_diff, fix_tail)
+    if a:fix_tail && a:n_columns_diff==a:p_diff && a:n_columns_diff!=0
+        if a:n_columns_diff==-1
+            let start=max([a:node_index+1, a:p_node_index])
+            let tail=repeat(["|", " "], (start-a:node_index-1))+
+                        \repeat(["/", " "], (a:n_columns-start))
+            return tail
+        else
+            return repeat(['\', ' '], (a:n_columns-a:node_index-1))
+        endif
+    else
+        return repeat(["|", " "], (a:n_columns-a:node_index-1))
+    endif
+endfunction
+"▶3 glog.draw_edges
+function s:F.glog.draw_edges(edges, nodeline, interline)
+    for [start, end] in a:edges
+        if start==end+1
+            let a:interline[2*end   + 1]='/'
+        elseif start==end-1
+            let a:interline[2*start + 1]='\'
+        elseif start==end
+            let a:interline[2*start    ]='|'
+        else
+            let a:nodeline[2*end]='+'
+            if start>end
+                let [start, end]=[end, start]
+            endif
+            for i in range(2*start + 1, 2*end)
+                if a:nodeline[i]!=#'+'
+                    let a:nodeline[i]='-'
+                endif
+            endfor
+        endif
+    endfor
+endfunction
+"▶3 glog.get_padding_line
+function s:F.glog.get_padding_line(ni, n_columns, edges)
+    let c=" "
+    if index(a:edges, [a:ni, a:ni-1])!=-1 || index(a:edges, [a:ni, a:ni])!=-1
+        let c="|"
+    endif
+    let line=repeat(["|", " "], a:ni)+
+                \[c, " "]+
+                \repeat(["|", " "], (a:n_columns-a:ni-1))
+    return line
+endfunction
+"▶3 glog.utf
+function s:F.glog.utf(state, type, char, text, coldata)
+    let [idx, edges, ncols, coldiff]=a:coldata
+    let add_padding_line=[]
+    let lnum=len(a:text.text)
+    if coldiff==-1
+        call s:F.glog.fix_long_right_edges(edges)
+        if lnum>2
+            let add_padding_line=map(filter(copy(edges),
+                        \                   '(v:val[0]+1)<v:val[1]'),
+                        \            'v:val[0]')
+        endif
+    endif
+    let fix_nodeline_tail = (lnum<=2 && empty(add_padding_line))
+    let shift_interline=repeat(["|", " "], idx)
+    let nodeline=copy(shift_interline)+
+                \[a:char, " "]+
+                \s:F.glog.get_nodeline_edges_tail(idx,     a:state[1], ncols,
+                \                                 coldiff, a:state[0],
+                \                                 fix_nodeline_tail)
+    if coldiff==-1
+        let n_spaces=1
+        let edge_ch='/'
+    elseif coldiff==0
+        let n_spaces=2
+        let edge_ch='|'
+    else
+        let n_spaces=3
+        let edge_ch='\'
+    endif
+    let shift_interline+=repeat([" "], n_spaces)+
+                \        repeat([edge_ch, " "], (ncols-idx-1))
+    call s:F.glog.draw_edges(edges, nodeline, shift_interline)
+    let lines=[nodeline]
+    if !empty(add_padding_line)
+        call add(lines, s:F.glog.get_padding_line(idx, ncols, edges))
+    endif
+    call add(lines, shift_interline)
+    let ltdiff=lnum-len(lines)
+    if ltdiff>0
+        let extra_interline=repeat(["|", " "], ncols+coldiff)
+        call extend(lines, repeat([extra_interline], ltdiff))
+    else
+        call extend(a:text.text, repeat([""], -ltdiff))
+    endif
+    let indentation_level=2*max([ncols, ncols+coldiff])
+    let a:state[0]=coldiff
+    let a:state[1]=idx
+    call map(lines, 'printf("%-*s ", indentation_level, join(v:val, ""))')
+    let curspecial=values(a:text.specials)[0]
+    let shiftlen=len(lines[0])
+    call s:F.comm.addcols(a:text, shiftlen)
+    let curspecial.blockstart=[0, shiftlen]
+    let curspecial.blockend  =[len(a:text.text)-1,
+                \              max(map(copy(lines), 'len(v:val)'))]
+    let curspecial.bullet=[0, stridx(lines[0], a:char), a:char]
+    call map(a:text.text, 'lines[v:key].v:val')
+    return a:text
+endfunction
+"▶3 glog.summary
+function s:F.glog.summary(cs)
+    return      {'text': [a:cs.rev.':'.a:cs.hex],
+                \'specials': {a:cs.hex: {}}}
+endfunction
+"▶3 glog.generate
+function s:F.glog.generate(css, showparents, Dumper)
+    let seen=[]
+    let state=[0, 0]
+    let r=      {'text': [],
+                \'specials': {}}
+    for cs in a:css
+        let char=((has_key(a:showparents, cs.hex))?('@'):('o'))
+        let text=call(a:Dumper, [cs], {})
+        call s:F.glog.utf(state, 'C', char, text,
+                    \     s:F.glog.utfedges(seen, cs.hex, cs.parents_hex))
+        call s:F.comm.addlines(text, len(r.text))
+        let r.text+=text.text
+        call extend(r.specials, text.specials)
+    endfor
+    return r
+endfunction
+"▶3 glog.graphlog
+function s:F.glog.graphlog(repo)
+    let css=reverse(a:repo.cslist[:-2])
+    return s:F.glog.generate(css, {a:repo.work_hex: '1'}, s:F.glog.summary)
+endfunction
+"▶2 comm
+"▶3 comm.addlines
+function s:F.comm.addlines(text, lnum)
+    let mapexpr='[v:val[0]+'.a:lnum.']+v:val[1:]'
+    call map(a:text.specials, 'v:key[-1:]==#"s"?'.
+                \                   'map(v:val, '.string(mapexpr).'):'.
+                \                   mapexpr)
+    return a:text
+endfunction
+"▶3 comm.addcols
+function s:F.comm.addcols(text, cnum)
+    let mapexpr='[v:val[0], v:val[1]+'.a:cnum.']+v:val[2:]'
+    call map(a:text.specials, 'v:key[-1:]==#"s"?'.
+                \                   'map(v:val, '.string(mapexpr).'):'.
+                \                   mapexpr)
+    return a:text
+endfunction
+"▶3 comm.hasrepo
+function s:F.comm.hasrepo(path)
+    return isdirectory(os#JoinPath(a:path, '.hg'))
+endfunction
+"▶3 comm.repopath
+function s:F.comm.repopath(...)
+    let r='.'
+    if a:0
+        let r=a:1
+        if stridx(r, '://')!=-1
+            return r
+        endif
+    endif
+    let r=fnamemodify(r, ':p')
+    let olddir=''
+    while r!=#olddir && !s:F.comm.hasrepo(r)
+        let olddir=r
+        let r=fnamemodify(r, ':h')
+    endwhile
+    return r
+endfunction
+"▶3 comm.getrepo
+function s:F.comm.getrepo(path)
+    return s:F.hg.repo(a:path)
+endfunction
+"▶3 comm.glog
+function s:F.comm.glog(...)
+    let repopath=call(s:F.comm.repopath, a:000, {})
+    let repo=s:F.comm.getrepo(repopath)
+    let text=s:F.glog.graphlog(repo)
+    new
+    setlocal filetype=aurum buftype=nofile
+    call setline(1, text.text)
+endfunction
+"▶2
+lockvar! s:F s:g
+unlockvar s:g.repos
+" vim: ft=vim ts=4 sts=4 et fmr=▶,▲
+
+from mercurial import hg, ui
+import vim
+
+ui=ui.ui()
+repositories={}
+
+def vim_escape(string):
+    # XXX works only in eval: NLs!
+    return "'"+str(string).replace("'", "''")+"'"
+
+def get_repo(path):
+    if(path not in repositories):
+        repositories[path]=hg.repository(ui, path)
+    return repositories[path]
+
+def new_repo(path):
+    repo=get_repo(path)
+    cscount=repo['tip'].rev()+1
+    vim.command('let repo.cscount='+str(cscount))
+    vim.command('let repo.changesets={}')
+    vim.command('let repo.cslist=[]')
+    vim.command('let repo.work_hex="'+repo['.'].hex()+'"')
+    curcsnum=0
+    while curcsnum<=cscount:
+        cs=repo[curcsnum]
+        vim.command('let cs={}')
+        vim.command('let cs.rev='+str(curcsnum))
+        vim.command('let cs.hex="'+cs.hex()+'"')
+        vim.command('let repo.changesets[cs.hex]=cs')
+        vim.eval('add(repo.cslist, cs)')
+        vim.command('let cs.parents_hex=[]')
+        for parent in cs.parents():
+            vim.eval('add(cs.parents_hex, "'+parent.hex()+'")')
+        vim.command('let cs.children_hex=[]')
+        for child in cs.children():
+            vim.eval('add(cs.children_hex, "'+child.hex()+'")')
+        vim.command('let cs.files=[]')
+        for file in cs:
+            vim.eval('add(cs.files, '+vim_escape(file)+')')
+        curcsnum+=1
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.