Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactor changenr()

  • Loading branch information...
commit d95f2b5f2546ce3f9b62e66f873d145891db03c7 1 parent fc4de8b
Steve Losh authored October 09, 2010

Showing 1 changed file with 14 additions and 15 deletions. Show diff stats Hide diff stats

  1. 29  plugin/gundo.vim
29  plugin/gundo.vim
@@ -449,8 +449,10 @@ def generate(dag, edgefn, current):
449 449
 ENDPYTHON
450 450
 "}}}
451 451
 
452  
-"{{{ Mercurial utility functions
  452
+"{{{ Mercurial age function
453 453
 python << ENDPYTHON
  454
+import time
  455
+
454 456
 agescales = [("year", 3600 * 24 * 365),
455 457
              ("month", 3600 * 24 * 30),
456 458
              ("week", 3600 * 24 * 7),
@@ -498,12 +500,13 @@ def _goto_window_for_buffer(b):
498 500
 def _goto_window_for_buffer_name(bn):
499 501
     b = vim.eval('bufnr("%s")' % bn)
500 502
     _goto_window_for_buffer(b)
501  
-
502 503
 ENDPYTHON
503 504
 "}}}
504 505
 
505 506
 "{{{ Python undo tree data structures and functions
506 507
 python << ENDPYTHON
  508
+import itertools
  509
+
507 510
 class Buffer(object):
508 511
     def __init__(self):
509 512
         self.b = ''
@@ -536,13 +539,19 @@ def make_nodes(entries):
536 539
     _make_nodes(entries, nodes, root)
537 540
     return (root, nodes)
538 541
 
  542
+def changenr(nodes):
  543
+    _curhead_l = list(itertools.dropwhile(lambda n: not n.curhead, nodes))
  544
+    if _curhead_l:
  545
+        current = _curhead_l[0].parent.n
  546
+    else:
  547
+        current = int(vim.eval('changenr()'))
  548
+    return current
539 549
 ENDPYTHON
540 550
 "}}}
541 551
 
542 552
 "{{{ Graph rendering
543 553
 function! s:GundoRender()
544 554
 python << ENDPYTHON
545  
-import itertools, time
546 555
 
547 556
 ut = vim.eval('undotree()')
548 557
 entries = ut['entries']
@@ -559,12 +568,7 @@ def walk_nodes(nodes):
559 568
         yield(node, [node.parent] if node.parent else [])
560 569
 
561 570
 dag = sorted(nodes, key=lambda n: int(n.n), reverse=True) + [root]
562  
-
563  
-_curhead_l = list(itertools.dropwhile(lambda n: not n.curhead, dag))
564  
-if _curhead_l:
565  
-    current = _curhead_l[0].parent.n
566  
-else:
567  
-    current = int(vim.eval('changenr()'))
  571
+current = changenr(nodes)
568 572
 
569 573
 result = generate(walk_nodes(dag), asciiedges, current).splitlines()
570 574
 result = [' ' + l for l in result]
@@ -606,12 +610,7 @@ import vim
606 610
 _goto_window_for_buffer(vim.eval('g:gundo_target_n'))
607 611
 
608 612
 root, nodes = make_nodes(entries)
609  
-
610  
-_curhead_l = list(itertools.dropwhile(lambda n: not n.curhead, nodes))
611  
-if _curhead_l:
612  
-    current = _curhead_l[0].parent.n
613  
-else:
614  
-    current = int(vim.eval('changenr()'))
  613
+current = changenr(nodes)
615 614
 
616 615
 print current
617 616
 ENDPYTHON

0 notes on commit d95f2b5

Please sign in to comment.
Something went wrong with that request. Please try again.