Commits

ZyX_I  committed 1094f0e

@aurum/cache: Added _r.cache.wipe()
@aurum: Added wiping certain caches after some commands were called
@aurum/commit, @aurum/record: Added wiping all caches after write() is done
Fixes #43

  • Participants
  • Parent commits 65a1c15

Comments (0)

Files changed (7)

File autoload/aurum.vim

     if repo is 0 || file is 0
         return ''
     endif
-    if !has_key(cbvar, 'status')
-        augroup AuInvalidateStatusCache
-            autocmd! BufWritePost <buffer> :call s:_r.cache.del('status')
-        augroup END
-    endif
+    augroup AuInvalidateStatusCache
+        autocmd! BufWritePost <buffer> :call s:_r.cache.del('status')
+    augroup END
     return get(keys(filter(copy(s:_r.cache.get('status', repo.functions.status,
                 \                              [repo, 0, 0, [file]], {})),
                 \          'index(v:val, file)!=-1')), 0, '')

File autoload/aurum/commit.vim

             \             '@%aurum/status': '1.0',
             \           '@%aurum/cmdutils': '3.0',
             \            '@%aurum/bufvars': '0.0',
-            \               '@%aurum/edit': '1.0',})
+            \               '@%aurum/edit': '1.0',
+            \               '@aurum/cache': '2.1',})
 let s:_messages={
             \'emptmsg': 'Message must contain at least one non-blank character',
             \'nocfile': 'Unsure what should be commited',
 function s:commit.write(lines, repo, user, date, cb, files)
     let message=join(filter(copy(a:lines), 'v:val[0] isnot# "#"'), "\n")
     call a:repo.functions.commit(a:repo, message, a:files, a:user, a:date, a:cb)
+    call map(copy(s:_r.allcachekeys), 's:_r.cache.wipe(v:val)')
 endfunction
 call s:_f.newcommand(s:commit)
 "▶1 Post resource

File autoload/aurum/drivers/mercurial.vim

     endtry
 endfunction
 function s:hg.repo(path)
-    " TODO remove bookmark label type if it is not available
     let repo={'path': a:path, 'changesets': {}, 'mutable': {'cslist': []},
                 \'local': (stridx(a:path, '://')==-1),
                 \'labeltypes': ['tag', 'bookmark'],

File autoload/aurum/record.vim

             \                     '@/os': '0.0',
             \               '@/mappings': '0.0',
             \                   '@aurum': '1.0',
+            \             '@aurum/cache': '2.1',
             \           '@%aurum/commit': '1.0',
             \         '@%aurum/cmdutils': '3.0',
             \        '@%aurum/lineutils': '0.0',
     call feedkeys("\<C-\>\<C-n>:call ".
             \      "call(<SNR>".s:_sid."_Eval('s:F.runstatmap'), ".
             \           "['commit', ".expand('<abuf>')."], {})\n", 'n')
+    call map(copy(s:_r.allcachekeys), 's:_r.cache.wipe(v:val)')
 endfunction
 "▶1 recfunc
 " TODO investigate why closing record tab is causing next character consumption

File doc/aurum.txt

     0.1: Added |aurum#branch()| function.
 @aurum/cache:
     0.1: Added _r.cache.del().
-    1.0: Added _r.getcrf(), removed cachebvars export
-    2.0: Removed getcrf, added _r.cache.getcbvar
+    1.0: Added _r.getcrf(), removed cachebvars export.
+    2.0: Removed getcrf, added _r.cache.getcbvar.
+    2.1: Added _r.cache.wipe().
 ftplugin/aurumlog:
     0.1: Added OpenAny and AnnotateAny mappings.
 @%aurum/drivers/common/hypsites:

File plugin/aurum.vim

             \                     '@/fwc': '0.3',
             \            '@/autocommands': '0.0',
             \               '@/resources': '0.0',
-            \              '@aurum/cache': '2.0',})
+            \              '@aurum/cache': '2.1',})
 "▶1 Messages
 let s:_messages={
             \'afail': 'Failed to load aurum:// function from %s',
             \          'v:val is# "numlines" ? '.
             \               '" ?".v:val." range 0 inf" : '.
             \               '"!?".v:val'))
