Commit 231b5953 authored by Ryan Jackson's avatar Ryan Jackson

Add script to find current HEAD for build

Add script that, when run from the root of the repository, returns the
sha1 hash of the current branch head.  It writes the hash to stdout if
successful or returning non-zero otherwise.  The three methods used to
get the hash are as follows:

1. Try using the git tools.  This is the preferred method since the
   layout of the .git directory may change (not likely to happen soon,
   but it did change a few years ago).
2. Failing that, assume the current (1.7.x) repository layout and try
   to extract the value of HEAD.
3. If there is no .git directory, try extracting the hash from the
   VERSION file in the top-level directory of the tree.

Also add the VERSION file and set the export-subst attribute for it.
parent 32d4f3ab
VERSION export-subst
# Files that already had DOS-style line endings and those # Files that already had DOS-style line endings and those
# that require them should be added to the list below. # that require them should be added to the list below.
delay/linux/iptables_mods/iptables-1.3.6-imq.diff -crlf delay/linux/iptables_mods/iptables-1.3.6-imq.diff -crlf
Version: $Format:%H %ci$
#! /bin/sh
# Use git tools to get the head of the current branch
# if they're available
head=`git rev-parse HEAD 2>/dev/null`
if [ -z "$head" ]; then
if [ -f .git/HEAD ]; then
echo "Extracting HEAD with git tools failed" 1>&2
echo "Trying to parse metadata manually" 1>&2
# Hmm, no git tools or they failed. Try
# extracting the rev by hand.
# .git/HEAD can contain either a symbolic ref or a
# sha1 hash (if on a detached head), so we need to
# handle both cases.
head=`cat .git/HEAD`
case $head in ref:*)
# The ref can be unpacked or packed, so we need
# to check both places.
ref=${head#ref: }
if [ -f .git/$ref ]; then
head=`cat .git/$ref`
elif [ -f .git/packed-refs ]; then
head=`sed -n 's#^\([a-f0-9]*\) '$ref'$#\1#p' \
echo "Symbolic ref \"$ref\" not found" 1>&2
exit 1
elif [ -f $version_file ]; then
# This is only used for exported tarballs
head=`sed -n 's#^Version: $Format:\([a-f0-9]*\) .*\$.*$#\1#p' \
exit 1
# Sanity check of head; should look like SHA1 hash
if ! echo $head | grep -E '^[a-f0-9]{40}$' > /dev/null 2>&1; then
echo "Head \"$head\" does not look like a SHA1 hash" 1>&2
exit 1
echo $head
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment