script/git-logs2version.pl untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 75 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 #===============================================================================
3 #
4 # ABSTRACT: use number of git log messages as a standin for version number
5 # PODNAME: git-logs2version.pl
6 #
7 # AUTHOR: Reid Augustin (REID), <reid@lucidport.com>
8 # COMPANY: LucidPort Technology, Inc.
9 # CREATED: 09/07/2011 11:27:40 AM PST
10 #===============================================================================
11  
12 use strict;
13 use warnings;
14  
15 use File::Basename;
16  
17 our $VERSION = '0.017'; # VERSION
18  
19 my $major = 0;
20 my $offset = 0;
21  
22 my ($myname, undef, $suffix) = fileparse($0);
23 $myname .= $suffix;
24 my $help = "$myname [ --major number ] [ --offset number ]\n";
25  
26 while (my $arg = shift) {
27 if ($arg =~ s/^--?//) {
28 if ($arg eq 'major') {
29 $major = shift;
30 } elsif ($arg eq 'offset') {
31 $offset = shift;
32 }
33 } else {
34 die $help;
35 }
36 }
37 if (not defined ($major) or
38 ($major =~ m/\D/)) {
39 $major = '<undefined>' unless (defined($major));
40 die "$help\n*** illegal major: $major (must be a non-negative integer)\n";
41 }
42 if (not defined ($offset) or
43 ($offset !~ m/^-?\d+$/)) {
44 $offset = '<undefined>' unless (defined($offset));
45 die "$help\n*** illegal offset: $offset (must be an integer)\n";
46 }
47  
48 my $cmd = "git log --pretty=oneline";
49 my @logs = `$cmd`; # could use Git::Wrapper here
50  
51 if ($? == -1) {
52 die "failed to execute \"$cmd\": $!";
53 }
54 elsif ($? & 127) {
55 die sprintf("$cmd failed (with%s coredump) with signal %d\n",
56 ($? & 128) ? '' : 'out',
57 ($? & 127),
58 );
59 }
60 else {
61 # printf "child exited with value %d\n", $? >> 8;
62 }
63  
64 if (not @logs) {
65 die "No log entries. Is this really a git repo?";
66 }
67  
68 my $ver = scalar(@logs) + $offset;
69  
70 print STDERR "Version too big: $ver\n" if ($ver > 999);
71 printf ("%d.%03d\n", $major, $ver);
72  
73  
74  
75 __END__