topic: optionally add test markers.

Junio C Hamano committed Apr 8, 2008 at 22:09 UTC 5d403d8039ff60c9ed720c12e7a0b7c24a042abd
1 file changed +69 -3
git-topic.perl
+69 -3
@@ -12,6 +12,7 @@ my @stage = qw(next pu);
12 my @mark = ('.', '?', '-', '+');
13 my $all = 0;
14 my $merges = 0;
15 +my $tests = 0;
16
17 my @custom_stage;
18 my @custom_mark;
@@ -20,6 +21,7 @@ GetOptions("topic=s" => \$topic_pattern,
21 "stage=s" => \@custom_stage,
22 "mark=s" => \@custom_mark,
23 "merges!" => \$merges,
24 + "tests!" => \$tests,
25 "all!" => \$all)
26 or die;
27
@@ -75,6 +77,46 @@ sub rebase_marker {
77 return '*';
78 }
79
80 +my %atlog_next = ();
81 +my %atlog_test = ();
82 +
83 +sub next_marker {
84 + my ($topic) = @_;
85 + return '' if (!$tests);
86 + return '??' if (!exists $atlog_next{$topic});
87 + for ($atlog_next{$topic}) {
88 + my ($merge, $test) = ('*', '*');
89 + if (/rerere ok/) {
90 + $merge = 'R';
91 + } elsif (/conflict (\d+)/) {
92 + if ($1 < 10) {
93 + $merge = $1;
94 + } else {
95 + $merge = 'X';
96 + }
97 + }
98 + $test = 'X' if (/test error/);
99 + return "$merge$test";
100 + }
101 +}
102 +
103 +sub test_marker {
104 + my ($commit) = @_;
105 + return '' if (!$tests);
106 + my $tree = `git rev-parse "$commit^{tree}"`;
107 + chomp($tree);
108 + return "?" if (!exists $atlog_test{$tree});
109 + for ($atlog_test{$tree}) {
110 + if (/build error/) {
111 + return 'B';
112 + } elsif (/test error/) {
113 + return 'X';
114 + } else {
115 + return ' ';
116 + }
117 + }
118 +}
119 +
120 sub describe_topic {
121 my ($topic) = @_;
122
@@ -90,20 +132,39 @@ sub describe_topic {
132 }
133
134 my @in_next = read_revs_short('^master', $stage[0]);
135 +my @topic = ();
136 +
137 +my @topic_pattern = map { "refs/heads/$_" } (@ARGV ? @ARGV : $topic_pattern);
138
139 open(TOPIC, '-|', qw(git for-each-ref),
140 '--sort=-authordate',
141 '--format=%(objectname) %(authordate) %(refname)',
97 - "refs/heads/$topic_pattern")
142 + @topic_pattern)
143 or die;
144
100 -my @topic = ();
145 while (<TOPIC>) {
146 chomp;
147 my ($sha1, $date, $topic) = m|^([0-9a-f]{40})\s(.*?)\srefs/heads/(.+)$|
148 or next;
149 push @topic, [$sha1, $date, $topic];
150 }
151 +close(TOPIC);
152 +
153 +if (open(AT, "Meta/AT.log")) {
154 + my $next = `git rev-parse --verify refs/heads/next`;
155 + chomp $next;
156 + while (<AT>) {
157 + if (/^N (.{40}) (.{40}) (.*)$/ && $1 eq $next) {
158 + $atlog_next{$2} = $3;
159 + next;
160 + }
161 + if (/^A (.{40}) (.*)/) {
162 + $atlog_test{$1} = $2;
163 + next;
164 + }
165 + }
166 + close(AT);
167 +}
168
169 my @last_merge_to_next = ();
170
@@ -121,7 +182,9 @@ for (@topic) {
182 }
183 }
184
124 - print '*' . rebase_marker($sha1, $stage[0], \@in_next);
185 + print '*' .
186 + next_marker($sha1) .
187 + rebase_marker($sha1, $stage[0], \@in_next);
188 my $count = "";
189 if (1 < @revs) {
190 $count = " " . (scalar @revs) . " commits";
@@ -136,6 +199,9 @@ for (@topic) {
199 if ($mark < @mark) {
200 $mark = $mark[$mark];
201 }
202 + if ($tests) {
203 + $mark = test_marker($item->[0]) . $mark;
204 + }
205 wrap_print("$mark $item->[1]");
206 }
207 }