git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: jeffpc@josefsipek.net
Cc: git@vger.kernel.org
Subject: [PATCH] guilt: add git commit level versioning
Date: Tue,  7 Oct 2008 22:08:42 -0400	[thread overview]
Message-ID: <1223431722-12259-1-git-send-email-paul.gortmaker@windriver.com> (raw)

Shamelessly steal the dynamic versioning goodies from git
itself.  Now when you do "guilt --version" you can expect to
see things like:

	Guilt version 0.31.2.14.gece1.dirty

assuming you've 14 commits since 0.31.2 and also some changes
that you've not committed yet.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 .gitignore             |    2 ++
 Documentation/Makefile |    4 ++--
 GUILT-VERSION-GEN      |   42 ++++++++++++++++++++++++++++++++++++++++++
 Makefile               |   21 ++++++++++++++++-----
 guilt                  |    4 +++-
 5 files changed, 65 insertions(+), 8 deletions(-)
 create mode 100755 GUILT-VERSION-GEN

diff --git a/.gitignore b/.gitignore
index c81112b..61161ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@
 #
 *~
 *.swp
+guilt.bin
+GUILT-VERSION-FILE
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 9fc1165..4b7d037 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -7,7 +7,7 @@ DOC_MAN1=$(patsubst %.txt,%.1,$(MAN1_TXT))
 DOC_MAN7=$(patsubst %.txt,%.7,$(MAN7_TXT))
 
 USAGE=$(patsubst %.txt,usage-%.txt,$(MAN1_TXT))
-VERSION=$(shell git describe 2> /dev/null || sed -n -e '/^GUILT_VERSION=/ { s/^GUILT_VERSION="/v/; s/"//; p; q; }' ../guilt)
+include ../GUILT-VERSION-FILE
 
 prefix?=$(PREFIX)
 bindir?=$(prefix)/bin
@@ -51,7 +51,7 @@ doc.dep : $(wildcard *.txt) build-docdep.perl
 -include doc.dep
 
 version.txt:
-	echo "(Generated for Guilt $(VERSION))" > version.txt
+	echo "(Generated for Guilt $(GUILT_VERSION))" > version.txt
 
 cmds.txt: cmd-list.sh $(MAN1_TXT)
 	sh ./cmd-list.sh
diff --git a/GUILT-VERSION-GEN b/GUILT-VERSION-GEN
new file mode 100755
index 0000000..66b40e2
--- /dev/null
+++ b/GUILT-VERSION-GEN
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+GVF=GUILT-VERSION-FILE
+DEF_VER=v0.31.2
+
+LF='
+'
+
+# First see if there is a version file (included in release tarballs),
+# then try git-describe, then default.
+if test -f version
+then
+	VN=$(cat version) || VN="$DEF_VER"
+elif test -d .git -o -f .git &&
+	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+	case "$VN" in
+	*$LF*) (exit 1) ;;
+	v[0-9]*)
+		git update-index -q --refresh
+		test -z "$(git diff-index --name-only HEAD --)" ||
+		VN="$VN-dirty" ;;
+	esac
+then
+	VN=$(echo "$VN" | sed -e 's/-/./g');
+else
+	VN="$DEF_VER"
+fi
+
+VN=$(expr "$VN" : v*'\(.*\)')
+
+if test -r $GVF
+then
+	VC=$(sed -e 's/^GUILT_VERSION = //' <$GVF)
+else
+	VC=unset
+fi
+test "$VN" = "$VC" || {
+	echo >&2 "GUILT_VERSION=$VN"
+	echo "GUILT_VERSION=$VN" >$GVF
+}
+
+
diff --git a/Makefile b/Makefile
index af53fb5..f3cf0b3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,25 +1,35 @@
 PREFIX=/usr/local
 DESTDIR=
 
-SCRIPTS = guilt \
-	  $(filter-out $(wildcard *~),$(wildcard guilt-*))
+SCRIPTS = $(filter-out $(wildcard *~),$(wildcard guilt-*))
 
-.PHONY: all 
-all: doc
+all::
+
+.PHONY: .FORCE-GUILT-VERSION-FILE
+GUILT-VERSION-FILE: .FORCE-GUILT-VERSION-FILE
+	@$(SHELL_PATH) ./GUILT-VERSION-GEN
+-include GUILT-VERSION-FILE
+
+.PHONY: all
+all:: doc guilt.bin
 	@echo "Nothing to build, it is all bash :)"
 	@echo "Try make install"
 
+guilt.bin: GUILT-VERSION-FILE
+	@sed 's/^GUILT_VERSION=$$/GUILT_VERSION="$(GUILT_VERSION)"/' < guilt > guilt.bin
+
 .PHONY: install
 install:
 	install -d $(DESTDIR)$(PREFIX)/bin/
 	install -m 755 $(SCRIPTS) $(DESTDIR)$(PREFIX)/bin/
+	install -m 755 guilt.bin $(DESTDIR)$(PREFIX)/bin/guilt
 
 .PHONY: uninstall
 uninstall:
 	./uninstall $(DESTDIR)$(PREFIX)/bin/ $(SCRIPTS)
 
 .PHONY: doc
-doc:
+doc: GUILT-VERSION-FILE
 	$(MAKE) -C Documentation all
 
 .PHONY: install-doc
@@ -33,3 +43,4 @@ test:
 .PHONY: clean
 clean: 
 	$(MAKE) -C Documentation clean 
+	$(RM) GUILT-VERSION-FILE guilt.bin
diff --git a/guilt b/guilt
index fabee17..7cfa23b 100755
--- a/guilt
+++ b/guilt
@@ -3,7 +3,9 @@
 # Copyright (c) Josef "Jeff" Sipek, 2006-2008
 #
 
-GUILT_VERSION="0.31.2"
+# Version replaced at build time. Could have in separate file, but why
+# do a "source version_file" on every guilt operation?
+GUILT_VERSION=
 GUILT_NAME="Ciuleandra"
 
 # If the first argument is one of the below, display the man page instead of
-- 
1.6.0

             reply	other threads:[~2008-10-08  2:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-08  2:08 Paul Gortmaker [this message]
2008-10-09 15:54 ` [PATCH] guilt: add git commit level versioning Josef 'Jeff' Sipek
2008-10-09 16:13   ` Paul Gortmaker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223431722-12259-1-git-send-email-paul.gortmaker@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=git@vger.kernel.org \
    --cc=jeffpc@josefsipek.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).