+sub cmd_find_rev {
+ my $revision_or_hash = shift;
+ my $result;
+ if ($revision_or_hash =~ /^r\d+$/) {
+ my $desired_revision = substr($revision_or_hash, 1);
+ my ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');
+ while (my $hash = <$fh>) {
+ chomp($hash);
+ my (undef, $rev, undef) = cmt_metadata($hash);
+ if ($rev && $rev eq $desired_revision) {
+ $result = $hash;
+ last;
+ }
+ }
+ command_close_pipe($fh, $ctx);
+ } else {
+ my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
+ $result = $rev;
+ }
+ print "$result\n" if $result;
+}
+