Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / release / determine_release_state.pl
blob7ea99867121c4c1bc5eb14c54a7d858fa7c70150
1 #!/usr/bin/perl -w
3 use strict;
5 # This is the version in configure.ac:
6 my $official_version = $ARGV[0];
7 my $lastrelease = "unknown";
9 my $state = "unknown";
10 if (-e "_darcs/hashed_inventory") {
11 my $patches = `darcs changes --from-tag '$official_version' --count 2>/dev/null`;
12 unless ($patches) {
13 # Looks like "darcs changes" does not support --count argument
14 $patches = grep(/^\S/, `darcs changes --from-tag '$official_version'`);
16 $patches = $patches - 1 if ($patches > 0);
17 if ($patches == 0) {
18 if ($official_version =~ /pre(\d+)/) {
19 $state = "prerelease $1";
20 } elsif ($official_version =~ /rc(\d+)/) {
21 $state = "release candidate $1";
22 } elsif ($official_version =~ /^[0-9\.]+$/) {
23 $state = "release";
24 } else {
25 $state = "tag";
27 } elsif ($patches > 1) {
28 $state = "+ $patches patches";
29 } else {
30 $state = "+ $patches patch";
33 if (open(X,"darcs changes -t '^[0-9\.]+\$' --reverse |")) {
34 while (<X>) {
35 if (/tagged (\S+)$/) {
36 $lastrelease = $1;
40 } elsif (open(FIN,"release/STATE")) {
41 my $statestring = <FIN>;
42 if ($statestring =~ /\((.+)\)/) {
43 $state = $1;
45 close(FIN);
48 print "$official_version ($state)\n";
50 if (open(FIN,"src/ThisVersion.lhs.in") && open(FOUT,">src/ThisVersion.lhs.tmp")) {
51 while (<FIN>) {
52 s/\@DARCS_VERSION_STATE\@/$state/g;
53 s/\@DARCS_VERSION\@/$official_version/g;
54 print FOUT $_;
56 close(FIN);
57 close(FOUT);
61 my $replace = 1;
62 if (open(FIN,"src/ThisVersion.lhs") && open(FTMP,"src/ThisVersion.lhs.tmp")) {
63 my ($old, $new);
64 read FIN, $old, 10000;
65 read FTMP, $new, 10000;
66 $replace = $old ne $new;
67 close(FIN);
68 close(FTMP);
71 if ($replace) {
72 rename "src/ThisVersion.lhs.tmp", "src/ThisVersion.lhs";
73 } else {
74 unlink "src/ThisVersion.lhs.tmp";
77 if (open(FIN,"doc/index.html.in") && open(FOUT,">doc/index.html")) {
78 while (<FIN>) {
79 s/VERSION/$official_version/g;
80 s/RELEASE/$lastrelease/g;
81 print FOUT $_;
83 close(FIN);
84 close(FOUT);