Commits

ZyX_I committed 8401a42

Made non-python driver always check return status
Fixed code that obtains null (00000000...) revision in non-python driver
Fixed repo.cslen computation in non-python driver
Fixed repo.cslen typing in python driver (it was either String or one-tuple)
Fixed :AuLog: it was assuming that getcsprop(..., "files") will also obtain cs.changes
Fixed $changes template key: it was not different from $files

  • Participants
  • Parent commits 410cb06

Comments (0)

Files changed (4)

File plugin/aurum.vim

     setlocal buftype=nofile readonly
     let buf=bufnr('%')
     setlocal modifiable
+    " FIXME This code is creating repository object for the second time
     "▶2 log command (repo:opts)
     if command is# 'log'
         let [repo, opts]=s:F.repotupleoptssplit(tail, 0)

File plugin/aurum/drivers/mercurial.vim

     call extend(s:_messages, {
                 \'parsefail': 'Failed to parse changeset information',
                 \ 'filefail': 'Failed to get file %s from repository %s: %s',
-                \ 'difffail': 'Failed to get diff for files %s '.
-                \             'from repository %s: %s',
+                \ 'difffail': 'Failed to get diff between %s and %s '.
+                \             'for files %s from the repository %s: %s',
+                \ 'statfail': 'Failed to obtain status information '.
+                \             'for the repository %s: %s',
+                \  'annfail': 'Failed to annotate revision %s of file %s '.
+                \             'in the repository %s: %s',
+                \  'cspfail': 'Failed to get property %s for changeset %s '.
+                \             'in the repository %s: %s',
+                \  'logfail': 'Failed to get log for repository %s: %s',
+                \  'keyfail': 'Failed to get %s for repository %s: %s',
+                \   'csfail': 'Failed to get changeset %s '.
+                \             'from the repository %s: %s',
+                \  'renfail': 'Failed to get renames list for revision %s '.
+                \             'in the repository %s: %s',
+                \  'cmdfail': 'Failure while running command %s '.
+                \             'for the repository %s: %s',
+                \ 'grepfail': 'Failed to search through repository %s: %s',
                 \ 'stat1mis': 'You must specify first revision as well',
-                \ 'statfail': 'Failed to obtain status information: %s',
-                \  'annfail': 'Failed to annotate revision %s of file %s: %s',
-                \ 'grepfail': 'Search failed: %s',
             \})
 endif
 "▶1 s:hypsites
         endfor
     endfor
 endfunction
-"▶2 hg :: repo, cmd, hasnulls → [String]
-function s:F.hg(repo, cmd, hasnulls)
+"▶2 hg :: repo, cmd, hasnulls, msgid[, throwarg1[, …]] → [String]
+function s:F.hg(repo, cmd, hasnulls, msgid, ...)
     let cmd='hg -R '.shellescape(a:repo.path, 1).' '.a:cmd
     if a:hasnulls
         let savedlazyredraw=&lazyredraw
         let r=getline(1, '$')
         noautocmd bwipeout!
         let &lazyredraw=savedlazyredraw
-        return r
     else
-        return split(system(cmd), "\n", 1)
+        let r=split(system(cmd), "\n", 1)
     endif
+    if v:shell_error
+        call call(s:_f.throw, [a:msgid.'fail']+a:000+[a:repo.path,
+                    \                                 join(r[:-1-(a:hasnulls)],
+                    \                                      "\n")], {})
+    endif
+    return r
 endfunction
 "▶2 parsecs :: csdata, lstart::UInt → [cs, line::UInt]
 function s:F.parsecs(csdata, lstart)
         call s:_f.throw('parsefail')
     endif
     if empty(match[1])
-        if cs.rev
+        if cs.rev>0
             let cs.parents=[cs.rev-1]
         else
             let cs.parents=[s:nullrev]
 "▶2 getcslist :: repo, start, end
 function s:F.getcslist(repo, start, end)
     let logbeg='log --template '.s:cstemplate.' '
-    let lines=s:F.hg(a:repo, logbeg.'-r '.a:start.'..'.a:end, 0)[:-2]
+    let lines=s:F.hg(a:repo, logbeg.'-r '.a:start.'..'.a:end, 0, 'log')[:-2]
     let css=[]
     if has_key(a:repo.changesets, s:nullrev)
         let cs0=a:repo.changesets[s:nullrev]
     else
-        let lines0=s:F.hg(a:repo, logbeg.'-r '.s:nullrev, 0)
+        let lines0=s:F.hg(a:repo, logbeg.'-r '.s:nullrev, 0, 'log')
         let cs0=s:F.parsecs(lines0, 0)[0]
     endif
     let llines=len(lines)
         let [cs, line]=s:F.parsecs(lines, line)
         if cs.rev-prevrev!=1
             let css+=map(range(prevrev+1, cs.rev-1),
-                        \'s:F.parsecs(s:F.hg(a:repo,logbeg."-r".v:val,0),0)[0]')
+                        \'s:F.parsecs(s:F.hg(a:repo, logbeg."-r".v:val, 0, '.
+                        \                   '"log"), 0)[0]')
         endif
         let css+=[cs]
         let prevrev=cs.rev
     endwhile
