Commits

ZyX_I committed 4068004

@aurum/drivers/mercurial: Copied iterfuncs.ancestors from @aurum/repo
(thus it won’t be broken by fix for ref #8)
Added iterfuncs.revrange and iterfuncs.changesets

  • Participants
  • Parent commits 5ebfaae

Comments (0)

Files changed (1)

File plugin/aurum/drivers/mercurial.vim

     finish
 endif
 let s:hg={}
+let s:iterfuncs={}
 let s:usepythondriver=0
 if has_key(s:_r, 'py')
     try
         return 0
     endtry
     let repo.hypsites=deepcopy(s:hypsites)
+    let repo.iterfuncs=deepcopy(s:iterfuncs)
     return repo
 endfunction
 else "▶2
     let repo={'path': a:path, 'changesets': {}, 'cslist': [],
                 \'local': (stridx(a:path, '://')==-1),
                 \'labeltypes': ['tag', 'bookmark'],
-                \'has_octopus_merges': 0, 'requires_sort': 0}
+                \'has_octopus_merges': 0, 'requires_sort': 0,
+                \'iterfuncs': deepcopy(s:iterfuncs),
+                \'hypsites': deepcopy(s:hypsites),}
     return repo
 endfunction
 endif
     endif
     return cslist[(rev1):(rev2)]
 endfunction
+"▶1 iterfuncs
+"▶2 iterfuncs.ancestors
+let s:iterfuncs.ancestors={}
+function s:iterfuncs.ancestors.start(repo, opts)
+    let cs=a:repo.functions.getcs(a:repo,
+                \a:repo.functions.getrevhex(a:repo, a:opts.revision))
+    return {'addrevs': [cs], 'revisions': {}, 'repo': a:repo,
+                \'hasrevisions': get(a:repo, 'hasrevisions', 1)}
+endfunction
+function! s:RevCmp(cs1, cs2)
+    let rev1=a:cs1.rev
+    let rev2=a:cs2.rev
+    return ((rev1==rev2)?(0):((rev1<rev2)?(1):(-1)))
+endfunction
+let s:_functions+=['s:RevCmp']
+function s:iterfuncs.ancestors.next(d)
+    if empty(a:d.addrevs)
+        return 0
+    endif
+    let cs=remove(a:d.addrevs, 0)
+    if has_key(a:d.revisions, cs.hex)
+        return s:iterfuncs.ancestors.next(a:d)
+    endif
+    let a:d.revisions[cs.hex]=cs
+    let parents=map(copy(cs.parents),'a:d.repo.functions.getcs(a:d.repo,v:val)')
+    call extend(a:d.addrevs, parents)
+    if a:d.hasrevisions
+        call sort(a:d.addrevs, 's:RevCmp')
+    endif
+    return cs
+endfunction
+"▶2 iterfuncs.revrange
+let s:iterfuncs.revrange={}
+function s:iterfuncs.revrange.start(repo, opts)
+    let rev1=a:repo.functions.getcs(a:repo, a:opts.revrange[0]).rev
+    let rev2=a:repo.functions.getcs(a:repo, a:opts.revrange[1]).rev
+    if rev1>rev2
+        let [rev1, rev2]=[rev2, rev1]
+    endif
+    return {'cur': rev2, 'last': rev1, 'repo': a:repo}
+endfunction
+function s:iterfuncs.revrange.next(d)
+    if a:d.cur<a:d.last
+        return 0
+    endif
+    let r=a:d.repo.functions.getcs(a:d.repo, a:d.cur)
+    let a:d.cur-=1
+    return r
+endfunction
+"▶2 iterfuncs.changesets
+let s:iterfuncs.changesets={}
+function s:iterfuncs.changesets.start(repo, opts)
+    return {'cur': a:repo.functions.getcs(a:repo, 'tip').rev, 'last': 0,
+                \'repo': a:repo}
+endfunction
+let s:iterfuncs.changesets.next=s:iterfuncs.revrange.next
 "▶1 hg.getrevhex :: repo, rev → rev(hex)
 if s:usepythondriver "▶2
 function s:hg.getrevhex(repo, rev)