Commits

ZyX_I committed 225bb50

Move some logic from @%aurum/maputils to @aurum/repo

Comments (0)

Files changed (3)

autoload/aurum/maputils.vim

 endfunction
 "▶1 getnthparentfile :: repo, rev, file, n[, changedonly] → (hex, file)
 function s:r.getnthparentfile(repo, rev, file, n, ...)
-    let n=a:n
-    let shift=(n>0 ? 1 : -1)
-    let file=a:file
-    let prevhex=0
-    let hex=a:repo.functions.getrevhex(a:repo, a:rev)
-    while n && hex isnot# prevhex
-        let prevhex=hex
-        let cs=a:repo.functions.getnthparent(a:repo, hex, shift)
-        let rhex=(shift>0 ? hex : cs.hex)
-        if cs.hex is# hex
-            break
-        endif
-        let hex=cs.hex
-        let renames=a:repo.functions.getcsprop(a:repo, rhex, 'renames')
-        if shift<0
-            let rrenames={}
-            call map(copy(renames), 'extend(rrenames, {v:val : v:key})')
-            let renames=rrenames
-        endif
-        let haschanges=get(a:000, 0, 1)
-        if get(renames, file, 0) isnot 0
-            let file=renames[file]
-            let haschanges=1
-        elseif !haschanges
-            let status=a:repo.functions.status(a:repo, prevhex, hex, [a:file])
-            let haschanges=!empty(filter(copy(status),
-                        \              'v:key isnot# "clean" && !empty(v:val)'))
-        endif
-        if haschanges
+    if !a:0 || a:1
+        let n=a:n
+        let shift=(n>0 ? 1 : -1)
+        let file=a:file
+        let prevhex=0
+        let hex=a:repo.functions.getrevhex(a:repo, a:rev)
+        while n && hex isnot# prevhex
+            let prevhex=hex
+            let cs=a:repo.functions.getnthparent(a:repo, hex, shift)
+            let rhex=(shift>0 ? hex : cs.hex)
+            if cs.hex is# hex
+                break
+            endif
+            let hex=cs.hex
+            let renames=a:repo.functions.getcsprop(a:repo, rhex, 'renames')
+            if shift<0
+                let rrenames={}
+                call map(copy(renames), 'extend(rrenames, {v:val : v:key})')
+                let renames=rrenames
+            endif
+            if get(renames, file, 0) isnot 0
+                let file=renames[file]
+            endif
             let n-=shift
-        endif
-    endwhile
-    return [hex, file]
+        endwhile
+        return [hex, file]
+    else
+        let [hex, files]=a:repo.functions.getnthchangerev(a:repo, a:rev, a:n,
+                    \                                     [a:file])
+        return [hex, files[0]]
+    endif
 endfunction
 "▶1 Post maputils resource
 call s:_f.postresource('maputils', s:r)

autoload/aurum/repo.vim

 "▶1
-execute frawor#Setup('5.7', { '@/resources': '0.0',
+execute frawor#Setup('5.8', { '@/resources': '0.0',
             \                        '@/os': '0.0',
             \                   '@/options': '0.0',
             \                    '@/python': '1.0',
     endfor
     return r
 endfunction
+"▶1 getnthchangerev :: repo, rev, n, files → cs
+function s:deffuncs.getnthchangerev(repo, rev, n, files)
+    let n=a:n
+    let shift=(n>0 ? 1 : -1)
+    let files=copy(a:files)
+    let prevhex=0
+    let hex=a:repo.functions.getrevhex(a:repo, a:rev)
+    while n && hex isnot# prevhex
+        let prevhex=hex
+        let cs=a:repo.functions.getnthparent(a:repo, hex, shift)
+        let rhex=(shift>0 ? hex : cs.hex)
+        if cs.hex is# hex
+            break
+        endif
+        let hex=cs.hex
+        let renames=a:repo.functions.getcsprop(a:repo, rhex, 'renames')
+        if shift<0
+            let rrenames={}
+            call map(copy(renames), 'extend(rrenames, {v:val : v:key})')
+            let renames=rrenames
+        endif
+        let haschanges=0
+        let renamed=map(copy(files), 'get(renames, v:val, v:val)')
+        if renamed !=# files
+            let files=renamed
+            let haschanges=1
+        else
+            let status=a:repo.functions.status(a:repo, prevhex, hex, files)
+            let haschanges=!empty(filter(copy(status),
+                        \              'v:key isnot# "clean" && !empty(v:val)'))
+        endif
+        if haschanges
+            let n-=shift
+        endif
+    endwhile
+    return [hex, files]
+endfunction
 "▶1 getcsprop :: repo, Either cs rev, propname → a
 function s:deffuncs.getcsprop(repo, csr, propname)
     if type(a:csr)==type({})
     |aurum-cs.hex|.
   getwork :: () -> cs                                       *aurum-rf-getwork*
     Get changeset object for the working directory revision.
-  getnthparent :: hex, n -> cs                         *aurum-rf-getnthparent*
+  getnthparent :: hex, n[, [ file ]] -> cs             *aurum-rf-getnthparent*
     Get nth generation grand-parent of given revision. Use negative n to get 
     nth generation child instead. With n equal to zero it must work like 
     |aurum-rf-getcs|(hex).
+                                                    *aurum-rf-getnthchangerev*
+  getnthchangerev :: hex, n, [ file ] -> (cs, [ file ])
+    Like above, but with two differences:
+    1. Only changesets containing changes to files listed in the fourth 
+       argument are taken into account.
+    2. Returns a pair of |aurum-changeset| object and a list of files. In case 
+       there were no renames returned list is equal to the list given in 
+       arguments, otherwise it returns list with new filenames.
+       Note: copies are ignored.
   getchangesets :: () -> [ cs ]                       *aurum-rf-getchangesets*
     Pull all changesets contained in repository into |aurum-repo.changesets| 
     dictionary. If this function is not called, then |aurum-repo.changesets| 
 |aurum-cs.time| is always 0 if “date” programm from coreutils is missing.
 |aurum-cs.children| is always empty.
 |aurum-cs.phase| is always “unknown”.
-|aurum-rf-getchasgesets|, |aurum-rf-getcs| are unable to work with commits 
+|aurum-rf-getchangesets|, |aurum-rf-getcs| are unable to work with commits 
     where description contains line with two spaces followed by 60 dashes.
 |aurum-rf-updatechangesets| is doing nothing.
 |aurum-rf-getrevhex| calls |aurum-rf-getcs| thus it may be slow.
     5.5: Added |aurum-rf-apause| and |aurum-rf-aresume|.
     5.6: Added |aurum-rf-strip|.
     5.7: Now exporting default functions in _r.repo.defaultfuncs
+    5.8: Added |aurum-rf-getnthchangerev|.
 @aurum:
     0.1: Added |:AuBranch| and |:AuName|.
     0.2: Added |:AuOther|.
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 ProjectModifiedEvent.java.
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.