ZyX_I avatar ZyX_I committed 5db691d

Speed up svn.getnthchangerev

Comments (0)

Files changed (1)

autoload/aurum/drivers/subversion.vim

 function s:svn.getwork(repo)
     return a:repo.functions.getcs(a:repo, 'BASE')
 endfunction
-"▶1 svn.getnthparent :: repo, rev, n → cs
-function s:svn.getnthparent(repo, rev, n)
-    let rev=a:repo.functions.getrevhex(a:repo, a:rev)-a:n
-    if a:n<0 && rev<=0
-        let rev=0
-    elseif a:n>0
-        let tiprev=+a:repo.functions.gettiphex(a:repo)
-        if rev>tiprev
-            let rev=tiprev
-        endif
-    endif
-    return a:repo.functions.getcs(a:repo, rev)
-endfunction
 "▶1 svn.getnthchangerev :: repo, rev, n, [ file ] → (cs, [ file ])
 function s:svn.getnthchangerev(repo, rev, n, files)
     " TODO Do not download all changesets
-    call a:repo.functions.updatechangesets(a:repo)
+    if empty(a:repo.mutable.cslist)
+        call a:repo.functions.getchangesets(a:repo)
+    else
+        call a:repo.functions.updatechangesets(a:repo)
+    endif
     return s:_r.repo.defaultfuncs.getnthchangerev(a:repo, a:rev, a:n, a:files)
 endfunction
 "▶1 getchangesets :: repo[, hex[, hex]|limit] → [cs]
         call xml.skipctag()
         call xml.skipws()
         let a:repo.changesets[cs.hex]=cs
+        if !empty(cslist)
+            let cs.children=[cslist[-1].hex]
+            let cslist[-1].parents=[cs.hex]
+        endif
         call add(cslist, cs)
     endwhile
     if !has_key(kwargs, 'revision')
         endif
     "▶2 Not so complicated case: cs and its parent or itself
     elseif a:0>1 && !empty(a:1) && !empty(a:2) && a:1.a:2!~#'\D' &&
-                \abs(a:1-a:2)<=1
+                \(abs(a:1-a:2)<=1 || (has_key(a:repo.changesets, a:1) &&
+                \                     index(a:repo.changesets[a:1].parents+
+                \                           a:repo.changesets[a:1].children,
+                \                           a:2)!=-1) ||
+                \                    (has_key(a:repo.changesets, a:2) &&
+                \                     index(a:repo.changesets[a:2].parents+
+                \                           a:repo.changesets[a:2].children,
+                \                           a:1)!=-1))
         let r=copy(s:_r.utils.emptystatdct)
         if requiresclean
             let allfiles=copy(a:repo.functions.getcsprop(a:repo,a:1,'allfiles'))
                 call filter(allfiles, 'index(a:3, v:val)!=-1')
             endif
         endif
-        if abs(a:1-a:2)==1
-            let reverse=(a:2<a:1)
-            let s=a:repo.functions.getcs(a:repo, ''.max([+a:1, +a:2])).status
-            if a:0>2 && !empty(a:3)
-                let s=map(deepcopy(s), 'filter(v:val, "index(a:3,v:val)!=-1")')
-            endif
-            if requiresclean
-                let revs=s:F.statreverse(s)
-                call filter(allfiles, '!has_key(revs, v:val)')
-            endif
-            call extend(r, s)
-            "▶3 Reversing range
-            if reverse
-                let [r.deleted, r.unknown]=[r.unknown, r.deleted]
-                let [r.added,   r.removed]=[r.removed, r.added  ]
-            endif
-            "▲3
+        let reverse=(a:2<a:1)
+        let s=a:repo.functions.getcs(a:repo, ''.max([+a:1, +a:2])).status
+        if a:0>2 && !empty(a:3)
+            let s=map(deepcopy(s), 'filter(v:val, "index(a:3,v:val)!=-1")')
         endif
         if requiresclean
+            let revs=s:F.statreverse(s)
+            call filter(allfiles, '!has_key(revs, v:val)')
+        endif
+        call extend(r, s)
+        "▶3 Reversing range
+        if reverse
+            let [r.deleted, r.unknown]=[r.unknown, r.deleted]
+            let [r.added,   r.removed]=[r.removed, r.added  ]
+        endif
+        "▲3
+        if requiresclean
             let r.clean=allfiles
         endif
         return r
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.