ZyX_I avatar ZyX_I committed fa198bc

@aurum/log: Some git graph code optimizations

Comments (0)

Files changed (1)

plugin/aurum/log.vim

         let self.new_mapping+=plist
     endif
 endfunction
-"▶2 graph.is_interesting_hex :: graph, hex → Bool
-function s:F.graph.is_interesting_hex(hex)
-    return has_key(self.addchangesets, a:hex)
-endfunction
-"▶2 graph.next_interesting_parent :: graph, [hex] → Maybe [hex]
-function s:F.graph.next_interesting_parent(orig)
-    for i in range(1, len(a:orig)-1)
-        if self.is_interesting_hex(a:orig[i])
-            return a:orig[(i):]
-        endif
-    endfor
-    return []
-endfunction
-"▶2 graph.first_interesting_parent :: graph → Maybe [hex]
-function s:F.graph.first_interesting_parent()
-    let parents=self.cs.parents
-    if empty(parents)
-        return []
-    elseif self.is_interesting_hex(parents[0])
-        return parents
-    else
-        return self.next_interesting_parent(parents)
-    endif
-endfunction
 "▶2 graph.insert_into_new_columns :: graph, cs, mapindex → mapindex + graph
 function s:F.graph.insert_into_new_columns(cs, mapindex)
     let i=0
-    for column in self.new_columns
-        if column.hex is# a:cs.hex
+    for hex in self.new_columns
+        if hex is# a:cs.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, {'hex': a:cs.hex})
+    call add(self.new_columns, a:cs.hex)
     return a:mapindex+2
 endfunction
-"▶2 graph.update_width :: graph, is_cs_in_existing_columns → + graph
-function s:F.graph.update_width(is_cs_in_existing_columns)
-    let maxcols=len(self.columns)+self.num_parents
-    if self.num_parents<1
-        let maxcols+=1
-    endif
-    if a:is_cs_in_existing_columns
-        let maxcols-=1
-    endif
-    let self.width=maxcols*2
-endfunction
 "▶2 graph.update_columns :: graph → + graph
 function s:F.graph.update_columns()
     let self.columns=self.new_columns
             let is_cs_in_columns=0
             let ccshex=self.cs.hex
         else
-            let ccshex=self.columns[i].hex
+            let ccshex=self.columns[i]
         endif
         if ccshex is# self.cs.hex
             let oldmidx=midx
             let seen=1
             let self.commit_index=i
-            let parents=self.first_interesting_parent()
-            while !empty(parents)
+            for parent in self.interesting_parents
                 let midx=self.insert_into_new_columns(
-                            \            self.repo.changesets[parents[0]], midx)
-                let parents=self.next_interesting_parent(parents)
-            endwhile
+                            \                self.repo.changesets[parent], midx)
+            endfor
             if midx==oldmidx
                 let midx+=2
             endif
     while self.mapping_size>1 && self.mapping[self.mapping_size-1]==-1
         let self.mapping_size-=1
     endwhile
-    call self.update_width(is_cs_in_columns)
+    let self.width=(len(self.columns)+self.num_parents+(self.num_parents<1)
+                \  -(is_cs_in_columns))*2
 endfunction
 "▶2 graph.update :: graph, cs → + graph
 function s:F.graph.update(cs)
     let self.cs=a:cs
-    let self.num_parents=len(filter(copy(a:cs.parents),
-                \               'self.is_interesting_hex(v:val)'))
+    let self.interesting_parents=filter(copy(a:cs.parents),
+                \                       'has_key(self.addchangesets, v:val)')
+    let self.num_parents=len(self.interesting_parents)
     let self.prev_commit_index=self.commit_index
     call self.update_columns()
     let self.expansion_row=0
     let seen=0
     let r=''
     let i=-1
-    for column in self.columns
+    for hex in self.columns
         let i+=1
-        if column.hex is# self.cs.hex
+        if hex is# self.cs.hex
             let seen=1
             let r.='|'.repeat(' ', self.expansion_row)
         elseif seen && self.expansion_row==0
 function s:F.graph.output_commit_line()
     let seen=0
     let r=''
-    for i in range(len(self.columns)+1)
-        if i==len(self.columns)
+    let lcolumns=len(self.columns)
+    for i in range(lcolumns+1)
+        if i==lcolumns
             if seen
                 break
             endif
             let ccshex=self.cs.hex
         else
-            let ccshex=self.columns[i].hex
+            let ccshex=self.columns[i]
         endif
         if ccshex is# self.cs.hex
             let seen=1
 function s:F.graph.output_post_merge_line()
     let seen=0
     let r=''
-    for i in range(len(self.columns)+1)
-        if i==len(self.columns)
+    let lcolumns=len(self.columns)
+    for i in range(lcolumns+1)
+        if i==lcolumns
             if seen
                 break
             endif
             let ccshex=self.cs.hex
         else
-            let ccshex=self.columns[i].hex
+            let ccshex=self.columns[i]
         endif
         if ccshex is# self.cs.hex
             let seen=1
-            let parents=self.first_interesting_parent()
             let r.='|'.repeat('\ ', self.num_parents-1)
         else
             let r.='|\'[seen].' '
     if self.state isnot# 'commit'
         return self.next_line()
     endif
-    let r=''
-    for column in self.columns
-        let ccshex=column.hex
-        let r.='|'.repeat(' ', ((ccshex isnot# self.cs.hex ||
-                    \            self.num_parents<3)?
-                    \               (1):
-                    \               ((self.num_parents-2)*2)))
-    endfor
-    let r.=self.pad_horizontally(len(self.columns))
+    if self.num_parents<3
+        let r.=repeat('| ', len(self.columns))
+    else
+        let r.=join(map(copy(self.columns),
+                    \   '"|".((v:val is# "'.self.cs.hex.'")?'.
+                    \           'repeat(" ", (self.num_parents-2)*2):'.
+                    \           '" ")'), '')
+    endif
+    let r.=self.pad_horizontally(len(r))
     let self.prev_state='padding'
     return r
 endfunction
-"▶2 graph.is_commit_finished :: graph → Bool
-function s:F.graph.is_commit_finished()
-    return (self.state is# 'padding')
-endfunction
 "▶2 graph.show_commit :: graph → [String]
 function s:F.graph.show_commit()
     let r=[]
 "▶2 graph.show_remainder :: graph → [String]
 function s:F.graph.show_remainder()
     let r=[]
-    while !self.is_commit_finished()
+    while self.state isnot# 'padding'
         let r+=[self.next_line()]
     endwhile
     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.