Commits

ZyX_I  committed 771da2c

doc, @aurum/repo: Rearranged repo functions locations

  • Participants
  • Parent commits 73394b3

Comments (0)

Files changed (3)

File doc/aurum.txt

     |aurum-cs.hex|.
   getwork :: () -> cs                                       *aurum-rf-getwork*
     Get changeset object for the working directory revision.
+  getnthparent :: hex, n -> [ cs ]                     *aurum-rf-getnthparent*
+    Get nth generation grand-parent of given revision. Use negative n to get 
+    nth generation child instead.
   getchangesets :: () -> [ cs ]                       *aurum-rf-getchangesets*
     Pull all changesets contained in repository into |aurum-repo.changesets| 
     dictionary. If this function is not called, then |aurum-repo.changesets| 
 Required functions: |aurum-rf-repo|, |aurum-rf-getcs|, |aurum-rf-checkdir|.
 Optional functions:
   Function               Default behavior ~
-  |aurum-rf-dirty|         Use |aurum-rf-status| and check whether file has 
-                         status different from “ignored” or “clean”
   |aurum-rf-getnthparent|  Use |aurum-rf-getcs| and |aurum-rf-getcsprop| 
                          (properties "parents" or "children")
   |aurum-rf-getcsprop|     Checks whether requested key is present in the 
                          changeset object. If yes returns its value, otherwise 
                          calls |aurum-rf-setcsprop|.
-  |aurum-rf-reltorepo|     Uses |aurum-repo.path| to get requested path.
-  |aurum-rf-revrange|      Gets sublist of cslist (uses |aurum-repo.cslist| or 
-                         |aurum-rf-getchangesets| if repo.cslist is empty), 
-                         using values of |aurum-cs.rev| as indexes.
-  |aurum-rf-difftobuffer|  Wrapper around |aurum-rf-diff|.
-  |aurum-rf-diffname|      Uses value of first capturing group of given 
-                         regular expression.
-  |aurum-rf-getstats|      Parses git-like unified diff, depends on 
-                         |aurum-rf-diffre| and |aurum-rf-diffname|.
+  |aurum-rf-dirty|         Use |aurum-rf-status| and check whether file has 
+                         status different from “ignored” or “clean”
+  |aurum-rf-move|          Uses |aurum-rf-copy| and |aurum-rf-remove| to 
+                         emulate renaming command.
   |aurum-rf-copy|          Copies file to destination (using command-line “cp” 
                          (cp -- source target), “copy” (copy source target) or 
                          |readfile()| + |writefile()| (in last case 
                          permissions are not copied)), then uses 
                          |aurum-rf-add| to make destination tracked.
-  |aurum-rf-move|          Uses |aurum-rf-copy| and |aurum-rf-remove| to 
-                         emulate renaming command.
   |aurum-rf-remove|        Uses |aurum-rf-forget| to untrack file and then 
                          |delete()|s it.
-  |aurum-rf-checkremote|   Returns 0.
   |aurum-rf-grep|          Does just the same what git grep does: iterates 
                          over given revisions and searches for given regular 
                          expression (in this case: vim |regexp|) in each file. 
                          argument), |aurum-rf-revrange|, |aurum-rf-getcs| and 
                          |aurum-rf-readfile|.
                          Slow!
+  |aurum-rf-difftobuffer|  Wrapper around |aurum-rf-diff|.
+  |aurum-rf-diffname|      Uses value of first capturing group of given 
+                         regular expression.
+  |aurum-rf-getstats|      Parses git-like unified diff, depends on 
+                         |aurum-rf-diffre| and |aurum-rf-diffname|.
+  |aurum-rf-reltorepo|     Uses |aurum-repo.path| to get requested path.
+  |aurum-rf-checkremote|   Returns 0.
   |aurum-repo.iterfuncs|   "changeset": Uses |aurum-rf-getchangesets|
                          "revrange": Uses |aurum-rf-revrange|
                          "ancestors": Iterates recursively over 

