Commits

ZyX_I  committed 74f1327

Some :AuAnnotate fixes, made :AuAnnotate accept options (repo, rev and file), added :AuAnnotate tests

  • Participants
  • Parent commits e53d2d3

Comments (0)

Files changed (4)

File ftplugin/aurumannotate.vim

 function s:F.setup()
     let bvar=s:_r.aurum.bufvars[bufnr('%')]
     let ann=bvar.repo.functions.annotate(bvar.repo, bvar.rev, bvar.file)
-    setlocal readonly nomodifiable
     let d={}
     call map(ann, 'call(s:F.formatann, [bvar.repo, v:val, v:key], d)')
     call setline('.', ann)
+    setlocal readonly nomodifiable
     augroup AuAnnotateNoInsert
         autocmd InsertEnter <buffer> :call feedkeys("\e", 'n')
     augroup END

File plugin/aurum.vim

     let s:glogcomp=[]
     call s:_f.command.add('AuGlog', s:glogfunc, {'nargs': '*',
                 \                             'complete': s:glogcomp})
-    " TODO Add repo argument to :AuAnnotate and :AuVimDiff
+    " TODO Add repo argument to :AuVimDiff
     let s:annfunc={}
-    call s:_f.command.add('AuAnnotate', s:annfunc, {'nargs': '*'})
+    let s:anncomp=[]
+    call s:_f.command.add('AuAnnotate', s:annfunc, {'nargs': '*',
+                \                                'complete': s:anncomp})
     " TODO Add file argument to :AuVimDiff
     " TODO Make :AuVimDiff accept more then one revision argument
     let s:difffunc={}
+    let s:diffcomp=[]
     call s:_f.command.add('AuVimDiff', s:difffunc, {'nargs': '*'})
     " TODO Add :AuDiff
     let s:statfunc={}
             \'recheight': {'default': 0,
             \               'filter': '(if type "" earg _  range 0 inf)'},
         \}
+" XXX There is a code relying on the fact that here exists string `"."' that
+"     is a default argument to getrepo
 let s:repoarg=':*F.comm.getrepo(".") (either(path d, '.
             \                               'match @\v^\w+%(\+\w+)*\V://@) '.
             \                        '|*F.comm.getrepo '.
             \                        'type {})'
+            " FIXME Check when this line is just before `type {}'
+            " \                        '#norepo '.
 let s:_messages={
             \'uknundo': 'Cannot undo changes made manually. Resetting buffer '.
             \           'instead.',
             \'renfail': 'Failed to move file %s to %s',
             \'delfail': 'Failed to remove file %s',
             \ 'bkpmis': 'Backup file %s not found',
+            \ 'norepo': 'Failed to find a repository',
         \}
 "▶1 Вторая загрузка — функции
 "▶2 hg
 "▶3 comm.getrepo
 function s:F.comm.getrepo(path)
     if empty(a:path)
-        let path=fnamemodify('.', ':p')
+        let path=s:_r.os.path.realpath('.')
     elseif a:path is# ':'
         let buf=bufnr('%')
         if has_key(s:bufvars, buf) && has_key(s:bufvars[buf], 'repo')
             let path=s:bufvars[buf].repo.path
+        elseif empty(expand('%'))
+            let path=s:_r.os.path.realpath('.')
+        elseif isdirectory(expand('%:p:h'))
+            let path=s:_r.os.path.realpath(expand('%:p:h'))
         else
-            let path=expand('%:p')
+            let path=s:_r.os.path.realpath('.')
         endif
     else
-        let path=s:_r.os.path.abspath(a:path)
+        let path=s:_r.os.path.realpath(a:path)
     endif
     if path!~#'\v^\w+%(\+\w+)*\V://'
         let olddir=''
 "▶3 glogfunc
 function s:glogfunc.function(repo, opts)
     if type(a:repo)!=type({})
-        return
+        call s:_f.throw('norepo')
     endif
     if has_key(a:opts, 'files')
         call map(a:opts.files, 'a:repo.functions.reltorepo(a:repo, v:val)')
             \'\V|*F.comm.getrepo',  '',           ''),
             \'\vfiles\s+\([^)]*\)', 'files path', ''))
 "▶3 annfunc
