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