From b9e3a9b74cb78302b19652b44114f2e491dd24f2 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 11 Apr 2012 23:12:21 +0100 Subject: [PATCH] Git: add pre-commit and post-rewrite hooks for versioning * Also adds the maintainer-only .private directory --- .private/README.txt | 5 +++++ .private/post-rewrite.sh | 28 +++++++++++++++++++++++++++ .private/pre-commit.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ libusb/version.h | 3 +-- 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 .private/README.txt create mode 100755 .private/post-rewrite.sh create mode 100755 .private/pre-commit.sh diff --git a/.private/README.txt b/.private/README.txt new file mode 100644 index 0000000..579f25a --- /dev/null +++ b/.private/README.txt @@ -0,0 +1,5 @@ +This directory contains private internal scripts used by the libusbx +project project maintainers. + +These scripts are not intended for general usage and will not be +exported when producing release archives. \ No newline at end of file diff --git a/.private/post-rewrite.sh b/.private/post-rewrite.sh new file mode 100755 index 0000000..b5fff07 --- /dev/null +++ b/.private/post-rewrite.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Detect amended commits and warn user if .amend is missing +# +# To have git run this script on commit, create a "post-rewrite" text file in +# .git/hooks/ with the following content: +# #!/bin/sh +# if [ -x .private/post-rewrite.sh ]; then +# source .private/post-rewrite.sh +# fi +# +# NOTE: These versioning hooks are intended to be used *INTERNALLY* by the +# libusbx development team and are NOT intended to solve versioning for any +# derivative branch, such as one you would create for private development. +# + +case "$1" in + amend) + # Check if a .amend exists. If none, create one and warn user to re-commit. + if [ -f .amend ]; then + rm .amend + else + echo "Amend commit detected, but no .amend file - One has now been created." + echo "Please re-commit as is (amend), so that the version number is correct." + touch .amend + fi ;; + *) ;; +esac diff --git a/.private/pre-commit.sh b/.private/pre-commit.sh new file mode 100755 index 0000000..c62fb35 --- /dev/null +++ b/.private/pre-commit.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Sets the nano version according to the number of commits on this branch, as +# well as the branch offset. +# +# To have git run this script on commit, first make sure you change +# BRANCH_OFFSET to 60000 or higher, then create a "pre-commit" text file in +# .git/hooks/ with the following content: +# #!/bin/sh +# if [ -x .private/pre-commit.sh ]; then +# source .private/pre-commit.sh +# fi +# +# NOTE: These versioning hooks are intended to be used *INTERNALLY* by the +# libusbx development team and are NOT intended to solve versioning for any +# derivative branch, such as one you would create for private development. +# +# Should you wish to reuse these scripts for your own versioning, in your own +# private branch, we kindly ask you to first set BRANCH_OFFSET to 60000, or +# higher, as any offset below below 60000 is *RESERVED* for libusbx official +# usage. + +################################################################################ +## YOU *MUST* SET THE FOLLOWING TO 60000 OR HIGHER IF YOU REUSE THIS SCRIPT ## +################################################################################ +BRANCH_OFFSET=10000 +################################################################################ + +type -P sed &>/dev/null || { echo "sed command not found. Aborting." >&2; exit 1; } +type -P git &>/dev/null || { echo "git command not found. Aborting." >&2; exit 1; } + +# The -b option of sed, which we use to prevent CRLF conversions on Windows +# was only introduced recently, and Linux distros may not have it +SED_CMD='sed -b' +$SED_CMD --version > /dev/null 2>&1 || SED_CMD='sed' + +NANO=`git log --oneline | wc -l` +NANO=`expr $NANO + $BRANCH_OFFSET` +# Amended commits need to have the nano corrected. Current versions of git hooks +# only allow detection of amending post commit, so we require a .amend file, +# which will be created post commit with a user warning if none exists when an +# amend is detected. +if [ -f .amend ]; then + NANO=`expr $NANO - 1` +fi +echo "setting nano to $NANO" +# -i option of sed is useless on Windows. +$SED_CMD -e "s/^#define LIBUSB_NANO.*/#define LIBUSB_NANO $NANO/" libusb/version.h > libusb/version.h~ +mv libusb/version.h~ libusb/version.h +git add libusb/version.h diff --git a/libusb/version.h b/libusb/version.h index 62446da..2549bde 100644 --- a/libusb/version.h +++ b/libusb/version.h @@ -8,9 +8,8 @@ #ifndef LIBUSB_MICRO #define LIBUSB_MICRO 9 #endif -/* LIBUSB_NANO may be used for Windows internal versioning. 0 means unused. */ #ifndef LIBUSB_NANO -#define LIBUSB_NANO 0 +#define LIBUSB_NANO 10470 #endif /* LIBUSB_RC is the release candidate suffix. Should normally be empty. */ #ifndef LIBUSB_RC -- 2.11.4.GIT