Commits

ZyX_I committed 3446d15

Some refactoring: moved some common code to get_revlist (aurum.py), made cs.parents and cs.children hold hex identifiers instead of links to dictionaries

Comments (0)

Files changed (3)

ftplugin/aurumgraphlog.vim

     endif
     let knownparents=[]
     let newparents=[]
-    for parent in a:parents
-        call add(((index(a:seen, parent.hex)==-1)?
+    for parenthex in a:parents
+        call add(((index(a:seen, parenthex)==-1)?
                     \   (newparents):
                     \   (knownparents)),
-                    \parent.hex)
+                    \parenthex)
     endfor
     let ncols=len(a:seen)
     call remove(a:seen, nodeidx)
     "▶3 Add patch
     if get(a:opts, 'patch', 0) && !empty(a:cs.parents)
         let diff=a:opts.repo.functions.diff(a:opts.repo, a:cs.hex,
-                    \                       a:cs.parents[0].hex, [],
-                    \                       {})
+                    \                       a:cs.parents[0], [], {})
         call map(diff, '":".v:val')
         let special.diff_R=[[len(text), 0], [len(text)+len(diff)-1, 0]]
         let text+=diff
         let epath=escape(bvar.repo.path, ':\')
         return ':e '.fnameescape('aurum://file:'.epath.':'.hex.':'.file)."\n".
                     \':diffsplit '.fnameescape('aurum://file:'.epath.':'.
-                    \                          cs.parents[0].hex.':'.file)."\n"
+                    \                          cs.parents[0].':'.file)."\n"
     endif
     return ''
 endfunction
 function s:F.next()
     let bvar=s:_r.aurum.bufvars[bufnr('%')]
     let [blockstart, blockend, hex]=s:F.getblock(bvar)
-    let child=get(bvar.repo.changesets[hex].children, 0, 0)
-    if child isnot 0
-        return (bvar.csstarts[child.hex]+1).'gg'
+    let childhex=get(bvar.repo.changesets[hex].children, 0, 0)
+    if childhex isnot 0
+        return (bvar.csstarts[childhex]+1).'gg'
     endif
     return ''
 endfunction
 function s:F.prev()
     let bvar=s:_r.aurum.bufvars[bufnr('%')]
     let [blockstart, blockend, hex]=s:F.getblock(bvar)
-    let parent=get(bvar.repo.changesets[hex].parents, 0, 0)
-    if parent isnot 0
-        return (bvar.csstarts[parent.hex]+1).'gg'
+    let parenthex=get(bvar.repo.changesets[hex].parents, 0, 0)
+    if parenthex isnot 0
+        return (bvar.csstarts[parenthex]+1).'gg'
     endif
     return ''
 endfunction
 function s:F.hg.addchangesets(repo, css)
     call map(copy(a:css), 'extend(a:repo.changesets, {v:val.hex : v:val})')
     for cs in a:css
-        call map(cs.parents, 'a:repo.changesets[v:val]')
-        for parent in cs.parents
-            call add(a:repo.changesets[parent.hex].children, cs)
+        for parenthex in cs.parents
+            call add(a:repo.changesets[parenthex].children, cs.hex)
         endfor
     endfor
 endfunction
 "▶3 hg.removechangesets :: repo, start_rev_num → + repo
 function s:F.hg.removechangesets(repo, start)
+    let changesets=a:repo.changesets
     for cs in remove(a:repo.cslist, a:start, -1)
-        for parent in cs.parents
-            call filter(parent.children, 'v:val isnot cs')
+        let hex=cs.hex
+        for parenthex in filter(cs.parents, 'has_key(changesets, v:val)')
+            call filter(changesets[parenthex].children, 'v:val isnot# cs.hex')
         endfor
-        for child in cs.children
-            call filter(child.parents, 'v:val isnot cs')
+        for childhex in filter(cs.children, 'has_key(changesets, v:val)')
+            call filter(changesets[childhex].parents, 'v:val isnot# cs.hex')
         endfor
     endfor
 endfunction
     call a:repo.functions.addchangesets(a:repo, d.css)
     let a:repo.work_hex=d.work_hex
     let a:repo.tip_hex=d.tip_hex
-    let a:repo.work=a:repo.changesets[a:repo.work_hex]
-    let a:repo.tip=a:repo.changesets[a:repo.tip_hex]
     return a:repo
 endfunction
 "▶3 hg.repo
         return 0
     endtry
     call s:F.hg.addchangesets(repo, repo.cslist)
-    let repo.work=repo.changesets[repo.work_hex]
-    let repo.tip=repo.changesets[repo.tip_hex]
-    let repo.type='hg'
     let s:repos[a:path]=repo
     return repo
 endfunction
     endif
     let repotype=s:F.comm.repotype(path)
     let repo=s:F[repotype].repo(path)
+    if repo is 0
+        return repo
+    endif
+    let repo.type=repotype
     let repo.functions=s:F[repotype]
     if !has_key(repo.functions, 'difftobuffer')
         let repo.functions.difftobuffer=s:F.comm.difftobuffer
         cs_vim['parents'].append(parent.hex())
     for file in cs.files():
         cs_vim['files'].append(file)
+    return cs_vim
 
 def get_updates(path, oldtip):
     repo=get_repo(path)
     if tipcs.hex()==cs.hex():
         return
     startrev=cs.rev()
-    curcsnum=startrev
-    cscount=tipcs.rev()+1
-    css_vim=[]
-    while curcsnum<=cscount:
-        cs_vim={'rev': curcsnum,
-            'parents': [],
-           'children': [],
-              'files': [],}
-        set_rev_dict(repo[curcsnum], cs_vim)
-        css_vim.append(cs_vim)
-        curcsnum+=1
-    vim.eval('extend(d, {"css": '+vim_dumps(css_vim)+', '+
+    r=get_revlist(repo, startrev)
+    vim.eval('extend(d, {"css": '+vim_dumps(r)+', '+
                         '"tip_hex": "'+tipcs.hex()+'", '+
                         '"work_hex": "'+repo['.'].hex()+'", '+
                         '"startrev": '+str(startrev)+'})')
 
+def get_revlist(repo, startrev=0):
+    cscount=repo['tip'].rev()+1
+    r=[set_rev_dict(repo[i], {'rev': i,
+                          'parents': [],
+                         'children': [],
+                            'files': [],}) for i in range(0, cscount+1)]
+    return r
+
 def new_repo(path):
     repo=get_repo(path)
     repo_vim={}
-    cscount=repo['tip'].rev()+1
     repo_vim['path']=path
-    repo_vim['cscount']=cscount
     repo_vim['changesets']={}
-    repo_vim['cslist']=[{'rev': i,
-                     'parents': [],
-                    'children': [],
-                       'files': [],} for i in range(0, cscount+1)]
     repo_vim['work_hex']=repo['.'].hex()
     repo_vim['tip_hex']=repo['tip'].hex()
-    curcsnum=0
-    while curcsnum<=cscount:
-        set_rev_dict(repo[curcsnum], repo_vim['cslist'][curcsnum])
-        curcsnum+=1
+    repo_vim['cslist']=get_revlist(repo)
     vim.eval('extend(repo, '+vim_dumps(repo_vim)+')')
 
 def get_file(path, rev, filepath):