ZyX_I avatar ZyX_I committed 41e9955

@aurum/log: Made glog.generate and glog.log_show_all iterating functions
Git-like grapher now does not know all revisions that are going to
be skipped, thus it outputs more lines then really necessary

Comments (0)

Files changed (2)

plugin/aurum/log.vim

             \'2multl': 'Two multiline statements on one line',
             \'argmis': 'Missing argument #%u for keyword %s',
         \}
+" iterfunc :: {fname: { "start": startfunc, "next": nextfunc }}
+" startfunc (always) :: repo, opts, * → d
+let s:iterfuncs={}
 "▶1 graph
 "▶2 graph.update_state :: graph, gstate → + graph
 function s:F.graph.update_state(s)
         let self.new_mapping+=plist
     endif
 endfunction
-"▶2 graph.insert_into_new_columns :: graph, cs, mapindex → mapindex + graph
-function s:F.graph.insert_into_new_columns(cs, mapindex)
+"▶2 graph.insert_into_new_columns :: graph, hex, mapindex → mapindex + graph
+function s:F.graph.insert_into_new_columns(hex, mapindex)
     let i=0
     for hex in self.new_columns
-        if hex is# a:cs.hex
+        if hex is# a:hex
             let self.mapping[a:mapindex]=i
             return a:mapindex+2
         endif
         let i+=1
     endfor
     let self.mapping[a:mapindex]=len(self.new_columns)
-    call add(self.new_columns, a:cs.hex)
+    call add(self.new_columns, a:hex)
     return a:mapindex+2
 endfunction
 "▶2 graph.update_columns :: graph → + graph
             let seen=1
             let self.commit_index=i
             for parent in self.interesting_parents
-                let midx=self.insert_into_new_columns(
-                            \                self.repo.changesets[parent], midx)
+                let midx=self.insert_into_new_columns(parent, midx)
             endfor
             if midx==oldmidx
                 let midx+=2
             endif
         else
-            let midx=self.insert_into_new_columns(self.repo.changesets[ccshex],
-                        \                         midx)
+            let midx=self.insert_into_new_columns(ccshex, midx)
         endif
     endfor
     while self.mapping_size>1 && self.mapping[self.mapping_size-1]==-1
 function s:F.graph.update(cs)
     let self.cs=a:cs
     let self.interesting_parents=filter(copy(a:cs.parents),
-                \                       'has_key(self.addchangesets, v:val)')
+                \                       '!has_key(self.skipchangesets, v:val)')
     let self.num_parents=len(self.interesting_parents)
     let self.prev_commit_index=self.commit_index
     call self.update_columns()
     call map(a:text.text, 'lines[v:key].v:val')
     return a:text
 endfunction
-"▶2 glog.generate
-function s:F.glog.generate(css, showparents, opts)
-    let seen=[]
-    let state=[0, 0]
-    let r=      {'text': [],
-                \'specials': {},
-                \'rectangles': [],
-                \'csstarts': {},}
-    for cs in a:css
-        let char=((index(a:showparents, cs.hex)==-1)?('o'):('@'))
-        if has_key(a:opts.skipchangesets, cs.hex)
-            let text={'skip': 1}
-            let skip=1
-        else
-            let text=a:opts.templatefunc(cs, a:opts)
-            let skip=0
-        endif
-        call s:F.glog.utf(state, 'C', char, text,
-                    \     s:F.glog.utfedges(seen, cs.hex, cs.parents))
-        if !has_key(text, 'text') || empty(text.text)
-            continue
-        endif
-        if !skip
-            let text.block_r[0][0]+=len(r.text)
-            let text.block_r[1][0]+=len(r.text)
-            let r.specials[cs.hex]=text.special
-            let r.rectangles+=[text.block_r+[cs.hex]]
-            let r.csstarts[cs.hex]=text.block_r[0][0]
-        endif
-        let r.text+=text.text
-    endfor
-    return r
-endfunction
 "▶2 glog.graph_init :: repo, [cs] → graph
 let s:defgraph={
             \'cs':                0,
             \'mapping':           [],
             \'new_mapping':       [],
             \'mapping_size':      0,
-            \'addchangesets':     {},
+            \'skipchangesets':    {},
         \}
-function s:F.glog.graph_init(css, showparents, opts)
+function s:F.glog.graph_init(showparents, opts)
     let graph=deepcopy(s:defgraph)
     let graph.repo=a:opts.repo
     let graph.workcss=a:showparents
-    call map(copy(a:css),
-                \'((has_key(a:opts.skipchangesets, v:val.hex))?(0):'.
-                \   '(extend(graph.addchangesets, {v:val.hex : v:val})))')
+    let graph.skipchangesets=a:opts.skipchangesets
     call extend(graph, s:F.graph)
     return graph
 endfunction
     let a:text.text=lines
     return a:text
 endfunction
