ZyX_I committed 3b633e9 Merge


Comments (0)

Files changed (1)


 let s:drivers={}
 let s:repos={}
+let s:bufrepos={}
 let s:_options={
             \'diffopts':  {'default': {},
             \              'checker': 'dict {numlines         range 0 inf '.
     return 0
-"▶1 getrepo :: path → repo
+"▶1 updaterepo :: repo → repo + repo
+function s:F.updaterepo(repo)
+    if !empty(a:repo.cslist)
+        call a:repo.functions.updatechangesets(a:repo)
+    endif
+    return a:repo
+"▶1 getrepo :: path → Maybe repo
 function s:F.getrepo(path)
     "▶2 Pull in drivers if there are no
     if empty(s:drivers)
     elseif a:path is# ':'
         let buf=bufnr('%')
         if has_key(s:_r.bufvars, buf) && has_key(s:_r.bufvars[buf], 'repo')
-            let path=s:_r.bufvars[buf].repo.path
+            return s:F.updaterepo(s:_r.bufvars[buf].repo)
         elseif has_key(s:_r.bufvars,buf) && s:_r.bufvars[buf].command is# 'copy'
             let path=s:_r.os.path.dirname(
-        elseif empty(&buftype) && isdirectory(expand('%:p:h'))
+        elseif empty(&buftype) && !empty(bufname('%')) &&
+                    \isdirectory(expand('%:p:h'))
             let path=s:_r.os.path.realpath(expand('%:p:h'))
             let path=s:_r.os.path.realpath('.')
+            unlet buf
     elseif stridx(a:path, '://')==-1
         let path=s:_r.os.path.realpath(a:path)
         let path=a:path
+    "▶2 Try to get repo from cache
+    if exists('buf') && has_key(s:bufrepos, buf)
+        return s:F.updaterepo(s:bufrepos[buf])
+    elseif has_key(s:repos, path)
+        return s:F.updaterepo(s:repos[path])
+    endif
     "▶2 Get driver
     if stridx(path, '://')==-1
         let olddir=''
     if driver is 0
         return 0
+    "▶2 Try to get repo from cache, attempt 2
+    if has_key(s:repos, path)
+        return s:F.updaterepo(s:repos[path])
+    endif
-    if has_key(s:repos, path)
-        let repo=s:repos[path]
-        if !empty(repo.cslist)
-            call repo.functions.updatechangesets(repo)
-        endif
-        return repo
-    endif
     let repo=driver.functions.repo(path)
     if repo is 0
         return 0
     unlockvar! repo.cslist
     unlockvar! repo.changesets
     unlockvar 1 repo
+    let s:repos[path]=repo
+    if exists('buf')
+        let s:bufrepos[buf]=repo
+    endif
     return repo
 "▶1 update
 call s:_f.newfeature('regdriver', {'cons': s:F.regdriver,
             \                    'unload': s:F.deldriver})
-call frawor#Lockvar(s:, '_pluginloaded,_r,repos,drivers')
+call frawor#Lockvar(s:, '_pluginloaded,_r,bufrepos,repos,drivers')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.