std.c: Improve some comments
[sunny256-utils.git] / git-reach-commit
blobfbe1af3320af92b0becf332f833f3372c25000cc
1 #!/usr/bin/env perl
3 #=======================================================================
4 # git-reach-commit
5 # File ID: dc91cf88-abf1-11e5-bfdc-fefdb24f8e10
7 # Estimate when a project in Git will reach a certain number of commits.
9 # Character set: UTF-8
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 local $| = 1;
21 our %Opt = (
23 'goal' => '',
24 'help' => 0,
25 'quiet' => 0,
26 'ref' => '',
27 'verbose' => 0,
28 'version' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.2.0';
36 Getopt::Long::Configure('bundling');
37 GetOptions(
39 'goal|g=i' => \$Opt{'goal'},
40 'help|h' => \$Opt{'help'},
41 'quiet|q+' => \$Opt{'quiet'},
42 'ref|r=s' => \$Opt{'ref'},
43 'verbose|v+' => \$Opt{'verbose'},
44 'version' => \$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'verbose'} -= $Opt{'quiet'};
49 $Opt{'help'} && usage(0);
50 if ($Opt{'version'}) {
51 print_version();
52 exit(0);
55 exit(main());
57 sub main {
58 # {{{
59 my $Retval = 0;
61 if (!length($Opt{'goal'})) {
62 warn("$progname: -g/--goal not specified\n");
63 return(1);
66 if (!length($Opt{'ref'})) {
67 warn("$progname: -r/--ref not specified\n");
68 return(1);
71 chomp(my $begindate = `git log -1 $Opt{'ref'} --format=%ct`);
72 msg(2, "begindate = \"$begindate\"");
73 chomp(my $beginvalue = `git log --format=%h $Opt{'ref'} | wc -l`);
74 msg(2, "beginvalue = \"$beginvalue\"");
75 chomp(my $currentvalue = `git log --format=%h | wc -l`);
77 system(
78 "goal",
79 sec_to_string($begindate, " "),
80 $beginvalue,
81 $Opt{'goal'},
82 $currentvalue,
85 return $Retval;
86 # }}}
87 } # main()
89 sub print_version {
90 # Print program version {{{
91 print("$progname $VERSION\n");
92 return;
93 # }}}
94 } # print_version()
96 sub sec_to_string {
97 # Convert seconds since 1970 to "yyyymmddThhmmss[.frac]Z" {{{
98 my ($Seconds, $Sep) = @_;
99 length($Seconds) || return('');
100 ($Seconds =~ /^-?(\d*)(\.\d+)?$/) || return(undef);
101 my $Secfrac = ($Seconds =~ /^([\-\d]*)(\.\d+)$/) ? 1.0*$2 : "";
102 $Secfrac =~ s/^0//;
104 defined($Sep) || ($Sep = " ");
105 my @TA = gmtime($Seconds);
106 my($DateString) = sprintf("%04u-%02u-%02u %02u:%02u:%02u",
107 $TA[5]+1900, $TA[4]+1, $TA[3],
108 $TA[2], $TA[1], $TA[0]);
109 return($DateString);
110 # }}}
111 } # sec_to_string()
113 sub usage {
114 # Send the help message to stdout {{{
115 my $Retval = shift;
117 if ($Opt{'verbose'}) {
118 print("\n");
119 print_version();
121 print(<<"END");
123 Estimate when a project in Git will reach a certain number of commits.
125 Usage: $progname [options] -r REF -g GOAL
127 Options:
129 -g NUM, --goal NUM
130 Estimate when the repository will reach NUM commits.
131 -h, --help
132 Show this help.
133 -q, --quiet
134 Be more quiet. Can be repeated to increase silence.
135 -r REF, --ref REF
136 Commit or tag to use as start value.
137 -v, --verbose
138 Increase level of verbosity. Can be repeated.
139 --version
140 Print version information.
143 exit($Retval);
144 # }}}
145 } # usage()
147 sub msg {
148 # Print a status message to stderr based on verbosity level {{{
149 my ($verbose_level, $Txt) = @_;
151 if ($Opt{'verbose'} >= $verbose_level) {
152 print(STDERR "$progname: $Txt\n");
154 return;
155 # }}}
156 } # msg()
158 __END__
160 # This program is free software; you can redistribute it and/or modify
161 # it under the terms of the GNU General Public License as published by
162 # the Free Software Foundation; either version 2 of the License, or (at
163 # your option) any later version.
165 # This program is distributed in the hope that it will be useful, but
166 # WITHOUT ANY WARRANTY; without even the implied warranty of
167 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
168 # See the GNU General Public License for more details.
170 # You should have received a copy of the GNU General Public License
171 # along with this program.
172 # If not, see L<http://www.gnu.org/licenses/>.
174 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :