3 # Copyright (C) 2014 Steven McDonald <steven@steven-mcdonald.id.au>
5 # This program is free software. It comes without any warranty, to the
6 # extent permitted by applicable law. You can redistribute it and/or
7 # modify it under the terms of the Do What The Fuck You Want To Public
8 # License, Version 2, as published by Sam Hocevar. See the COPYING file
9 # or visit http://www.wtfpl.net/ for more details.
17 my %name_to_node = (root => $tree);
18 my $show_detached = 0;
21 $show_detached = 1 if /^(-d|--show-detached)$/;
25 if (/^(\w+) at (\w+):?\s(.*?["(<])?([^"()<>\n]+)?/) {
28 $node_prettyname = "$1 ($4)";
30 $node_prettyname = $1;
34 $name_to_node{$2}{$node_prettyname} = $new_node;
35 $name_to_node{$1} = $new_node;
36 } elsif (/^(\w+) detached$/ and my $node = $name_to_node{$1}) {
37 $node->{_is_detached} = 1;
47 my $prev_indent = shift || "";
48 my $indent = $prev_indent . " |";
50 my @keys = keys $tree;
54 if (delete $tree->{$_}->{_is_detached}) {
55 next unless $show_detached;
56 $name = "$name [DETACHED]";
59 print $indent . "-$name\n";
60 $indent = $prev_indent . " " if $count eq $#keys;
61 print_tree $tree->{$_}, $indent;