File plugin/aurum/drivers/mercurial.vim

 "▲2
 let s:F.runcmd=s:F.runshellcmd
 endif
+"▶1 getcs :: repo, rev → cs
+if s:usepythondriver "▶2
+function s:F.getcs(repo, rev)
+    let cs={}
+    try
+        execute s:_r.py.cmd 'aurum.get_cs(vim.eval("a:repo.path"), '.
+                    \                    'vim.eval("a:rev"))'
+    endtry
+    return cs
+endfunction
+else "▶2
+function s:F.getcs(repo, rev)
+    let csdata=s:F.hg(a:repo, 'log', [], {'rev': a:rev, 'style': s:stylefile},0,
+                \     'cs', a:rev)
+    let cs=s:F.parsecs(csdata, 0)[0]
+    call map(cs.parents,
+                \'type(v:val)=='.type(0).'? '.
+                \   'a:repo.functions.getrevhex(a:repo, v:val): '.
+                \   'v:val')
+    return cs
+endfunction
+endif
 "▶1 hg.updatechangesets :: repo → + repo
 "▶2 python
 if s:usepythondriver
     endif
     return cslist[(rev1):(rev2)]
 endfunction
-"▶1 getcs :: repo, rev → cs
-if s:usepythondriver "▶2
-function s:F.getcs(repo, rev)
-    let cs={}
-    try
-        execute s:_r.py.cmd 'aurum.get_cs(vim.eval("a:repo.path"), '.
-                    \                    'vim.eval("a:rev"))'
-    endtry
-    return cs
-endfunction
-else "▶2
-function s:F.getcs(repo, rev)
-    let csdata=s:F.hg(a:repo, 'log', [], {'rev': a:rev, 'style': s:stylefile},0,
-                \     'cs', a:rev)
-    let cs=s:F.parsecs(csdata, 0)[0]
-    call map(cs.parents,
-                \'type(v:val)=='.type(0).'? '.
-                \   'a:repo.functions.getrevhex(a:repo, v:val): '.
-                \   'v:val')
-    return cs
-endfunction
-endif
 "▶1 iterfuncs
 "▶2 getfromchangesets
 function s:F.getfromchangesets(repo, hex)

File plugin/aurum/repo.vim

     endtry
     return r
 endfunction
