X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=scripts%2Fsetlocalversion;h=46989b88d7345d233ce5d734e2ed9845784df4d0;hb=8de016e2bd8ebce9b3728462085bef51179841a6;hp=7c805c8fccd26b7a839079ba9e5268046cb392e9;hpb=aaebf4332018980fef4e601d1b5a6e52dd9e9ae4;p=safe%2Fjmp%2Flinux-2.6 diff --git a/scripts/setlocalversion b/scripts/setlocalversion old mode 100644 new mode 100755 index 7c805c8..46989b8 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -1,56 +1,82 @@ -#!/usr/bin/perl -# Copyright 2004 - Ryan Anderson GPL v2 - -use strict; -use warnings; -use Digest::MD5; -require 5.006; - -if (@ARGV != 1) { - print < -EOT - exit(1); +#!/bin/sh +# +# This scripts adds local version information from the version +# control systems git, mercurial (hg) and subversion (svn). +# +# If something goes wrong, send a mail the kernel build mailinglist +# (see MAINTAINERS) and CC Nico Schottelius +# . +# +# + +usage() { + echo "Usage: $0 [srctree]" >&2 + exit 1 } -my ($srctree) = @ARGV; -chdir($srctree); +cd "${1:-.}" || usage -my @LOCALVERSIONS = (); +# Check for git and a git repo. +if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then -# We are going to use the following commands to try and determine if this -# repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches) We -# currently assume that all meaningful version boundaries are marked by a tag. -# We don't care what the tag is, just that something exists. + # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it, + # because this version is defined in the top level Makefile. + if [ -z "`git describe --exact-match 2>/dev/null`" ]; then -# Git/Cogito store the top-of-tree "commit" in .git/HEAD -# A list of known tags sits in .git/refs/tags/ -# -# The simple trick here is to just compare the two of these, and if we get a -# match, return nothing, otherwise, return a subset of the SHA-1 hash in -# .git/HEAD - -sub do_git_checks { - open(H,"<.git/HEAD") or return; - my $head = ; - chomp $head; - close(H); - - opendir(D,".git/refs/tags") or return; - foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) { - open(F,"<.git/refs/tags/" . $tagfile) or return; - my $tag = ; - chomp $tag; - close(F); - return if ($tag eq $head); - } - closedir(D); - - push @LOCALVERSIONS, "g" . substr($head,0,8); -} + # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"), + # we pretty print it. + if atag="`git describe 2>/dev/null`"; then + echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' -if ( -d ".git") { - do_git_checks(); -} + # If we don't have a tag at all we print -g{commitish}. + else + printf '%s%s' -g $head + fi + fi + + # Is this git on svn? + if git config --get svn-remote.svn.url >/dev/null; then + printf -- '-svn%s' "`git svn find-rev $head`" + fi + + # Update index only on r/w media + [ -w . ] && git update-index --refresh --unmerged > /dev/null + + # Check for uncommitted changes + if git diff-index --name-only HEAD | grep -v "^scripts/package" \ + | read dummy; then + printf '%s' -dirty + fi + + # All done with git + exit +fi + +# Check for mercurial and a mercurial repo. +if hgid=`hg id 2>/dev/null`; then + tag=`printf '%s' "$hgid" | cut -d' ' -f2` + + # Do we have an untagged version? + if [ -z "$tag" -o "$tag" = tip ]; then + id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` + printf '%s%s' -hg "$id" + fi + + # Are there uncommitted changes? + # These are represented by + after the changeset id. + case "$hgid" in + *+|*+\ *) printf '%s' -dirty ;; + esac + + # All done with mercurial + exit +fi + +# Check for svn and a svn repo. +if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then + rev=`echo $rev | awk '{print $NF}'` + printf -- '-svn%s' "$rev" -printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0); + # All done with svn + exit +fi