Commits

ZyX_I committed b92bfda

Got rid of repo.csnum, repo.tip_hex and repo.work_hex: this should reduce number of shell calls for non-python driver

  • Participants
  • Parent commits 96825d6

Comments (0)

Files changed (13)

File doc/aurum.txt

     Option    Description ~
     rev       Revision that is to be refered.
               Default: see |:AuAnnotate| (for url=html,raw,annotate,filehist),
-                       tip (for url=bundle,changeset),
+                       working directory revision (for url=bundle,changeset),
                        not applicable (for url=log,clone,push).
     file      File that is to be refered
               (only for url=html,raw,annotate,filehist)
 changesets :: {hex : cs}                               *aurum-repo.changesets*
     Dictionary containing all |aurum-changeset| objects that are associated 
     with the repository. For each changeset cs is repo.changesets[cs.hex].
-tip_hex :: hex                                            *aurum-repo.tip_hex*
-    Hash of latest revision in repository. See also |aurum-cs.hex|.
-work_hex :: hex                                          *aurum-repo.work_hex*
-    Hash of working directory revision. See also |aurum-cs.hex|.
 csnum :: UInt                                               *aurum-repo.csnum*
     Total number of revisions in repository. For any changeset 
     cs.rev<repo.csnum. See also |aurum-cs.rev|.
          number in both mercurial drivers, but though zero is a valid 
          revision, it is used to indicate absence of an argument and thus you 
          have to write '0' (String) where you want to write just 0 (Number).
+  gettiphex :: () -> hex                                  *aurum-rf-gettiphex*
+    Get changeset hash of the last revision in a repository.
+  getworkhex :: () -> hex                                *aurum-rf-getworkhex*
+    Get changeset hash of the working directory revision.
+  getwork:: () -> cs                                        *aurum-rf-getwork*
+    Get changeset object for the working directory revision.
   updatechangesets :: () -> _                      *aurum-rf-updatechangesets*
     Updates data stored in repository. Is called automatically when you get 
     the repository object unless this object is obtained from cash used by 

File ftplugin/aurumannotate.vim

     if a:action[-4:] is# 'diff'
         if a:action[:2] is# 'rev'
             let rev1=get(bvar.repo.functions.getcs(bvar.repo, hex).parents,0,'')
-        elseif bvar.rev isnot# bvar.repo.work_hex
+        elseif bvar.rev isnot# bvar.repo.functions.getworkhex(bvar.repo)
             let rev1=bvar.rev
         else
             let rev1=''

File ftplugin/aurumstatus.vim

         let rev2=''
     endif
     if empty(rev1) && empty(rev2)
-        let rev1=bvar.repo.work_hex
+        let rev1=bvar.repo.functions.getworkhex(bvar.repo)
     endif
     let curline=line('.')-1
     let vline1=line("'<")

File plugin/aurum.vim

         \}
 "▶1 getexsttrckdfiles
 function s:F.getexsttrckdfiles(repo)
