3 - | open( $gitver, "git tag -l '[0-9]*.[0-9]*.[0-9]*' 2> /dev/null |" ); |
4 - | chomp( @versions = <$gitver> ); |
5 - | close( $gitver ); |
6 - | @versions = grep(/^\d+.\d+.\d$/, @versions); |
7 - | sort @versions; |
8 - | print( $versions[$#versions], "\n" ); |
3 + | |
4 + | |
5 + | |
6 + | |
7 + | |
8 + | |
9 + | |
10 + | |
11 + | my $gitbranch=`git rev-parse --abbrev-ref HEAD`; |
12 + | chomp($gitbranch); |
13 + | my $last_branch_tag=""; |
14 + | my $last_release_tag=""; |
15 + | if ($gitbranch eq "master" || $gitbranch =~ "release/"){ |
16 + | $last_release_tag=get_last_release_tag ($gitbranch); |
17 + | $last_branch_tag=$last_release_tag; |
18 + | } else { |
19 + | $last_release_tag=get_last_release_tag ($gitbranch); |
20 + | $last_branch_tag=get_last_branch_tag ($gitbranch); |
21 + | } |
22 + | |
23 + | print ("$last_branch_tag $last_release_tag"); |
24 + | my $headcommit=`git rev-parse HEAD`; |
25 + | |
26 + | |
27 + | if ($last_branch_tag eq "") { |
28 + | print (" dirty"); |
29 + | |
30 + | } else { |
31 + | my $tagcommit=`git rev-list -n 1 $last_branch_tag`; |
32 + | if ($headcommit ne $tagcommit) { |
33 + | print (" dirty"); |
34 + | } |
35 + | } |
36 + | |
37 + | print ("\n"); |
38 + | |
39 + | sub get_last_branch_tag () { |
40 + | my $gitbranch = shift; |
41 + | my $branchpattern = qr/^$gitbranch-\d+/; |
42 + | my $delim="-"; |
43 + | return get_last_tag($gitbranch,$branchpattern,$delim) |
44 + | } |
45 + | |
46 + | sub get_last_release_tag () { |
47 + | my $gitbranch = shift; |
48 + | my $branchpattern = qr/^\d+\.\d+\.\d+$/; |
49 + | my $delim="\\."; |
50 + | return get_last_tag($gitbranch,$branchpattern,$delim) |
51 + | } |
52 + | |
53 + | sub get_last_tag () { |
54 + | my $gitbranch = shift; |
55 + | my $branchpattern = shift; |
56 + | my $delim = shift; |
57 + | my @versions; |
58 + | my @tags; |
59 + | open( $githashes, "git log --since 2019-10-01 --simplify-by-decoration --pretty='%H' ".$gitbranch." |" ); |
60 + | chomp( @hashes = <$githashes> ); |
61 + | close( $githashes ); |
62 + | foreach ( @hashes ) { |
63 + | |
64 + | |
65 + | |
66 + | if ($gitbranch =~ "release/"){ |
67 + | $releaseid=(split('/',$gitbranch))[-1]; |
68 + | $grep_cmd = "git tag -l | grep \"" . "^" .$releaseid . "\" | "; |
69 + | open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | grep " .$releaseid ." |sed -e 's/\\^{}//' 2> /dev/null |" ); |
70 + | chomp( @tags = <$gitver> ); |
71 + | close( $gitver ); |
72 + | } |
73 + | else{ |
74 + | open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | sed -e 's/\\^{}//' 2> /dev/null |" ); |
75 + | chomp( @tags = <$gitver> ); |
76 + | close( $gitver ); |
77 + | } |
78 + | |
79 + | |
80 + | foreach my $tag (@tags) { |
81 + | |
82 + | if(grep(/$branchpattern/, $tag)) { |
83 + | |
84 + | |
85 + | push @versions, $tag; |
86 + | } |
87 + | } |
88 + | |
89 + | last if (scalar @versions >= 1); |
90 + | } |
91 + | my @sorted = |
92 + | map { $_->[0] } |
93 + | sort { $a->[1] cmp $b->[1] } |
94 + | map { [$_, join '', map { sprintf "%8d", $_ } split $delim, $_] } |
95 + | @versions; |
96 + | |
97 + | return($sorted[$#sorted]); |
98 + | } |