blob: 448f13d676fb2df361654faa43c2a4c05606e39d [file] [log] [blame]
David Lamparter0be793e2012-11-27 01:34:56 +00001#!/usr/bin/perl -w
2use strict;
3
4my $dir = shift;
5chdir $dir || die "$dir: $!\n";
6
7my $gitdesc = `git describe --always --dirty || echo -- \"0-gUNKNOWN\"`;
8chomp $gitdesc;
9my $gitsuffix = ($gitdesc =~ /([0-9a-fA-F]{7}(-dirty)?)$/) ? $1 : "-gUNKNOWN";
10
11printf STDERR "git suffix: %s\n", $gitsuffix;
12printf "#define GIT_SUFFIX \"%s\"\n", $gitsuffix;
13
14my $gitcommit = `git log -1 --format=\"%H\" || echo DEADBEEF`;
15chomp $gitcommit;
16open(BRANCHES, "git branch -a -v --abbrev=40|") || die "git branch: $!\n";
17my @names = ();
18while (<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
37printf STDERR "git branches: %s\n", join(", ", @names);
38
39my $cr = "\\r\\n\\";
40printf <<EOF, $gitdesc, join($cr."\n\\t", @names);
41#define GIT_INFO "$cr
42This is a git build of %s$cr
43Associated branch(es):$cr
44\\t%s$cr
45"
46EOF
47