]> git.proxmox.com Git - mirror_frr.git/blame - lib/gitversion.pl
Merge pull request #13278 from FRRouting/mergify/bp/stable/8.5/pr-13269
[mirror_frr.git] / lib / gitversion.pl
CommitLineData
0be793e6
DL
1#!/usr/bin/perl -w
2use strict;
3
4my $dir = shift;
5chdir $dir || die "$dir: $!\n";
6
181d6146 7my $gitdesc = `git describe --always --first-parent --tags --dirty --match 'frr-*' || echo -- \"0-gUNKNOWN\"`;
0be793e6 8chomp $gitdesc;
7fb434ef 9my $gitsuffix = ($gitdesc =~ /-g([0-9a-fA-F]+(-dirty)?)$/) ? "-g$1" : "-gUNKNOWN";
0be793e6
DL
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