setlocalversion 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl
  2. # Copyright 2004 - Ryan Anderson <ryan@michonline.com> GPL v2
  3. use strict;
  4. use warnings;
  5. use Digest::MD5;
  6. require 5.006;
  7. if (@ARGV != 1) {
  8. print <<EOT;
  9. Usage: setlocalversion <srctree>
  10. EOT
  11. exit(1);
  12. }
  13. my ($srctree) = @ARGV;
  14. chdir($srctree);
  15. my @LOCALVERSIONS = ();
  16. # We are going to use the following commands to try and determine if this
  17. # repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches) We
  18. # currently assume that all meaningful version boundaries are marked by a tag.
  19. # We don't care what the tag is, just that something exists.
  20. # Git/Cogito store the top-of-tree "commit" in .git/HEAD
  21. # A list of known tags sits in .git/refs/tags/
  22. #
  23. # The simple trick here is to just compare the two of these, and if we get a
  24. # match, return nothing, otherwise, return a subset of the SHA-1 hash in
  25. # .git/HEAD
  26. sub do_git_checks {
  27. open(H,"<.git/HEAD") or return;
  28. my $head = <H>;
  29. chomp $head;
  30. close(H);
  31. opendir(D,".git/refs/tags") or return;
  32. foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) {
  33. open(F,"<.git/refs/tags/" . $tagfile) or return;
  34. my $tag = <F>;
  35. chomp $tag;
  36. close(F);
  37. return if ($tag eq $head);
  38. }
  39. closedir(D);
  40. push @LOCALVERSIONS, "g" . substr($head,0,8);
  41. }
  42. if ( -d ".git") {
  43. do_git_checks();
  44. }
  45. printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);