-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrevert.pl
68 lines (58 loc) · 1.64 KB
/
revert.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
# Adapter script for Revert.pm module
# exports Revert.pm functionality for command line use.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use Revert;
use Changeset;
if (scalar(@ARGV) < 1 || scalar(@ARGV) > 2)
{
print <<EOF;
usage: $0 <changeset_to_undo> [ <current_changeset> | <comment>]
where
changeset_to_undo : is the id of the changeset you want to revert,
or the minus sign (-) if you want to read a .osc file from stdin
current_changeset : is the id of a currently open changeset under
which this action will run.
If this is given, the changeset will not be closed in order
to allow you to run multiple operations on the same changeset.
If unset, a new changeset will be created and closed afterwards.
comment : the comment to use when closing the changeset (must not
be numeric lest it would be interpreted as a changeset id).
EOF
exit;
}
my ($undo_cs, $current_cs_or_comment) = @ARGV;
my $do_close = 0;
my $current_cs;
my $nontrivial_comment;
if ($undo_cs eq "-")
{
$undo_cs = "";
$undo_cs .= $_ while(<STDIN>);
}
# what have we got, changeset or comment?
if ($current_cs_or_comment =~ /^\d+$/)
{
$current_cs = $current_cs_or_comment;
}
else
{
my $comment = $current_cs_or_comment;
$nontrivial_comment = $comment;
$comment = "reverting changeset $undo_cs" unless defined($comment);
$current_cs = Changeset::create($comment);
$do_close = 1;
}
if (defined($current_cs))
{
if (Revert::revert($undo_cs, $current_cs, $nontrivial_comment))
{
if ($do_close)
{
Changeset::close($current_cs);
}
}
}