-    let cs=a:repo.functions.getcs(a:repo, '.')
+    let cs=a:repo.functions.getwork(a:repo)
     let r=copy(a:repo.functions.getcsprop(a:repo, cs, 'allfiles'))
     let status=a:repo.functions.status(a:repo)
     call filter(r, 'index(status.removed, v:val)==-1 && '.
                         \index(repo.functions.status(repo).clean, file)==-1
                 call remove(opts, 'line')
             endif
-            let rev=repo.work_hex
+            let cs=repo.functions.getwork(repo)
+        else
+            let cs=repo.functions.getcs(repo, rev)
         endif
-        let cs=repo.functions.getcs(repo, rev)
         let gitbranch=s:F.urlescape(substitute(get(cs.bookmarks, 0, 'master'),
                     \                          '\m^origin/', '', ''))
     else
         let repo=s:_r.repo.get(a:opts.repo)
         call s:_r.cmdutils.checkrepo(repo)
         if utype is# 'bundle' || utype is# 'changeset'
-            let rev=get(a:opts, 'rev', 'tip')
-            let cs=repo.functions.getcs(repo, rev)
+            if has_key(a:opts, 'rev')
+                let cs=repo.functions.getwork(repo)
+            else
+                let cs=repo.functions.getcs(repo, a:opts.rev)
+            endif
             let gitbranch=s:F.urlescape(substitute(get(cs.bookmarks,0,'master'),
                         \                          '\m^origin/', '', ''))
         endif
     if has_key(a:opts, 'files')
         if empty(revisions)
             if get(a:opts, 'workmatch', 1)
-                let cslist=[repo.functions.getcs(repo, repo.work_hex)]
+                let cslist=[repo.functions.getwork(repo)]
             else
                 call repo.functions.getchangesets(repo)
                 let cslist=repo.cslist[:-2]

File plugin/aurum/annotate.vim

         return
     endif
     if rev is 0
-        let rev=repo.work_hex
+        let rev=repo.functions.getworkhex(repo)
     endif
     if hasannbuf
         let annbuf=bufnr('%')

File plugin/aurum/commit.vim

         if exists('g:AuPreviousRepoPath') &&
                     \   g:AuPreviousRepoPath is# a:repo.path &&
                     \exists('g:AuPreviousTip') &&
-                    \   g:AuPreviousTip is# a:repo.tip_hex &&
+                    \   g:AuPreviousTip is# a:repo.functions.gettiphex(a:repo)&&
                     \exists('g:AuPreviousCommitMessage')
             call setline('.', split(g:AuPreviousCommitMessage, "\n", 1))
             call cursor(line('$'), col([line('$'), '$']))
     endif
     if s:_f.getoption('remembermsg')
         let g:AuPreviousCommitMessage=message
-        let g:AuPreviousTip=a:bvar.repo.tip_hex
+        let g:AuPreviousTip=a:bvar.repo.functions.gettiphex(a:bvar.repo)
         let g:AuPreviousRepoPath=a:bvar.repo.path
     endif
     call a:bvar.repo.functions.commit(a:bvar.repo, message, a:bvar.files,

File plugin/aurum/diff.vim

     endif
     if empty(rev2)
         if empty(rev1)
-            let rev2=repo.work_hex
+            let rev2=repo.functions.getworkhex(repo)
         else
             let rev2=repo.functions.getnthparent(repo, rev1, 1).hex
         endif
             if filereadable(fullpath)
                 let cmd.=':edit'
             else
-                let cmd.=':AuFile '.((empty(bvar.rev2))?(bvar.repo.work_hex):
-                            \                           (bvar.rev2))
+                let cmd.=':AuFile '.
+                            \((empty(bvar.rev2))?
+                            \       (bvar.repo.functions.getworkhex(bvar.repo)):
+                            \       (bvar.rev2))
             endif
         else
             let cmd.=':AuFile '.bvar.rev1
         let rev2=a:repo.functions.getrevhex(a:repo, rev2)
     endif
     if empty(rev1) && empty(rev2)
-        let rev2=a:repo.work_hex
+        let rev2=a:repo.functions.getworkhex(a:repo)
     endif
     "▲2
     if a:read

File plugin/aurum/drivers/mercurial.vim

 else
     function s:F.getupdates(repo, start)
         let r={}
-        let a:repo.work_hex=a:repo.functions.getrevhex(a:repo, '.')
         let tip_hex=a:repo.functions.getrevhex(a:repo, 'tip')
         if a:start
             try
             endfor
         endfor
         let a:repo.csnum=a:start+len(r.css)
-        let a:repo.tip_hex=tip_hex
         return r
     endfunction
 endif
 "▶2 hg.updatechangesets
-" TODO test updating in cases of rollback and commit
+" TODO test updating in cases of rollback
 function s:hg.updatechangesets(repo)
     let d={}
     let start=len(a:repo.cslist)-2
     call s:F.addchangesets(a:repo, d.css)
     return a:repo
 endfunction
+"▶1 gettiphex :: repo → hex
+function s:hg.gettiphex(repo)
+    return a:repo.functions.getrevhex(a:repo, 'tip')
+endfunction
+"▶1 getworkhex :: repo → hex
+function s:hg.getworkhex(repo)
+    return a:repo.functions.getrevhex(a:repo, '.')
+endfunction
+"▶1 getwork :: repo → hex
+function s:hg.getwork(repo)
+    return a:repo.functions.getcs(a:repo, '.')
+endfunction
 "▶1 hg.repo :: path + ? → repo
 if s:usepythondriver "▶2
 function s:hg.repo(path)
     let repo={'path': a:path, 'changesets': {}, 'cslist': [],
                 \'local': (stridx(a:path, '://')==-1),
                 \'functions': copy(s:hg),}
-    try
-        let lines=s:F.hg(repo, 'log --template '.shellescape('{rev}:{node}\n').
-                    \             ' -r . -r tip', 0, 'log')[:-2]
-    catch
-        return 0
-    endtry
-    let t=(len(lines)!=1)
-    let repo.work_hex = lines[0][ stridx(lines[0], ':')+1:]
-    let repo.tip_hex  = lines[t][ stridx(lines[t], ':')+1:]
-    let repo.csnum    = lines[t][:stridx(lines[t], ':')-1 ]+2
     return repo
 endfunction
 endif

File plugin/aurum/log.vim

 function s:F.glog.graphlog(repo, opts)
     let css=reverse(a:repo.cslist[a:opts.revs[0]:a:opts.revs[1]])
     let a:opts.repo=a:repo
-    return s:F.glog.generate(css, [a:repo.work_hex], a:opts)
+    return s:F.glog.generate(css, [a:repo.functions.getworkhex(a:repo)], a:opts)
 endfunction
 "▶1 temp
 "▶2 s:templates

File plugin/aurum/record.vim

             if ntype is# 'm' || (modified && ntype is# 'a')
                 if !modified
                     let fcontents=bvar.repo.functions.readfile(
-                                \bvar.repo, bvar.repo.work_hex, file)
+                                \     bvar.repo,
+                                \     bvar.repo.functions.getworkhex(bvar.repo),
+                                \     file)
                 endif
                 diffthis
                 execute rwnr.'wincmd w'
                 if ntype is# 'r'
                     diffthis
                     execute rwnr.'wincmd w'
-                    call s:F.edit(bvar, ['file', bvar.repo, bvar.repo.work_hex,
-                                \        file], 1)
+                    call s:F.edit(bvar,
+                                \ ['file', bvar.repo,
+                                \  bvar.repo.functions.getworkhex(bvar.repo),
+                                \  file], 1)
                     diffthis
                     wincmd p
                 endif
                     let fcontents=readfile(fullpath, 'b')
                 elseif ntype is# 'r'
                     let fcontents=bvar.repo.functions.readfile(
-                                \bvar.repo, bvar.repo.work_hex, file)
+                                \     bvar.repo,
+                                \     bvar.repo.functions.getworkhex(bvar.repo),
+                                \     file)
                 endif
             endif
             if !modified