-function s:annfunc.function(...)
-    let repo=s:F.comm.getrepo('')
-    let file=bufname('%')
-    let file=s:_r.os.path.relpath(file, repo.path)
-    let file=join(s:_r.os.path.split(file)[1:], '/')
-    let annbuf=bufnr('%')
+function s:annfunc.function(opts)
+    let repo=a:opts.repo
+    if type(repo)!=type({})
+        call s:_f.throw('norepo')
+    endif
+    let file=get(a:opts, 'file', bufname('%'))
+    let file=s:F.comm.reltorepo(repo, file)
+    let  rev=repo.functions.getrevhex(repo, get(a:opts, 'rev', '.'))
+    let epath=escape(repo.path, ':\')
+    if !has_key(a:opts, 'file')
+        let annbuf=bufnr('%')
+    endif
     setlocal scrollbind
-    execute 'leftabove 42vsplit '.fnameescape(
-                \'aurum://annotate::.:'.file)
+    execute 'leftabove 42vsplit '.
+                \fnameescape('aurum://annotate:'.epath.':'.rev.':'.file)
     setlocal scrollbind
-    let s:bufvars[bufnr('%')].annbuf=annbuf
+    if !has_key(a:opts, 'file')
+        let s:bufvars[bufnr('%')].annbuf=annbuf
+    endif
 endfunction
+let s:annfunc['@FWC']=['-onlystrings'.
+            \          '{  repo '.substitute(s:repoarg, '\V"."', '":"', '').
+            \          '  ?file (path)'.
+            \          '  ?rev  type ""'.
+            \          '}', 'filter']
+call add(s:anncomp,
+            \substitute(s:annfunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''))
 "▶3 statfunc
 function s:statfunc.function(repo, opts)
+    if type(a:repo)!=type({})
+        call s:_f.throw('norepo')
+    endif
     let opts=[]
     if has_key(a:opts, 'files')
         call map(a:opts.files, 'a:repo.functions.reltorepo(a:repo, v:val)')
             \                                  'match /\v^[MARDUIC!?]+$/))'.
             \           '}', 'filter']
 call add(s:statcomp,
-            \substitute(substitute(s:glogfunc['@FWC'][0],
+            \substitute(substitute(s:statfunc['@FWC'][0],
             \'\V|*F.comm.getrepo',  '',           ''),
             \'\vfiles\s+\([^)]*\)', 'files path', ''))
 "▶3 difffunc
 function s:difffunc.function(...)
     let repo=s:F.comm.getrepo('')
+    if type(repo)!=type({})
+        call s:_f.throw('norepo')
+    endif
     let file=bufname('%')
     let file=s:_r.os.path.relpath(file, repo.path)
     let file=join(s:_r.os.path.split(file)[1:], '/')
 function s:comfunc(opts, ...)
     let files=((a:0)?(a:000):([bufname('%')]))
     let repo=a:opts.repo
+    if type(repo)!=type({})
+        call s:_f.throw('norepo')
+    endif
     let types=get(a:opts, 'type', 0)
     if a:0
         let filepats=map(copy(a:000), 's:F.comm.globtopattern('.

File test/annotate.in

+:execute 'silent !hg clone testrepo '.g:curtest.'repo'
+:W{{{1 AuAnnotate
+:silent edit `=g:curtest.'repo/chgrepo.zsh'`
+:W{{{2 buffer
+:Run! AuAnnotate
+:W{{{2
+:call WriteFile(bufname('%'), 'w$: '.winnr('$').', w0: '.winnr())
+:bwipeout!
+:bwipeout!
+:W{{{1 AuAnnotate file
+:W{{{2 buffer
+:Run AuAnnotate file chgrepo.zsh
+:W{{{2
+:call WriteFile(bufname('%'), 'w$: '.winnr('$').', w0: '.winnr())
+:bwipeout!
+:bwipeout!
+:W{{{1 AuAnnotate file+rev
+:W{{{2 buffer
+:Run AuAnnotate file crepo.zsh rev 2
+:W{{{2
+:call WriteFile(bufname('%'), 'w$: '.winnr('$').', w0: '.winnr())
+:bwipeout!
+:bwipeout!
+:W{{{1 AuAnnotate file+rev+repo
+:W{{{2 buffer
+:Run! AuAnnotate file annotaterepo/crepo.zsh rev 2 repo annotaterepo
+:W{{{2
+:call WriteFile(bufname('%'), 'w$: '.winnr('$').', w0: '.winnr())
+:bwipeout!
+:bwipeout!
+:source addmessages.vim

File test/annotate.ok

Binary file added.