gitversion.pl 1.2 KB

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