-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartmktag
executable file
·121 lines (112 loc) · 2.69 KB
/
smartmktag
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /usr/bin/perl
use strict;
use File::Basename;
sub get_head_rev
{
my ($input, $rev);
my $dir = $_[0];
open($input, "git -C $dir log -1 |") or die "Failed to get HEAD revision: $!";
while (<$input>) {
chomp;
if (m/^commit\s+/) {
s/^commit\s//;
$rev=$_;
}
}
close $input;
return $rev;
}
sub extract_spec_version
{
my ($input, $version, $release);
my $dir = $_[0];
my $fn = $_[1];
my $rev = $_[2];
open($input, "git -C $dir show $rev:$fn |")
or "Failed to run git -C $dir show $rev:$fn: $!";
while (<$input>) {
chomp;
if (m/\s*Version:/) {
s/\s*Version:\s*//;
s/\s*$//;
$version = $_;
} elsif (m/\s*Release:/) {
s/\s*Release:\s*//;
s/\%.*//;
$release = $_;
}
}
close $input;
defined($version) and defined($release)
or die "Failed to extract version and release from $dir/$fn for revision $rev";
return "${version}-${release}";
}
sub git_config_get
{
my $dir = shift;
my $cfgname = shift;
my ($input, $retval);
open($input, "git config --get $cfgname |")
or die "Failed to run 'git config --get': $!";
while (<$input>) {
chomp;
$retval = $_;
last;
}
close $input;
return $retval
}
sub get_revison_and_version
{
my $input;
my $dir = shift;
my $count = shift;
if ($count == 0) {
$count = 10;
}
my @spec_files = glob("$dir/smartmet-*.spec");
scalar @spec_files == 1 or die "Exactly one SPEC file expected in $dir";
my $fn = basename($spec_files[0]);
print "Found spec file $fn\n";
open($input, "git -C $dir log -$count $fn |")
or die "Failed to get git history of $fn: $!";
my ($rev, $version);
$version = undef;
while (<$input>) {
if (m/^commit/) {
chomp;
s/^commit\s+//;
my $curr_rev = $_;
my $curr_ver = extract_spec_version($dir, $fn, $curr_rev);
if (!$version) {
$rev = $curr_rev;
$version = $curr_ver;
} elsif ($version eq $curr_ver) {
$rev = $curr_rev;
} else {
last;
}
}
}
close $input;
return ($rev, $version);
}
sub create_tag_if_needed
{
my $input;
my $dir = shift;
my ($rev, $ver_full) = get_revison_and_version($dir, 10);
print "Latest version change to $ver_full in SPEC file found at revision $rev\n";
open ($input, "git tag -l $ver_full |") or die "Failed to list tags";
my @tag_list = <$input>;
close $input;
if (scalar @tag_list == 0) {
my $head = get_head_rev $dir;
print "Creating tag $ver_full for commit $rev\n";
system("git -C $dir tag $ver_full $rev");
} else {
print "Tag $ver_full already exists\n"
}
}
#create_new_version(".", "Rebuilt due to joy");
create_tag_if_needed (".");