+"▶1 getnthparent :: repo, rev, n → cs
+function s:deffuncs.getnthparent(repo, rev, n)
+    let r=a:repo.functions.getcs(a:repo, a:rev)
+    let key=((a:n>0)?('parents'):('children'))
+    for i in range(1, abs(a:n))
+        let rl=a:repo.functions.getcsprop(a:repo, r, key)
+        if empty(rl)
+            break
+        endif
+        let r=a:repo.functions.getcs(a:repo, rl[0])
+    endfor
+    return r
+endfunction
+"▶1 getcsprop :: repo, Either cs rev, propname → a
+function s:deffuncs.getcsprop(repo, csr, propname)
+    if type(a:csr)==type({})
+        let cs=a:csr
+    else
+        let cs=a:repo.functions.getcs(a:repo, a:csr)
+    endif
+    if has_key(cs, a:propname)
+        return cs[a:propname]
+    endif
+    call a:repo.functions.setcsprop(a:repo, cs, a:propname)
+    " XXX There is much code relying on the fact that after getcsprop property 
+    " with given name is added to changeset dictionary
+    return cs[a:propname]
+endfunction
+"▶1 dirty :: repo, file → Bool
+function s:deffuncs.dirty(repo, file)
+    let status=a:repo.functions.status(a:repo, 0, 0, [a:file])
+    for [type, files] in items(status)
+        if type is# 'ignored' || type is# 'clean'
+            continue
+        endif
+        if index(files, a:file)!=-1
+            return 1
+        endif
+    endfor
+    return 0
+endfunction
+"▶1 move
+function s:deffuncs.move(repo, force, source, target)
+    call a:repo.functions.copy(a:repo, a:force, a:source, a:target)
+    call a:repo.functions.remove(a:repo, a:source)
+endfunction
+"▶1 copy
+function s:deffuncs.copy(repo, force, source, target)
+    let src=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:source))
+    let tgt=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:target))
+    if filewritable(tgt)==1
+        if a:force
+            call delete(tgt)
+        else
+            call s:_f.throw('tgtex', tgt)
+        endif
+    elseif s:_r.os.path.exists(tgt)
+        " Don’t try to delete directories and non-writable files.
+        call s:_f.throw('tgtex', tgt)
+    endif
+    let cmd=0
+    if executable('cp')
+        let cmd='cp --'
+    elseif executable('copy')
+        let cmd='copy'
+    endif
+    if cmd is 0
+        try
+            if writefile(readfile(src, 'b'), tgt, 'b')!=0
+                call s:_f.throw('wrfail', src, tgt)
+            endif
+        endtry
+    else
+        let hasnls=(stridx(src.tgt, "\n")==-1)
+        let cmd.=' '.shellescape(src, hasnls).' '.shellescape(tgt, hasnls)
+        if hasnls
+            let shout=system(cmd)
+        else
+            noautocmd tabnew
+            noautocmd setlocal buftype=nofile
+            noautocmd execute 'silent! %!'.cmd
+            let shout=join(getline(1, '$'), "\n")
+            noautocmd tabclose
+        endif
+        if v:shell_error
+            call s:_f.throw('cpfail', src, tgt, shout)
+        endif
+    endif
+    call a:repo.functions.add(a:repo, tgt)
+endfunction
+"▶1 remove
+function s:deffuncs.remove(repo, file)
+    call a:repo.functions.forget(a:repo, a:file)
+    let file=s:_r.os.path.join(a:repo.path, a:file)
+    if s:_r.os.path.isfile(file)
+        if delete(file)
+            call s:_f.throw('nrm', a:file, a:repo.path)
+        endif
+    endif
+endfunction
+"▶1 grep :: repo, pattern, [file], [Either hex (hex, hex)], ic, _ → qflist
+function s:deffuncs.grep(repo, pattern, files, revs, ic, wdf)
+    if empty(a:revs)
+        let cs=a:repo.functions.getwork(a:repo)
+        let filelist=copy(a:repo.functions.getcsprop(a:repo, cs, 'allfiles'))
+        if !empty(a:files)
+            call filter(filelist, 'index(a:files, v:val)!=-1')
+        endif
+        call map(filelist, 's:_r.os.path.join(a:repo.path, v:val)')
+        call filter(filelist, 'filereadable(v:val)')
+        let expr='readfile(fspec, "b")'
+    else
+        let css=[]
+        for rspec in a:revs
+            if type(rspec)==type([])
+                let css+=a:repo.functions.revrange(a:repo, rspec[0], rspec[1])
+            else
+                let css+=[a:repo.functions.getcs(a:repo, rspec)]
+            endif
+            unlet rspec
+        endfor
+        let filelist=[]
+        let gcspexpr='a:repo.functions.getcsprop(a:repo, v:val, "allfiles")'
+        let mexpr='extend(filelist, '.
+                    \    'map('.((empty(a:files))?
+                    \               (gcspexpr):
+                    \               ('filter(copy('.gcspexpr.'), '.
+                    \                       '"index(a:files, v:val)!=-1")')).
+                    \        ', "[css[".v:key."].hex, v:val]"))'
+        call map(copy(css), mexpr)
+        let expr='a:repo.functions.readfile(a:repo, fspec[0], fspec[1])'
+    endif
+    let r=[]
+    let fexpr='v:val[1]=~'.('?#'[!a:ic]).string(a:pattern)
+    for fspec in filelist
+        let r+=map(filter(map(copy(eval(expr)), '[v:key, v:val]'), fexpr),
+                    \'{"filename": fspec,"lnum": v:val[0]+1,"text": v:val[1]}')
+    endfor
+    return r
+endfunction
+"▶1 difftobuffer
+function s:deffuncs.difftobuffer(repo, buf, ...)
+    let diff=call(a:repo.functions.diff, [a:repo]+a:000, {})
+    let oldbuf=bufnr('%')
+    if oldbuf!=a:buf
+        execute 'buffer' a:buf
+    endif
+    call s:_r.lineutils.setlines(diff, 0)
+    if oldbuf!=a:buf
+        execute 'buffer' oldbuf
+    endif
+endfunction
+"▶1 diffname :: _, line, diffre, _ → rpath
+function s:deffuncs.diffname(repo, line, diffre, opts)
+    return get(matchlist(a:line, a:diffre), 1, 0)
+endfunction
+"▶1 getstats :: _, diff, diffopts → stats
+" stats :: { ( "insertions" | "deletions" ): UInt,
+"            "files": { ( "insertions" | "deletions" ): UInt } }
+function s:deffuncs.getstats(repo, diff, opts)
+    let diffre=a:repo.functions.diffre(a:repo, a:opts)
+    let i=0
+    let llines=len(a:diff)
+    let stats={'files': {}, 'insertions': 0, 'deletions': 0}
+    let file=0
+    let pmlines=0
+    while i<llines
+        let line=a:diff[i]
+        let newfile=a:repo.functions.diffname(a:repo, line, diffre, a:opts)
+        if newfile isnot 0
+            let file=newfile
+            let stats.files[file]={'insertions': 0, 'deletions': 0,}
+            let pmlines=2
+        elseif file is 0
+        elseif pmlines
+            let lstart=line[:2]
+            if lstart is# '+++' || lstart is# '---'
+                let pmlines-=1
+            endif
+        elseif line[0] is# '+'
+            let stats.insertions+=1
+            let stats.files[file].insertions+=1
+        elseif line[0] is# '-'
+            let stats.deletions+=1
+            let stats.files[file].deletions+=1
+        endif
+        let i+=1
+    endwhile
+    return stats
+endfunction
+"▶1 reltorepo :: repo, path → rpath
+function s:deffuncs.reltorepo(repo, path)
+    return join(s:_r.os.path.split(s:_r.os.path.relpath(a:path,
+                \                                       a:repo.path))[1:], '/')
+endfunction
+"▶1 checkremote
+function s:deffuncs.checkremote(...)
+    return 0
+endfunction
 "▶1 iterfuncs: cs generators
 " startfunc (here)  :: repo, opts → d
 "▶2 ancestors
 endfunction
 "▶2 changesets
 let s:iterfuncs.changesets=s:iterfuncs.revrange
