Commits

ZyX_I committed 10d822c

Added support for file=: to getrrf
Changed :AuCommit : to :AuCommit all
Partially fixed problems for opening already opened file from :AuRecord

Comments (0)

Files changed (7)

ftplugin/aurumlog.vim

     let epath=escape(bvar.repo.path, ':\')
     return ':silent edit '.
                 \fnameescape('aurum://log:'.epath.':'.opts.
-                \            'files:'.escape(file, ';,:\*?[').','.
+                \            'files:'.escape(file, ';,:\*?[{}').','.
                 \            'crrestrict:files')."\n"
 endfunction
 "▶1 update
     "      :AuForget ignore (adds ignored *patterns* to ./.hgignore and adds
     "                        .hgignore to repository if it is not present)
     " TODO :AuDirectory/:AuTree
-    " TODO :Au ?
     " TODO aurum#changeset(), aurum#repository() and aurum#status()
     " TODO vimdiff mapping to aurum://diff
-    " TODO make :AuLog accept date ranges
     let s:addargs={'Update': {'bang': 1}}
     for s:cmd in ['Diff', 'File', 'Update']
         let s:part=tolower(s:cmd[:3])
 let s:_messages={
             \'nocread': 'Cannot read aurum://commit',
         \}
-"▶1 setlines :: [String], read::Bool → + buffer
-function s:F.setlines(lines, read)
-    let d={'set': function((a:read)?('append'):('setline'))}
-    if len(a:lines)>1 && empty(a:lines[-1])
-        call d.set('.', a:lines[:-2])
-    else
-        if !a:read
-            setlocal binary noendofline
-        endif
-        call d.set('.', a:lines)
-    endif
-endfunction
 "▶1 closebuf :: bvar → + buf
 function s:F.closebuf(bvar)
     let r="\<C-\>\<C-n>"
     elseif command is# 'file'
         let [repo, rev, file]=s:F.repotuplesplit(tail, 2)
         let rev=repo.functions.getrevhex(repo, rev)
-        call s:F.setlines(repo.functions.readfile(repo, rev, file), a:read)
+        call s:_r.cmdutils.setlines(repo.functions.readfile(repo, rev, file),
+                    \               a:read)
         if !a:read
             let s:_r.bufvars[buf]={'repo': repo, 'rev': rev, 'file': file}
         endif
         " XXX All options should be from s:_r.repo.diffoptslst list
         call map(opts, '+v:val')
         if a:read
-            call s:F.setlines(repo.functions.diff(repo, rev1, rev2,
-                        \                              filelist, opts), 1)
+            call s:_r.cmdutils.setlines(repo.functions.diff(repo, rev1, rev2,
+                        \                                   filelist, opts), 1)
         else
             let s:_r.bufvars[buf]={'repo': repo, 'rev1': rev1, 'rev2': rev2,
                         \          'files': filelist, 'opts': opts,
     "▶2 copy command (file)
     elseif command is# 'copy'
         let file=tail
-        call s:F.setlines(readfile(file, 'b'), a:read)
+        call s:_r.cmdutils.setlines(readfile(file, 'b'), a:read)
         if !a:read
             let s:_r.bufvars[buf]={'file': file}
         endif
     endif
     let rev=repo.functions.getrevhex(repo, a:rev)
     if get(a:opts, 'replace', 0)
-        call s:F.setlines(repo.functions.readfile(repo, rev, file), 0)
+        call s:_r.cmdutils.setlines(repo.functions.readfile(repo, rev, file), 0)
         return
     endif
     let epath=escape(repo.path, ':\')

plugin/aurum/bufvars.vim

     if has_key(s:bufvars, buf)
         let bvar=s:bufvars[buf]
         if !has_key(bvar, 'command')
-        elseif bvar.command is# 'status' && get(bvar.opts, 'record', 0)
+        elseif has_key(bvar, 'bwfunc')
             let eval='<SNR>'.s:_sid.'_Eval'
             call feedkeys("\<C-\>\<C-n>:call ".
-                    \      "call(".eval."('s:bufvars[".buf."].recunload'), ".
+                    \      "call(".eval."('s:bufvars[".buf."].bwfunc'), ".
                     \           "[".eval."('s:bufvars[".buf."]')], {}) | ".
                     \"call ".eval."('remove(s:bufvars, ".buf.")')\n", 'n')
             return

plugin/aurum/cmdutils.vim

 "▶1 globtopattern :: glob → pattern
 function s:F.globtopattern(glob)
     " XXX If more metacharacters will be supported, they must be added to 
-    " escape() calls in s:F.filehistory in ftplugin/aurumlog and in logfunc call
+    " escape() calls in s:F.filehistory in ftplugin/aurumlog and in logfunc 
+    " call
+    " TODO {a,b}
     return '\V\^'.substitute(substitute(substitute(substitute(substitute(
-                \substitute(substitute(substitute(substitute(substitute(a:glob,
+                \substitute(substitute(substitute(substitute(substitute(
+                \substitute(substitute(a:glob,
                 \'\v\\(.)', '\="\\{".char2nr(submatch(1))."}"', 'g'),
                 \'\V//\+',  '/',              'g'),
                 \'\V/\$',   '',                ''),
-                \'\V**/',   '\\(**/\\)\\=',   'g'),
+                \'\V**/',   '\\%(**/\\)\\=',  'g'),
                 \'\V**',    '\\.\\\\{42}',    'g'),
                 \'\V*',     '\\\\{91}^/]\\*', 'g'),
                 \'\V?',     '\\.',            'g'),
+                \'\V[^',    '\\\\{91}\\^',    'g'),
+                \'\V[!',    '\\\\{91}^',      'g'),
                 \'\V[',     '\\[',            'g'),
                 \'\V\\{'.char2nr('\').'}', '\\\\', 'g'),
                 \'\V\\{\(\d\+\)}', '\=nr2char(submatch(1))', 'g').'\v($|\/)'
     let hasbuf=0
     let file=0
     "▶2 a:opts.file file → (repo?)
-    if has_key(a:opts, 'file')
+    if has_key(a:opts, 'file') && a:opts.file isnot# ':'
         if a:ann!=-1 && a:opts.repo is# ':'
             let repo=s:_r.repo.get(s:_r.os.path.dirname(a:opts.file))
             let file=repo.functions.reltorepo(repo, a:opts.file)
     endif
     return 1
 endfunction
+"▶1 setlines :: [String], read::Bool → + buffer
+function s:F.setlines(lines, read)
+    let d={'set': function((a:read)?('append'):('setline'))}
+    if len(a:lines)>1 && empty(a:lines[-1])
+        call d.set('.', a:lines[:-2])
+    else
+        if !a:read
+            setlocal binary noendofline
+        endif
+        call d.set('.', a:lines)
+    endif
+endfunction
 "▶1 Post cmdutils resource
 call s:_f.postresource('cmdutils', {'globtopat': s:F.globtopattern,
             \                      'encodeopts': s:F.encodeopts,
             \                          'getrrf': s:F.getrrf,
             \                     'getdifffile': s:F.getdifffile,
             \                       'checkrepo': s:F.checkrepo,
+            \                        'setlines': s:F.setlines,
             \                    'nogetrepoarg': s:nogetrepoarg,
             \                         'repoarg': s:repoarg,
             \})

plugin/aurum/commit.vim

     let repo=a:opts.repo
     call s:_r.cmdutils.checkrepo(repo)
     "▶2 Get file list
-    if a:0 && index(a:000, ':')!=-1
+    if a:0 && index(a:000, 'all')!=-1
         let files=[]
     elseif a:0
         if has_key(a:opts, 'type')
             let types=s:_r.status.parseshow(a:opts.type)
         endif
-        let filepats=map(copy(a:000), 's:_r.cmdutils.globtopat('.
-                    \                 'repo.functions.reltorepo(repo, v:val))')
+        let filepats=map(filter(copy(a:000), 'v:val isnot# ":"'),
+                    \    's:_r.cmdutils.globtopat('.
+                    \    'repo.functions.reltorepo(repo, v:val))')
         let status=repo.functions.status(repo)
         let files=[]
+        if len(filepats)!=a:0
+            let files+=[repo.functions.reltorepo(repo, expand('%'))]
+        endif
         let statfiles={}
         for [type, sfiles] in items(status)
             if type is# 'clean' || type is# 'ignored' ||

plugin/aurum/log.vim

         let special.branch_r=[[0, changesetend+1], [0, len(text[0])-1]]
     endif
     "▶3 Minimize changesets that do not match opts
+    " TODO Move this to glog.setup
     if (has_key(a:opts, 'branch') && a:cs.branch isnot# a:opts.branch) ||
                 \(has_key(a:opts, 'merges') &&
                 \   ((a:opts.merges)?(len(a:cs.parents)<=1):
 endfunction
 let s:_augroups+=['AuLogNoInsert']
 "▶1 logfunc
+" TODO make :AuLog accept date ranges
+" TODO Add :AuLog style
 function s:logfunc.function(repo, opts)
     call s:_r.cmdutils.checkrepo(a:repo)
     let opts=copy(a:opts)
             if curfile is 0
                 call remove(opts.files, 0)
             else
-                let opts.files[0]=escape(curfile, '\*?[')
+                let opts.files[0]=escape(curfile, '\*?[{}')
             endif
         endif
         call map(opts.files, 'a:repo.functions.reltorepo(a:repo, v:val)')

plugin/aurum/record.vim

     let bvar.recopts=extend(copy(a:opts), {'repo': repo})
     let bvar.bufnr=bufnr('%')
     let bvar.oldbufs={}
-    let bvar.recunload=s:F.unload
+    let bvar.bwfunc=s:F.unload
     let bvar.getwnrs=s:F.getwnrs
     if !bvar.startundo
         setlocal undolevels=-1
     return [lwnr, rwnr, swnr]
 endfunction
 "▶1 edit
-function s:F.edit(bvar, fname, ro, ...)
+function s:F.edit(bvar, fname, ro)
     let existed=bufexists(a:fname)
-    if a:0 && a:1
-        execute 'silent write!' fnameescape(a:fname)
-    endif
     execute 'silent edit' fnameescape(a:fname)
     let buf=bufnr('%')
     if existed
         endif
         if type is# 'modified' || type is# 'added'   || type is# 'unknown'
                     \          || type is# 'removed' || type is# 'deleted'
-            if modified
-                call s:F.edit(bvar, fullpath, 0)
-            else
+            if !modified
                 execute swnr.'wincmd w'
                 let status=3
                 let bvar.statuses[line('.')-1]=status
                 setlocal nomodifiable
                 execute lwnr.'wincmd w'
             endif
+            call s:F.edit(bvar, fullpath, 0)
             if type is# 'modified'
                 if !modified
-                    call s:F.edit(bvar, 'aurum://file:'.epath.':.:'.file, 0)
+                    let fcontents=bvar.repo.functions.readfile(
+                                \bvar.repo, bvar.repo.work_hex, file)
                 endif
                 diffthis
                 execute rwnr.'wincmd w'
                 wincmd p
             elseif !modified
                 if type is# 'added' || type is# 'unknown'
-                    call s:F.edit(bvar, 'aurum://copy:'.fullpath, 0)
+                    let fcontents=readfile(fullpath, 'b')
                 elseif type is# 'removed' || type is# 'deleted'
-                    call s:F.edit(bvar, 'aurum://file:'.epath.':.:'.file, 0)
+                    let fcontents=bvar.repo.functions.readfile(
+                                \bvar.repo, bvar.repo.work_hex, file)
                 endif
             endif
             if !modified
                     let isexe=0
                 endif
                 let diff=&diff
-                call s:F.edit(bvar, fullpath, 0, 1)
-                if diff
-                    diffthis
+                if exists('fcontents')
+                    silent %delete _
+                    call s:_r.cmdutils.setlines(fcontents, 0)
+                    if diff
+                        diffupdate
+                    endif
                 endif
                 if isexe && s:_r.os.name is# 'posix'
                     call s:_r.os.run(['chmod', '+x', fullpath])