David Lamparter | 0be793e | 2012-11-27 01:34:56 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | use strict; |
| 3 | |
| 4 | my $dir = shift; |
| 5 | chdir $dir || die "$dir: $!\n"; |
| 6 | |
| 7 | my $gitdesc = `git describe --always --dirty || echo -- \"0-gUNKNOWN\"`; |
| 8 | chomp $gitdesc; |
David Lamparter | 4a01458 | 2013-02-27 11:24:24 +0100 | [diff] [blame] | 9 | my $gitsuffix = ($gitdesc =~ /([0-9a-fA-F]{7}(-dirty)?)$/) ? "-g$1" : "-gUNKNOWN"; |
David Lamparter | 0be793e | 2012-11-27 01:34:56 +0000 | [diff] [blame] | 10 | |
| 11 | printf STDERR "git suffix: %s\n", $gitsuffix; |
| 12 | printf "#define GIT_SUFFIX \"%s\"\n", $gitsuffix; |
| 13 | |
| 14 | my $gitcommit = `git log -1 --format=\"%H\" || echo DEADBEEF`; |
| 15 | chomp $gitcommit; |
| 16 | open(BRANCHES, "git branch -a -v --abbrev=40|") || die "git branch: $!\n"; |
| 17 | my @names = (); |
| 18 | while (<BRANCHES>) { |
| 19 | chomp $_; |
| 20 | if (/\s+(.*?)\s+$gitcommit/) { |
| 21 | my $branch = $1; |
| 22 | if ($branch =~ /^remotes\/(.*?)(\/.*)$/) { |
| 23 | my $path = $2; |
| 24 | my $url = `git config --get "remote.$1.url"`; |
| 25 | chomp $url; |
| 26 | $url =~ s/^(git:|https?:|git@)\/\/github\.com/github/i; |
| 27 | $url =~ s/^(ssh|git):\/\/git\.sv\.gnu\.org\/srv\/git\//savannah:/i; |
| 28 | $url =~ s/^(ssh|git):\/\/git\.savannah\.nongnu\.org\//savannah:/i; |
| 29 | |
| 30 | push @names, $url.$path; |
| 31 | } else { |
| 32 | push @names, 'local:'.$branch; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | printf STDERR "git branches: %s\n", join(", ", @names); |
| 38 | |
| 39 | my $cr = "\\r\\n\\"; |
| 40 | printf <<EOF, $gitdesc, join($cr."\n\\t", @names); |
| 41 | #define GIT_INFO "$cr |
| 42 | This is a git build of %s$cr |
| 43 | Associated branch(es):$cr |
| 44 | \\t%s$cr |
| 45 | " |
| 46 | EOF |
| 47 | |