-"▶1 getrevhex
-function s:deffuncs.getrevhex(repo, rev)
-    return a:rev.''
-endfunction
-"▶1 dirty :: repo, file → Bool
-function s:deffuncs.dirty(repo, file)
-    let status=a:repo.functions.status(a:repo, 0, 0, [a:file])
-    for [type, files] in items(status)
-        if type is# 'ignored' || type is# 'clean'
-            continue
-        endif
-        if index(files, a:file)!=-1
-            return 1
-        endif
-    endfor
-    return 0
-endfunction
-"▶1 getnthparent :: repo, rev, n → cs
-function s:deffuncs.getnthparent(repo, rev, n)
-    let r=a:repo.functions.getcs(a:repo, a:rev)
-    let key=((a:n>0)?('parents'):('children'))
-    for i in range(1, abs(a:n))
-        let rl=a:repo.functions.getcsprop(a:repo, r, key)
-        if empty(rl)
-            break
-        endif
-        let r=a:repo.functions.getcs(a:repo, rl[0])
-    endfor
-    return r
-endfunction
-"▶1 reltorepo :: repo, path → rpath
-function s:deffuncs.reltorepo(repo, path)
-    return join(s:_r.os.path.split(s:_r.os.path.relpath(a:path,
-                \                                       a:repo.path))[1:], '/')
-endfunction
-"▶1 getcsprop :: repo, Either cs rev, propname → a
-function s:deffuncs.getcsprop(repo, csr, propname)
-    if type(a:csr)==type({})
-        let cs=a:csr
-    else
-        let cs=a:repo.functions.getcs(a:repo, a:csr)
-    endif
-    if has_key(cs, a:propname)
-        return cs[a:propname]
-    endif
-    call a:repo.functions.setcsprop(a:repo, cs, a:propname)
-    " XXX There is much code relying on the fact that after getcsprop property 
-    " with given name is added to changeset dictionary
-    return cs[a:propname]
-endfunction
-"▶1 revrange :: repo, rev, rev → [cs]
-function s:F.getrev(repo, rev, cslist)
-    if type(a:rev)==type(0)
-        if a:rev<0
-            return len(a:cslist)+a:rev
-        else
-            return a:rev
-        endif
-    else
-        return a:repo.functions.getcs(a:repo, a:rev).rev
-    endif
-endfunction
-function s:deffuncs.revrange(repo, rev1, rev2)
-    if empty(a:repo.cslist)
-        let cslist=a:repo.functions.getchangesets(a:repo)
-    else
-        let cslist=a:repo.cslist
-    endif
-    let rev1=s:F.getrev(a:repo, a:rev1, cslist)
-    let rev2=s:F.getrev(a:repo, a:rev2, cslist)
-    if rev1>rev2
-        let [rev1, rev2]=[rev2, rev1]
-    endif
-    return cslist[(rev1):(rev2)]
-endfunction
-"▶1 difftobuffer
-function s:deffuncs.difftobuffer(repo, buf, ...)
-    let diff=call(a:repo.functions.diff, [a:repo]+a:000, {})
-    let oldbuf=bufnr('%')
-    if oldbuf!=a:buf
-        execute 'buffer' a:buf
-    endif
-    call s:_r.lineutils.setlines(diff, 0)
-    if oldbuf!=a:buf
-        execute 'buffer' oldbuf
-    endif
-endfunction
-"▶1 diffname :: _, line, diffre, _ → rpath
-function s:deffuncs.diffname(repo, line, diffre, opts)
-    return get(matchlist(a:line, a:diffre), 1, 0)
-endfunction
-"▶1 getstats :: _, diff, diffopts → stats
-" stats :: { ( "insertions" | "deletions" ): UInt,
-"            "files": { ( "insertions" | "deletions" ): UInt } }
-function s:deffuncs.getstats(repo, diff, opts)
-    let diffre=a:repo.functions.diffre(a:repo, a:opts)
-    let i=0
-    let llines=len(a:diff)
-    let stats={'files': {}, 'insertions': 0, 'deletions': 0}
-    let file=0
-    let pmlines=0
-    while i<llines
-        let line=a:diff[i]
-        let newfile=a:repo.functions.diffname(a:repo, line, diffre, a:opts)
-        if newfile isnot 0
-            let file=newfile
-            let stats.files[file]={'insertions': 0, 'deletions': 0,}
-            let pmlines=2
-        elseif file is 0
-        elseif pmlines
-            let lstart=line[:2]
-            if lstart is# '+++' || lstart is# '---'
-                let pmlines-=1
-            endif
-        elseif line[0] is# '+'
-            let stats.insertions+=1
-            let stats.files[file].insertions+=1
-        elseif line[0] is# '-'
-            let stats.deletions+=1
-            let stats.files[file].deletions+=1
-        endif
-        let i+=1
-    endwhile
-    return stats
-endfunction
-"▶1 grep :: repo, pattern, [file], [Either hex (hex, hex)], ic, _ → qflist
-function s:deffuncs.grep(repo, pattern, files, revs, ic, wdf)
-    if empty(a:revs)
-        let cs=a:repo.functions.getwork(a:repo)
-        let filelist=copy(a:repo.functions.getcsprop(a:repo, cs, 'allfiles'))
-        if !empty(a:files)
-            call filter(filelist, 'index(a:files, v:val)!=-1')
-        endif
-        call map(filelist, 's:_r.os.path.join(a:repo.path, v:val)')
-        call filter(filelist, 'filereadable(v:val)')
-        let expr='readfile(fspec, "b")'
-    else
-        let css=[]
-        for rspec in a:revs
-            if type(rspec)==type([])
-                let css+=a:repo.functions.revrange(a:repo, rspec[0], rspec[1])
-            else
-                let css+=[a:repo.functions.getcs(a:repo, rspec)]
-            endif
-            unlet rspec
-        endfor
-        let filelist=[]
-        let gcspexpr='a:repo.functions.getcsprop(a:repo, v:val, "allfiles")'
-        let mexpr='extend(filelist, '.
-                    \    'map('.((empty(a:files))?
-                    \               (gcspexpr):
-                    \               ('filter(copy('.gcspexpr.'), '.
-                    \                       '"index(a:files, v:val)!=-1")')).
-                    \        ', "[css[".v:key."].hex, v:val]"))'
-        call map(copy(css), mexpr)
-        let expr='a:repo.functions.readfile(a:repo, fspec[0], fspec[1])'
-    endif
-    let r=[]
-    let fexpr='v:val[1]=~'.('?#'[!a:ic]).string(a:pattern)
-    for fspec in filelist
-        let r+=map(filter(map(copy(eval(expr)), '[v:key, v:val]'), fexpr),
-                    \'{"filename": fspec,"lnum": v:val[0]+1,"text": v:val[1]}')
-    endfor
-    return r
-endfunction
-"▶1 copy
-function s:deffuncs.copy(repo, force, source, target)
-    let src=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:source))
-    let tgt=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:target))
-    if filewritable(tgt)==1
-        if a:force
-            call delete(tgt)
-        else
-            call s:_f.throw('tgtex', tgt)
-        endif
-    elseif s:_r.os.path.exists(tgt)
-        " Don’t try to delete directories and non-writable files.
-        call s:_f.throw('tgtex', tgt)
-    endif
-    let cmd=0
-    if executable('cp')
-        let cmd='cp --'
-    elseif executable('copy')
-        let cmd='copy'
-    endif
-    if cmd is 0
-        try
-            if writefile(readfile(src, 'b'), tgt, 'b')!=0
-                call s:_f.throw('wrfail', src, tgt)
-            endif
-        endtry
-    else
-        let hasnls=(stridx(src.tgt, "\n")==-1)
-        let cmd.=' '.shellescape(src, hasnls).' '.shellescape(tgt, hasnls)
-        if hasnls
-            let shout=system(cmd)
-        else
-            noautocmd tabnew
-            noautocmd setlocal buftype=nofile
-            noautocmd execute 'silent! %!'.cmd
-            let shout=join(getline(1, '$'), "\n")
-            noautocmd tabclose
-        endif
-        if v:shell_error
-            call s:_f.throw('cpfail', src, tgt, shout)
-        endif
-    endif
-    call a:repo.functions.add(a:repo, tgt)
-endfunction
-"▶1 move
-function s:deffuncs.move(repo, force, source, target)
-    call a:repo.functions.copy(a:repo, a:force, a:source, a:target)
-    call a:repo.functions.remove(a:repo, a:source)
-endfunction
-"▶1 remove
-function s:deffuncs.remove(repo, file)
-    call a:repo.functions.forget(a:repo, a:file)
-    let file=s:_r.os.path.join(a:repo.path, a:file)
-    if s:_r.os.path.isfile(file)
-        if delete(file)
-            call s:_f.throw('nrm', a:file, a:repo.path)
-        endif
-    endif
-endfunction
-"▶1 checkremote
-function s:deffuncs.checkremote(...)
-    return 0
-endfunction
 "▶1 getdriver :: path, type → Maybe driver
 function s:F.getdriver(path, ptype)
     for driver in values(s:drivers)