diff -ur v8/fsyn.py v9/fsyn.py --- v8/fsyn.py 2020-05-03 13:13:09.000000000 +0900 +++ v9/fsyn.py 2020-05-05 12:24:53.000000000 +0900 @@ -554,6 +554,9 @@ if do_checkout_clatest: checkout( get_clatest() ) + def tree(): + nodes_tree( get_link, get_curr() ) + return empty.new( locals() ) @@ -587,6 +590,75 @@ fsyn.checkout( id ) +def nodes_tree(get_link, curr): + def link_to_nodes(id, from_node=None): + link = get_link( id ) + node = empty.new( id=id, from_=from_node, to=[] ) + if link.to: + node.to = list( map( lambda id: link_to_nodes( id, node ), link.to ) ) + return node + + def get_tails(node): + if not node.to: + return [ node ] + return sum( map( get_tails, node.to ), [] ) + + def max_tail(node): + def len_from(node, from_node): + if node == from_node: + return 0 + return len_from( node.from_, from_node ) + 1 + + return max( get_tails( node ), key=lambda tail: len_from( tail, node ) ) + + def get_lst(from_node, tail): + lst = [ tail ] + while tail != from_node: + tail = tail.from_ + lst.insert( 0, tail ) + return lst + + lsts = [] + + def add_lst(from_node, i=0): + tail = max_tail( from_node ) + lst = get_lst( from_node, tail ) + if lsts: + n = len( lsts[ 0 ] ) + j = n - i - len( lst ) + lst = [ None ] * i + lst + [ None ] * j + lsts.append( lst ) + + n = len( lst ) + for i in reversed( range( n ) ): + node = lst[ i ] + if not node or len( node.to ) < 2: + continue + for to_node in node.to: + if to_node != lst[ i + 1 ]: + add_lst( to_node, i + 1 ) + + def show(): + if not lsts: + return + zip_lsts = list( zip( *lsts ) ) + n = len( zip_lsts ) + for i in reversed( range( n ) ): + lst = zip_lsts[ i ] + for j in range( len( lst ) ): + node = lst[ j ] + if node: + s = ' ' * j + node.id + if node.id == curr: + s += '@' # curr + elif i == n - 1 or not lsts[ j ][ i + 1]: + s += '*' # tail + dbg.out( s ) + + org = link_to_nodes( 'org' ) + add_lst( org ) + show() + if __name__ == "__main__": cmds = [ arg.cmd_new( 'create' ), @@ -606,6 +678,7 @@ arg.cmd_new( 'push', [ 'to_path' ] ), arg.cmd_new( 'pull', [ 'from_path' ] ), arg.cmd_new( 'clone', [ 'dot_fsyn_path' ], comment='ex. site/foo.fsyn' ), + arg.cmd_new( 'tree', comment='show id tree' ), ] cmd = arg.get_name_args( cmds )