-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgit2tags
executable file
·84 lines (63 loc) · 1.32 KB
/
git2tags
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
#! /usr/bin/perl
use Getopt::Long;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 1;
use strict;
sub usage;
my $opt_watch = "version";
GetOptions(
'help' => sub { usage 0 },
'watch|w=s' => \$opt_watch,
) || usage 1;
usage 1 if @ARGV;
my @commits;
if(open my $f, "git log -- $opt_watch |") {
while(<$f>) {
push @commits, [ $1 ] if /^commit\s(\S+)/;
}
close $f;
}
for my $c (@commits) {
if(open my $f, "git branch --contains $c->[0] |") {
my ($br, $m);
while(<$f>) {
chomp;
$br = $1 if /^\*\s*(\S+)/;
$m = 1 if /^\*?\s*master/;
}
close $f;
$c->[1] = $br if $br && !$m;
}
}
for my $c (@commits) {
if(open my $f, "git show $c->[0] |") {
my $v = 0;
while(<$f>) {
chomp;
$v = 1, next if /^\+\+\+ b\/$opt_watch/;
if($v && /^\+(\S+)/) {
$c->[2] = $1;
last;
}
}
close $f;
}
}
for my $c (@commits) {
my $t = $c->[2];
$t = "$c->[1]-$t" if $c->[1];
print "git tag $t $c->[0]\n";
}
sub usage
{
my $err = shift;
print <<" usage";
Usage: git2tags [OPTIONS]
Try to relate git commits to tags and branch names based on changes to a version file.
-w, --watch Version file (default: \"$opt_watch\")
--help Print this help text.
usage
exit $err;
}