+let s:allcachekeys=['branch', 'changeset', 'repository', 'status']
 let s:cmds={
             \'Update':    {'opts': {'bang': 1},
             \               'fwc': '[:=(0) '.s:revarg.
             \                      '['.s:nogetrepoarg.']',
+            \              'wipe': ['branch', 'changeset', 'status'],
             \             },
             \'Move':      {'opts': {'bang': 1},
             \               'fwc': '{  repo '.s:nogetrepoarg.
             \                      ' ?!pretend'.
             \                      '} '.
             \                      '+ '.s:filearg,
+            \              'wipe': ['status'],
             \             },
             \'Junk':      { 'fwc': '{?!forget '.
             \                       '?!ignore '.
             \                       '?!remove '.
             \                       '?!ignoreglobs '.
             \                      '} + '.s:filearg,
+            \              'wipe': ['status'],
             \             },
-            \'Track':     {'fwc': '+ '.s:filearg,
+            \'Track':     { 'fwc': '+ '.s:filearg,
+            \              'wipe': ['status'],
             \             },
             \'Hyperlink': {'opts': {'range': '%'},
             \               'fwc': '{   ?repo '.s:nogetrepoarg.
             \               'fwc': 'type "" '.
             \                      '{  repo '.s:nogetrepoarg.
             \                      '}',
+            \              'wipe': ['branch', 'changeset'],
             \             },
             \'Name':      {'opts': {'bang': 1},
             \               'fwc': 'type ""'.
             \                      ' ?!local'.
             \                      '} '.
             \                      '+ type ""',
+            \              'wipe': ['branch', 'changeset'],
             \             },
             \'Other':     {'opts': {'bang': 1},
             \               'fwc': 'in ppactions ~ smart '.
             \                      '[:":" '.s:revarg.
             \                      '[:":" '.s:filearg.
             \                      '['.s:nogetrepoarg.']]]',
+            \              'wipe': s:allcachekeys,
             \             },
             \'Annotate':  { 'fwc': '{  repo  '.s:nogetrepoarg.
             \                      '  ?file  '.s:filearg.
             \                      ' !?closebranch'.
             \                      '}'.
             \                      '+ '.s:filearg,
+            \              'wipe': s:allcachekeys,
             \             },
             \'Diff':      { 'fwc': '{  repo     '.s:nogetrepoarg.
             \                      '  ?rev1     '.s:revarg.
 let s:tlist=['default', 'compact', 'git', 'svn', 'hgdef', 'hgdescr', 'cdescr',
             \'gitoneline']
 call s:_f.postresource('tlist', s:tlist)
+call s:_f.postresource('allcachekeys', s:allcachekeys)
 "▶1 Completion helpers
 let s:compcmds=['new', 'vnew', 'edit',
             \   'leftabove vnew', 'rightbelow vnew',
                 \                                   "'filter']}, ".
                 \                         "s:cmddicts[".s:eplid."]))\n".
                 \"    endif\n".
-                \"    return call(s:cmdfuncs[".s:eplid."], a:000, {})\n".
+                \"    call call(s:cmdfuncs[".s:eplid."], a:000, {})\n".
+                \((has_key(s:cdesc, 'wipe'))?
+                \    ("    call map(".string(s:cdesc.wipe).", ".
+                \                  "'s:_r.cache.wipe(v:val)')\n"):
+                \    ("")).
                 \"endfunction"
     unlet s:eplid
     call s:_f.command.add('Au'.s:cmd, remove(s:d, 'function'), s:cdesc.opts)

File plugin/aurum/cache.vim

 "▶1
 scriptencoding utf-8
 if !exists('s:_pluginloaded')
-    execute frawor#Setup('2.0', {'@/resources': '0.0',
+    execute frawor#Setup('2.1', {'@/resources': '0.0',
                 \                  '@/options': '0.0',}, 0)
     finish
 elseif s:_pluginloaded
             \'repocachetime':   {'default': 7, 'checker': 'range 0 inf'},
         \}
 let s:cachebvars={}
+let s:r={}
 "▶1 bufwipeout
 function s:F.bufwipeout()
     let buf=+expand('<abuf>')
     autocmd BufWipeOut,BufFilePost * :call s:F.bufwipeout()
 augroup END
 let s:_augroups+=['AurumCacheBufVars']
-"▶1 getcbvar ::  () + buf, cachebvars → cbvar + cachebvars?
-function s:F.getcbvar()
+"▶1 r.getcbvar ::  () + buf, cachebvars → cbvar + cachebvars?
+function s:r.getcbvar()
     let buf=bufnr('%')
     if !has_key(s:cachebvars, buf)
         let s:cachebvars[buf]={}
     endif
     return s:cachebvars[buf]
 endfunction
-"▶1 getcachedval :: key, func, args, dict → val + cbvar
-function s:F.getcachedval(key, Func, args, dict)
-    let cbvar=s:F.getcbvar()
+"▶1 r.get :: key, func, args, dict → val + cbvar
+function s:r.get(key, Func, args, dict)
+    let cbvar=s:r.getcbvar()
     if !(has_key(cbvar, a:key) &&
                 \localtime()-cbvar['_time'.a:key]<cbvar['_maxtime'.a:key])
         let cbvar[a:key]=call(a:Func, a:args, a:dict)
     endif
     return cbvar[a:key]
 endfunction
-"▶1 delcachedval :: key
-function s:F.delcachedval(key)
+"▶1 r.del :: key → + cbvar
+function s:r.del(key)
     let buf=bufnr('%')
     if !has_key(s:cachebvars, buf)
         return
         unlet cbvar[a:key]
     endif
 endfunction
+"▶1 r.wipe :: key → + cachebvars
+function s:r.wipe(key)
+    " empty() is here only to avoid possible “Using smth as a number” error
+    call map(copy(s:cachebvars), 'has_key(v:val,a:key) && '.
+                \                                  'empty(remove(v:val,a:key))')
+endfunction
 "▶1 Post cache resource
-call s:_f.postresource('cache', {'get': s:F.getcachedval,
-            \                    'del': s:F.delcachedval,
-            \               'getcbvar': s:F.getcbvar,})
+call s:_f.postresource('cache', s:r)
 "▶1
 call frawor#Lockvar(s:, '_pluginloaded,cachebvars')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