File plugin/aurum/repo.vim

     endif
     if has_key(s:repos, path)
         let repo=s:repos[path]
-        if empty(repo.cslist)
-            let repo.tip_hex=repo.functions.getrevhex(repo, 'tip')
-            let repo.work_hex=repo.functions.getrevhex(repo, '.')
-        else
+        if !empty(repo.cslist)
             call repo.functions.updatechangesets(repo)
         endif
         return repo
     lockvar! repo
     unlockvar! repo.cslist
     unlockvar! repo.changesets
-    unlockvar repo.work_hex
-    unlockvar repo.tip_hex
-    unlockvar repo.csnum
     unlockvar 1 repo
     return repo
 endfunction

File plugin/aurum/vimdiff.vim

         if empty(revs)
             let revs+=[rev]
         endif
-        let revs+=[repo.work_hex]
+        let revs+=[repo.functions.getworkhex(repo)]
     endif
     if revs[1] is# revs[0]
-        let revs[1]=get(repo.functions.getcs(repo, '.').parents, 0, 0)
+        let revs[1]=get(repo.functions.getwork(repo).parents, 0, 0)
         if revs[1] is 0
             call s:_f.throw('nodrev')
         endif

File python/aurum.py

 def get_updates(path, oldtip=None):
     try:
         repo=g_repo(path)
-        vim.eval('extend(a:repo, {"work_hex": "'+repo['.'].hex()+'"})')
         tipcs=repo['tip']
         if oldtip is not None:
             try:
                 'startrev': startrev,
                     'tags': tags_vim,
                'bookmarks': bookmarks_vim,}
-        vim.eval('extend(a:repo, {"tip_hex": "'+tipcs.hex()+'", '+
-                                 '"csnum": '+str(len(repo)+1)+'})')
+        vim.eval('extend(a:repo, {"csnum": '+str(len(repo)+1)+'})')
         vim.eval('extend(d, '+utf_dumps(d_vim)+')')
     except AurumError:
         pass
                 'cslist': [],
                  'local': 1 if repo.local() else 0,
                  }
-        if hasattr(repo, '__getitem__'):
-            vim_repo['work_hex']=repo['.'].hex()
-            vim_repo['tip_hex']=repo['tip'].hex()
         if hasattr(repo, '__len__'):
             vim_repo['csnum']=len(repo)+1
         vim.eval('extend(repo, '+utf_dumps(vim_repo)+')')