git-gui: Ensure version number is always current.
I'm stealing the exact logic used by core Git within its own Makefile to setup the version number within scripts and executables. This way we can be sure that the version number is always updated after a commit, and that the version number also reflects when it is coming from a dirty working directory (and is thus pretty worthless). I've cleaned up some of the version display code in the about dialog too. There were simply too many blank lines in the bottom section where we showed the version data. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jan 20, 2007 at 20:31 UTC
f1cee4e6d19919f6e333f9e671c720003a9a7cec
4 files changed
+63
-6
.gitignore
+1
@@ -1,2 +1,3 @@
1
+GIT-VERSION-FILE
2
git-citool
3
git-gui
GIT-VERSION-GEN
new
+46
@@ -0,0 +1,46 @@
1
+#!/bin/sh
2
+
3
+GVF=GIT-VERSION-FILE
4
+DEF_VER=v0.5.GIT
5
+
6
+LF='
7
+'
8
+
9
+# First try git-describe, then see if there is a version file
10
+# (included in release tarballs), then default
11
+if VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
12
+ case "$VN" in
13
+ *$LF*) (exit 1) ;;
14
+ v[0-9]*) : happy ;;
15
+ esac
16
+then
17
+ VN=$(echo "$VN" | sed -e 's/-/./g');
18
+elif test -f version
19
+then
20
+ VN=$(cat version) || VN="$DEF_VER"
21
+else
22
+ VN="$DEF_VER"
23
+fi
24
+
25
+VN=$(expr "$VN" : v*'\(.*\)')
26
+
27
+dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
28
+case "$dirty" in
29
+'')
30
+ ;;
31
+*)
32
+ VN="$VN-dirty" ;;
33
+esac
34
+
35
+if test -r $GVF
36
+then
37
+ VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
38
+else
39
+ VC=unset
40
+fi
41
+test "$VN" = "$VC" || {
42
+ echo >&2 "GIT_VERSION = $VN"
43
+ echo "GIT_VERSION = $VN" >$GVF
44
+}
45
+
46
+
Makefile
+12
-3
@@ -1,9 +1,12 @@
1
all::
2
3
+GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
4
+ @$(SHELL_PATH) ./GIT-VERSION-GEN
5
+-include GIT-VERSION-FILE
6
+
7
SCRIPT_SH = git-gui.sh
8
GITGUI_BUILT_INS = git-citool
9
ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
6
-GITGUI_VERSION := $(shell git describe)
10
11
ifndef SHELL_PATH
12
SHELL_PATH = /bin/sh
@@ -20,7 +23,7 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
23
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
24
rm -f $@ $@+
25
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
23
- -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
26
+ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
27
$@.sh >$@+
28
chmod +x $@+
29
mv $@+ $@
@@ -28,6 +31,9 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
31
$(GITGUI_BUILT_INS): git-gui
32
rm -f $@ && ln git-gui $@
33
34
+# These can record GIT_VERSION
35
+$(patsubst %.sh,%,$(SCRIPT_SH)): GIT-VERSION-FILE
36
+
37
all:: $(ALL_PROGRAMS)
38
39
install: all
@@ -36,4 +42,7 @@ install: all
42
$(foreach p,$(GITGUI_BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
43
44
clean::
39
- rm -f $(ALL_PROGRAMS)
45
+ rm -f $(ALL_PROGRAMS) GIT-VERSION-FILE
46
+
47
+.PHONY: all install clean
48
+.PHONY: .FORCE-GIT-VERSION-FILE
git-gui.sh
+4
-3
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
21
22
-set appvers {@@GITGUI_VERSION@@}
22
+set appvers {@@GIT_VERSION@@}
23
set appname [lindex [file split $argv0] end]
24
set gitdir {}
25
@@ -2543,8 +2543,9 @@ $copyright" \
2543
pack $w.desc -side top -fill x -padx 5 -pady 5
2544
2545
set v {}
2546
- append v "$appname version $appvers\n\n"
2547
- append v "[exec git --version]\n\n"
2546
+ append v "$appname version $appvers\n"
2547
+ append v "[exec git version]\n"
2548
+ append v "\n"
2549
if {$tcl_patchLevel eq $tk_patchLevel} {
2550
append v "Tcl/Tk version $tcl_patchLevel"
2551
} else {