+    let cs0.rev=len(css)
     let css+=[cs0]
     return css
 endfunction
 else
     "▶3 getkeylist :: repo, key → [(name, rev)]
     function s:F.getkeylist(repo, key)
-        let lines=s:F.hg(a:repo, a:key, 0)[:-2]
+        let lines=s:F.hg(a:repo, a:key, 0, 'key', a:key)[:-2]
         if len(lines)==1 && lines[0]!~#'\v\ [1-9]\d*\:\x{12}$'
             return []
         endif
                 endif
             endfor
         endfor
-        let a:repo.csnum=a:start+len(r.css)+1
+        let a:repo.csnum=a:start+len(r.css)
         let a:repo.tip_hex=a:repo.functions.getrevhex(a:repo, 'tip')
         let a:repo.work_hex=a:repo.functions.getrevhex(a:repo, '.')
+        " " FIXME
+        " let r.startrev=
         return r
     endfunction
 endif
     let repo.work_hex=s:hg.getrevhex(repo, '.')
     let tipcs=s:hg.getcs(repo, 'tip')
     let repo.tip_hex=tipcs.hex
-    let repo.csnum=tipcs.rev+1
+    let repo.csnum=tipcs.rev+2
     return repo
 endfunction
 endif
         return a:repo.cslist[a:rev].hex
     endif
     let hex=get(s:F.hg(a:repo, 'log --template '.s:getrevhextemplate.' '.
-                \                  '-r '.shellescape(a:rev), 0), 0, 0)
-    if v:shell_error || hex is 0
+                \                  '-r '.shellescape(a:rev), 0, 'log'), 0, 0)
+    if hex is 0
         call s:_f.throw('norev', a:rev, a:repo.path)
     endif
     return hex
 else "▶2
 function s:hg.readfile(repo, rev, file)
     let r=s:F.hg(a:repo, 'cat -r '.shellescape(a:rev, 1).' -- '.
-                \             shellescape(a:file, 1), 1)
-    if v:shell_error
-        call s:_f.throw('filefail', a:file, a:repo.path, r[0])
-    endif
+                \             shellescape(a:file, 1), 1, 'file', a:file)
     return r
 endfunction
 endif
     let cmd='annotate -r '.shellescape(a:rev,1).' -fnl -- '.
                 \     shellescape(a:file,1)
     let r=[]
-    let lines=s:F.hg(a:repo, cmd, 1)
-    if v:shell_error
-        call s:_f.throw('annfail', a:rev, a:file, lines[0])
-    endif
+    let lines=s:F.hg(a:repo, cmd, 1, 'ann', a:rev, a:file)
     for line in lines
         " XXX This won't work for files that start with spaces and also with 
         " some other unusual filenames that can be present in a repository
 else "▶3
 function s:F.setcsprop(repo, cs, propname)
     if a:propname is# 'allfiles'
-        let r=s:F.hg(a:repo, 'manifest -r '.a:cs.rev, 0)[:-2]
-    elseif a:propname is# 'changes'
-        let r=map(s:F.hg(a:repo, 'status --change '.a:cs.rev.' -arm', 0)[:-2],
-                    \'v:val[2:]')
-    elseif a:propname is# 'files'
-        let r=map(s:F.hg(a:repo, 'status --change '.a:cs.rev.' -am', 0)[:-2],
-                    \'v:val[2:]')
+        let r=s:F.hg(a:repo, 'manifest -r '.a:cs.rev, 0,
+                    \'csp', a:propname, a:cs.rev)[:-2]
+    elseif a:propname is# 'changes' || a:propname is# 'files'
+        let lines=s:F.hg(a:repo, 'status --change '.a:cs.rev.' -arm', 0,
+                    \    'csp', a:propname, a:cs.rev)[:-2]
+        let a:cs.changes=map(lines, 'v:val[2:]')
+        let a:cs.files=filter(copy(a:cs.changes), 'lines[v:key][0] isnot# "R"')
+        return a:cs[a:propname]
     elseif a:propname is# 'children'
         " XXX str2nr('123:1f6de') will return number 123
         let r=map(split(s:F.hg(a:repo, 'log -r '.a:cs.rev.' --template '.
-                    \                       shellescape('{children}'), 0)[0]),
+                    \                       shellescape('{children}'), 0,
+                    \          'csp', a:propname, a:cs.rev)[0]),
                     \    'str2nr(v:val)')
         if empty(a:repo.cslist)
             call map(r, 'a:repo.functions.getrevhex(a:repo, v:val)')
 endfunction
 else "▶3
 function s:F.getcs(repo, hex)
