1#!/bin/sh 2# 3# This scripts adds local version information from the version 4# control systems git and mercurial (hg). 5# 6# If something goes wrong, send a mail the kernel build mailinglist 7# (see MAINTAINERS) and CC Nico Schottelius 8# <nico-linuxsetlocalversion -at- schottelius.org>. 9# 10# Based on setlocalversion from Linux kernel 11# 12# 13 14usage() { 15 echo "Usage: $0 [--save-scmversion] [srctree]" >&2 16 exit 1 17} 18 19save_scm=false 20srctree=. 21if test "$1" = "--save-scmversion"; then 22 save_scm=true 23 shift 24fi 25if test $# -gt 0; then 26 srctree=$1 27 shift 28fi 29if test $# -gt 0 -o ! -d "$srctree"; then 30 usage 31fi 32 33scm_version() 34{ 35 if test -e .scmversion; then 36 cat .scmversion 37 return 38 fi 39 40 # Check for git and a git repo. 41 if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then 42 date=`git show -s --pretty="%ad" HEAD` 43 44 printf '%s %s%s' "$date" git: $head 45 46 # Is this git on svn? 47 if git config --get svn-remote.svn.url >/dev/null; then 48 printf -- 'svn:%s' "`git svn find-rev $head`" 49 fi 50 51 # Update index only on r/w media 52 [ -w . ] && git update-index --refresh --unmerged > /dev/null 53 54 # Check for uncommitted changes 55 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then 56 printf '%s' -dirty 57 fi 58 59 # All done with git 60 return 61 fi 62 63 # Check for mercurial and a mercurial repo. 64 if test -d .hg && hgid=`hg id 2>/dev/null`; then 65 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` 66 date=`hg parents --template "{date|date}"` 67 printf '%s %s%s' "$date" hg: "$id" 68 69 # Are there uncommitted changes? 70 # These are represented by + after the changeset id. 71 case "$hgid" in 72 *+|*+\ *) printf '%s' -dirty ;; 73 esac 74 75 # All done with mercurial 76 return 77 fi 78} 79 80cd $srctree 81 82# full scm version string 83res="$(scm_version)" 84 85if [ "$save_scm" = "true" ]; then 86 echo $res > .scmversion 87fi 88 89echo "$res" 90