-"▶2 glog.log_show_all :: [cs], showparents, opts → Log
-function s:F.glog.log_show_all(css, showparents, opts)
-    let graph=s:F.glog.graph_init(a:css, a:showparents, a:opts)
-    let show_header=1
-    let r={'text': [], 'specials': {}, 'rectangles': [], 'csstarts': {}}
-    for cs in filter(copy(a:css), 'has_key(graph.addchangesets, v:val.hex)')
-        let text=a:opts.templatefunc(cs, a:opts)
-        let text.block_r=[[0, 0],
-                    \     [len(text.text)-1,
-                    \      max(map(copy(text.text), 'len(v:val)'))]]
-        let text=s:F.glog.show_log(graph, cs, text)
-        let r.text+=text.text
-        let text.block_r[0][0]+=len(r.text)
-        let text.block_r[1][0]+=len(r.text)
-        let r.specials[cs.hex]=text.special
-        let r.rectangles+=[text.block_r+[cs.hex]]
-        let r.csstarts[cs.hex]=text.block_r[0][0]
-    endfor
-    return r
-endfunction
 "▶2 s:DateCmp :: cs, cs → -1|0|1
 function s:DateCmp(a, b)
     let a=a:a.time
 let s:_functions+=['s:DateCmp']
 "▶2 glog.graphlog
 function s:F.glog.graphlog(repo, opts, css)
-    let d={}
     if get(a:repo, 'has_octopus_merges', 1)
-        let d.func=s:F.glog.log_show_all
+        let iterfuncs=s:iterfuncs.git
     else
-        let d.func=s:F.glog.generate
+        let iterfuncs=s:iterfuncs.hg
     endif
-    return d.func(a:css, [a:repo.functions.getworkhex(a:repo)], a:opts)
+    let specials={}
+    let rectangles=[]
+    let csstarts={}
+    let text=[]
+    let d=iterfuncs.start(a:repo, a:opts, [a:repo.functions.getworkhex(a:repo)])
+    for cs in a:css
+        let [lines, rectangle, special]=iterfuncs.proccs(d, cs)
+        if rectangle isnot 0
+            let rectangle[0][0]=len(text)
+            let rectangle[1][0]=len(text)+len(lines)-1
+            let rectangle+=[cs.hex]
+            call add(rectangles, rectangle)
+            let csstarts[cs.hex]=rectangle[0][0]
+            if special isnot 0
+                let specials[cs.hex]=special
+            endif
+        endif
+        let text+=lines
+        unlet rectangle special
+    endfor
+    return    {'rectangles': rectangles,
+                \'specials': specials,
+                \'csstarts': csstarts,
+                \    'text': text,}
+endfunction
+"▶1 iterfuncs: loggers
+"▶2 iterfuncs.git
+" TODO Fix skipping changesets if possible
+let s:iterfuncs.git={}
+function s:iterfuncs.git.start(repo, opts, ...)
+    let graph=s:F.glog.graph_init(get(a:000, 0, []), a:opts)
+    return {'graph': graph, 'opts': a:opts}
+endfunction
+function s:iterfuncs.git.proccs(d, cs)
+    if has_key(a:d.opts.skipchangesets, a:cs.hex)
+        return [[], 0, 0]
+    endif
+    let text=a:d.opts.templatefunc(a:cs, a:d.opts)
+    let text.block_r=[[0, 0],
+                \     [len(text.text)-1,
+                \      max(map(copy(text.text), 'len(v:val)'))]]
+    let text=s:F.glog.show_log(a:d.graph, a:cs, text)
+    return [text.text, text.block_r, text.special]
+endfunction
+"▶2 iterfuncs.hg
+let s:iterfuncs.hg={}
+function s:iterfuncs.hg.start(repo, opts, ...)
+    return {'seen': [], 'state': [0, 0], 'opts': a:opts,
+                \'showparents': get(a:000, 0, [])}
+endfunction
+function s:iterfuncs.hg.proccs(d, cs)
+    let char=((index(a:d.showparents, a:cs.hex)==-1)?('o'):('@'))
+    if has_key(a:d.opts.skipchangesets, a:cs.hex)
+        let text={'skip': 1}
+        let skip=1
+    else
+        let text=a:d.opts.templatefunc(a:cs, a:d.opts)
+        let skip=0
+    endif
+    call s:F.glog.utf(a:d.state, 'C', char, text,
+                \     s:F.glog.utfedges(a:d.seen, a:cs.hex, a:cs.parents))
+    if !has_key(text, 'text') || empty(text.text)
+        return [[], 0, 0]
+    endif
+    if !skip
+        return [text.text, text.block_r, text.special]
+    else
+        return [text.text, 0, 0]
+    endif
 endfunction
 "▶1 temp
 "▶2 s:templates
     endtry
     return r
 endfunction
-"▶1 iterfuncs :: {fname: { "start": startfunc, "next": nextfunc }}
-" startfunc :: repo, opts → d
-" nextfunc  :: d → cs
-let s:iterfuncs={}
+"▶1 iterfuncs: cs generators
+" startfunc (here)  :: repo, opts → d
 "▶2 ancestors
 let s:iterfuncs.ancestors={}
 function s:iterfuncs.ancestors.start(repo, opts)
 "▶2 changesets
 let s:iterfuncs.changesets=s:iterfuncs.revrange
 "▶1 iterfuncs.check
+" startfunc (here)  :: repo, opts → d
 let s:fcheckpropslist=['renames', 'copies', 'changes', 'files']
 let s:iterfuncs.check={}
 "▶2 iterfuncs.check.start

Binary file modified.

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.