-    let csdata=s:F.hg(a:repo, 'log -r '.a:hex.' --template '.s:cstemplate, 0)
+    let csdata=s:F.hg(a:repo, 'log -r '.a:hex.' --template '.s:cstemplate, 0,
+                \     'cs', a:hex)
     let cs=s:F.parsecs(csdata, 0)[0]
     call map(cs.parents, 'a:repo.functions.getrevhex(a:repo, v:val)')
     return cs
 endfunction
 else "▶3
 function s:F.getrenames(repo, cs, ...)
-    let slines=s:F.hg(a:repo, 'status --change '.a:cs.rev.' -raC', 0)[:-2]
-    if v:shell_error
-        " TODO
-    endif
+    let slines=s:F.hg(a:repo, 'status --change '.a:cs.rev.' -raC', 0,
+                \     'ren', a:cs.rev)[:-2]
     let copies={}
     let removed=[]
     let added=[]
 "▲3
 function s:hg.diff(repo, rev1, rev2, files, opts)
     let cmd=s:F.getdiffcmd(a:repo, a:rev1, a:rev2, a:files, a:opts)
-    let r=s:F.hg(a:repo, cmd, 1)
-    if v:shell_error
-        call s:_f.throw('difffail', join(a:files, ', '), a:repo.path, r[0])
-    endif
+    let r=s:F.hg(a:repo, cmd, 1, 'diff', string(a:rev1), string(a:rev2),
+                \                        join(a:files, ', '))
     return r+['']
 endfunction
 endif
                         \'shellescape(s:_r.os.path.join(a:repo.path, v:val))'))
         endif
     endif
-    let slines=s:F.hg(a:repo, cmd, 0)[:-2]
-    if v:shell_error
-        call s:_f.throw('statfail', slines[0])
-    endif
+    let slines=s:F.hg(a:repo, cmd, 0, 'stat')[:-2]
     let r=deepcopy(s:initstatdct)
     for line in slines
         let r[s:hgstatchars[line[0]]]+=[line[2:]]
                 \                                              'v:val), 1)'))
     endif
     let prevempty=0
-    for line in s:F.hg(a:repo, cmd, a:0 && a:1)[:-2+(a:0 && a:1)]
+    for line in s:F.hg(a:repo, cmd, a:0 && a:1, 'cmd', cmd)[:-2+(a:0 && a:1)]
         if empty(line)
             let prevempty+=1
         else
     let cmd.='--line-number '
     let cmd.='-- '.shellescape(a:pattern, 1).
                 \join(map(copy(a:files), 'shellescape(v:val, 1)'))
-    let lines=s:F.hg(a:repo, cmd, 1)
-    if v:shell_error
-        call s:_f.throw('grepfail', lines[0])
-    endif
+    let lines=s:F.hg(a:repo, cmd, 1, 'grep')
     let epath=escape(bvar.repo.path, ':\')
     let r=[]
     let cnmscache={}

File plugin/aurum/log.vim

 let s:kwexpr.files       = [2, 's:F.temp.multlfmt(@@@, a:cs.files, '.
             \                                    '@<@, @0@, '.
             \                                    '"file")', ', ']
-let s:kwexpr.changes     = [2, 's:F.temp.multlfmt(@@@, a:cs.files, '.
+let s:kwexpr.changes     = [2, 's:F.temp.multlfmt(@@@, a:cs.changes, '.
             \                                    '@<@, @0@, '.
             \                                    '"file")', ', ']
 let s:kwexpr.renames     = [2, 's:F.temp.renames(@@@, a:cs.files, '.
             call bvar.repo.functions.getcsprop(bvar.repo, cs, 'files')
         endfor
     endif
+    "▶2 Generate cs.changes for showfiles option
+    if get(bvar.opts, 'showfiles', 0)
+        for cs in cslist
+            call bvar.repo.functions.getcsprop(bvar.repo, cs, 'changes')
+        endfor
+    endif
     "▶2 Generate file lists for `files' option
     if has_key(bvar.opts, 'files')
         let bvar.opts.csfiles={}

File python/aurum.py

                     'tags': tags_vim,
                'bookmarks': bookmarks_vim,}
         vim.eval('extend(a:repo, {"tip_hex": "'+tipcs.hex()+'", '+
-                                 '"csnum": "'+str(len(repo)+1)+'"})')
+                                 '"csnum": '+str(len(repo)+1)+'})')
         vim.eval('extend(d, '+utf_dumps(d_vim)+')')
     except AurumError:
         pass
             vim_repo['work_hex']=repo['.'].hex()
             vim_repo['tip_hex']=repo['tip'].hex()
         if hasattr(repo, '__len__'):
-            vim_repo['csnum']=len(repo)+1,
+            vim_repo['csnum']=len(repo)+1
         vim.eval('extend(repo, '+utf_dumps(vim_repo)+')')
     except AurumError:
         pass