From 9ad625cefc18f136e2f80cb241a8efc255946a33 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Sat, 18 Jun 2016 11:50:09 +0200 Subject: [PATCH 1/3] Simplify finding of fallback version number --- vimcat | 24 ++---------------------- vimpager | 28 ++-------------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/vimcat b/vimcat index 3d75d75..8be9c72 100755 --- a/vimcat +++ b/vimcat @@ -1,8 +1,6 @@ #!/bin/sh #!/usr/bin/env vim #! -#! vimcat 2.06 -#! #! This is a bash script that executes itself as a vimscript to do its work #! Based on _v by Magnus Woldrich: https://github.com/trapd00r/utils/blob/master/_v @@ -23,7 +21,8 @@ . "$project_dir""/inc/prologue.sh" - version="$(cd "$project_dir"; git describe 2>/dev/null) (git)" + fallback_version='2.06 (fallback)' + if ! version="$(cd "$project_dir" && git describe 2>/dev/null) (git)"; then version=$fallback_version; fi if command -v vim >/dev/null; then vim=vim @@ -34,25 +33,6 @@ exit 1 fi - # Check if version was set correctly from git - case "$version" in - [0-9].*) - ;; - *) - # use the version from the comment at the top of the file instead - i=4 - while true; do - if [ $i -eq 1 ]; then - read _hash _progname version - break - else - read _line - fi - i=$((i-1)) - done < "$0" - ;; - esac - quit() { ( kill "$vim_pid" >/dev/null 2>&1 diff --git a/vimpager b/vimpager index 5991eac..61e3a74 100755 --- a/vimpager +++ b/vimpager @@ -1,7 +1,5 @@ #!/bin/sh # -# vimpager 2.06 -# # Script for using ViM as a PAGER. # Based on Bram's less.sh. # git://github.com/rkitover/vimpager.git @@ -29,7 +27,8 @@ project_dir=`dirname "$link"` . "$project_dir/inc/prologue.sh" -version="$(cd "$project_dir"; git describe 2>/dev/null) (git)" +fallback_version='2.06 (fallback)' +if ! version="$(cd "$project_dir" && git describe 2>/dev/null) (git)"; then version=$fallback_version; fi runtime='$project_dir' vimcat='$project_dir/vimcat' system_vimpagerrc='$project_dir/vimpagerrc' @@ -61,8 +60,6 @@ main() { extra_cmd= line_numbers=0 - check_version - # Check for certain parameters to pass on to vim (or conceivably do something else) # Couldn't use getopt or getopts as neither supports options prepended with + while [ $# -gt 0 ] ; do @@ -937,27 +934,6 @@ fits_on_screen() { ' num_files=$# total_lines=$lines total_cols=$cols file_sep_lines=3 first_file_sep_lines=2 - } -check_version() { - # Check if version was set correctly from git - case "$version" in - [0-9].*) - ;; - *) - # use the version from the comment at the top of the file instead - i=3 - while true; do - if [ $i -eq 1 ]; then - read _hash _progname version - break - else - read _line - fi - i=$((i-1)) - done < "$0" - ;; - esac -} - # INCLUDE BUNDLED SCRIPTS HERE # END OF BUNDLED SCRIPTS From 7ef32e7213d46ef1fe80a7e92a906e3c5dd9a9e5 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Mon, 20 Jun 2016 04:14:17 -0400 Subject: [PATCH 2/3] ver tag var at top of progs/buid from src tarball Set the latest version tag as version_tag=XXX at the top of vimpager and vimcat. If version assignment fails due to not having .git or a shallow clone, use the version_tag var with the postfix '(checkout)'. On make for the all recipe, update the version_tag var from either git or the ChangeLog files. For make recipes that used `git describe`, write out a XXX-version.txt file instead with the output of `git describe`, or the latest tag from ChangeLog if `git describe` has failed. This allows building from a source tarball (rather than only a git clone.) --- Makefile | 34 ++++++++++++++++++++++++++-------- vimcat | 7 ++++--- vimpager | 6 ++++-- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b4f8aef..10ab0fa 100644 --- a/Makefile +++ b/Makefile @@ -20,14 +20,32 @@ RUNTIME=autoload/vimpager.vim autoload/vimpager_utils.vim plugin/vimpager.vim ma SRC=vimcat ${RUNTIME} -all: balance-shellvim-stamp standalone/vimpager standalone/vimcat docs +PROGRAMS=vimpager vimcat + +all: ${PROGRAMS:=-vertag-stamp} balance-shellvim-stamp standalone/vimpager standalone/vimcat docs + +# set tag from git or ChangeLog +%-vertag-stamp: % + @tag=`git tag 2>/dev/null | tail -1`; \ + [ -z "$$tag" ] && tag=`grep '^[0-9][0-9.]* [0-9-]*:$$' ChangeLog_${<}.yml | head -1 | awk '{ print $$1 }'`; \ + if [ -n "$$tag" ]; then \ + sed -e 's/^\( *version_tag=\).*/\1'"$$tag"'/' $< > ${<}.work; \ + mv ${<}.work $<; \ + fi + @chmod +x $< + @touch $@ + +# other recipes need the version, get it from git describe or ChangeLog +%-version.txt: % + @git describe >${<}-version.txt 2>/dev/null \ + || grep '^[0-9][0-9.]* [0-9-]*:$$' ChangeLog_${<}.yml | head -1 | awk '{ print $$1 }' >${<}-version.txt balance-shellvim-stamp: vimcat Makefile @chmod +x scripts/balance-shellvim @scripts/balance-shellvim @touch balance-shellvim-stamp -standalone/%: % ${SRC:=.uu} inc/* Makefile +standalone/%: % ${SRC:=.uu} inc/* Makefile %-version.txt @echo building $@ @${MKPATH} `dirname $@` @base="`basename $@`"; \ @@ -47,7 +65,7 @@ standalone/%: % ${SRC:=.uu} inc/* Makefile sed -n '/^# END OF BUNDLED SCRIPTS$$/,$$p' "$$base" >> $@; \ fi @cp $@ $@.work - @sed -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"|' \ + @sed -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat ${<}-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ -e '/^ *\. .*inc\/prologue.sh"$$/{' \ -e 'r inc/prologue.sh' \ -e d \ @@ -59,12 +77,12 @@ standalone/%: % ${SRC:=.uu} inc/* Makefile fi @chmod +x $@ -vimcat.uu: vimcat +vimcat.uu: vimcat vimcat-version.txt @echo uuencoding $< @echo 'vimcat_script() {' > $@ @printf "\t(cat <<'EOF') | do_uudecode > bin/vimcat\n" >> $@ @sed \ - -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (bundled, shell=\$$(command -v \$$POSIX_SHELL))"|' \ + -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat vimcat-version.txt`"' (bundled, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ -e '/^ *\. .*inc\/prologue.sh"$$/{' \ -e 'r inc/prologue.sh' \ -e d \ @@ -143,7 +161,7 @@ install: docs vimpager.configured vimcat.configured echo ${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc"; \ ${INSTALLCONF} vimpagerrc "$${SYSCONFDIR}/vimpagerrc" -%.configured: % +%.configured: % %-version.txt @echo configuring $< @POSIX_SHELL="`scripts/find_shell`"; \ if [ '${PREFIX}' = /usr ]; then \ @@ -154,7 +172,7 @@ install: docs vimpager.configured vimcat.configured sed -e '1{ s|.*|#!'"$$POSIX_SHELL"'|; }' \ -e 's|\$$POSIX_SHELL|'"$$POSIX_SHELL|" \ -e '/^ *\. .*inc\/prologue.sh"$$/d' \ - -e 's|^\( *\)version=.*|\1version="'"`git describe`"' (configured, shell='"$$POSIX_SHELL"')"|' \ + -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat ${<}-version.txt`"' (configured, shell='"$$POSIX_SHELL"')"\2|' \ -e '/^# FIND REAL PARENT DIRECTORY$$/,/^# END OF FIND REAL PARENT DIRECTORY$$/d' \ -e 's!^\( *\)runtime=.*!\1runtime='\''${PREFIX}/share/vimpager'\''!' \ -e 's!^\( *\)vimcat=.*!\1vimcat='\''${PREFIX}/bin/vimcat'\''!' \ @@ -247,6 +265,6 @@ html/%.html: %.md.work fi realclean distclean clean: - rm -rf *.work */*.work *-stamp *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* + rm -rf *.work */*.work *-stamp *-version.txt *.deb *.tar.gz *.configured *.uu */*.uu man html standalone */with_meta_* .PHONY: all install install-deb uninstall docs realclean distclean clean diff --git a/vimcat b/vimcat index 8be9c72..123eb24 100755 --- a/vimcat +++ b/vimcat @@ -5,6 +5,8 @@ #! Based on _v by Magnus Woldrich: https://github.com/trapd00r/utils/blob/master/_v : if 0 + version_tag=2.06 + link=$0 while [ -h "$link" ]; do @@ -21,8 +23,8 @@ . "$project_dir""/inc/prologue.sh" - fallback_version='2.06 (fallback)' - if ! version="$(cd "$project_dir" && git describe 2>/dev/null) (git)"; then version=$fallback_version; fi + version="$(cd "$project_dir" && git describe 2>/dev/null) (git)" \ + || version="$version_tag (checkout)" if command -v vim >/dev/null; then vim=vim @@ -356,7 +358,6 @@ squeeze_blank_lines() { : endif : endif : endif -: endwhile : endif : endif : endwhile diff --git a/vimpager b/vimpager index 61e3a74..4dccb25 100755 --- a/vimpager +++ b/vimpager @@ -4,6 +4,8 @@ # Based on Bram's less.sh. # git://github.com/rkitover/vimpager.git +version_tag=2.06 + # Just pass through if not on a tty if [ ! -t 1 ]; then exec cat "$@" @@ -27,8 +29,8 @@ project_dir=`dirname "$link"` . "$project_dir/inc/prologue.sh" -fallback_version='2.06 (fallback)' -if ! version="$(cd "$project_dir" && git describe 2>/dev/null) (git)"; then version=$fallback_version; fi +version="$(cd "$project_dir" && git describe 2>/dev/null) (git)" \ + || version="$version_tag (checkout)" runtime='$project_dir' vimcat='$project_dir/vimcat' system_vimpagerrc='$project_dir/vimpagerrc' From f55176cc68561e34e4eefb5f277c5ec13a7b4a56 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 20 Jun 2016 11:43:51 +0200 Subject: [PATCH 3/3] Simplify makefile rules for version info --- Makefile | 17 ++++++++++------- vimcat | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 10ab0fa..f912452 100644 --- a/Makefile +++ b/Makefile @@ -26,21 +26,24 @@ all: ${PROGRAMS:=-vertag-stamp} balance-shellvim-stamp standalone/vimpager stand # set tag from git or ChangeLog %-vertag-stamp: % + @echo updating version tag in $< @tag=`git tag 2>/dev/null | tail -1`; \ - [ -z "$$tag" ] && tag=`grep '^[0-9][0-9.]* [0-9-]*:$$' ChangeLog_${<}.yml | head -1 | awk '{ print $$1 }'`; \ + [ -z "$$tag" ] && tag=`sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml`; \ if [ -n "$$tag" ]; then \ - sed -e 's/^\( *version_tag=\).*/\1'"$$tag"'/' $< > ${<}.work; \ - mv ${<}.work $<; \ + sed -e 's/^\( *version_tag=\).*/\1'"$$tag"'/' $< > $<.work; \ + mv $<.work $<; \ fi @chmod +x $< @touch $@ # other recipes need the version, get it from git describe or ChangeLog %-version.txt: % - @git describe >${<}-version.txt 2>/dev/null \ - || grep '^[0-9][0-9.]* [0-9-]*:$$' ChangeLog_${<}.yml | head -1 | awk '{ print $$1 }' >${<}-version.txt + @echo building $@ + @git describe >$<-version.txt 2>/dev/null \ + || sed -n '/^[0-9][0-9.]* [0-9-]*:$$/{s/ .*//;p;q;}' ChangeLog_$<.yml >$<-version.txt balance-shellvim-stamp: vimcat Makefile + @echo balanceing vimcat @chmod +x scripts/balance-shellvim @scripts/balance-shellvim @touch balance-shellvim-stamp @@ -65,7 +68,7 @@ standalone/%: % ${SRC:=.uu} inc/* Makefile %-version.txt sed -n '/^# END OF BUNDLED SCRIPTS$$/,$$p' "$$base" >> $@; \ fi @cp $@ $@.work - @sed -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat ${<}-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ + @sed -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat $<-version.txt`"' (standalone, shell=\$$(command -v \$$POSIX_SHELL))"\2|' \ -e '/^ *\. .*inc\/prologue.sh"$$/{' \ -e 'r inc/prologue.sh' \ -e d \ @@ -172,7 +175,7 @@ install: docs vimpager.configured vimcat.configured sed -e '1{ s|.*|#!'"$$POSIX_SHELL"'|; }' \ -e 's|\$$POSIX_SHELL|'"$$POSIX_SHELL|" \ -e '/^ *\. .*inc\/prologue.sh"$$/d' \ - -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat ${<}-version.txt`"' (configured, shell='"$$POSIX_SHELL"')"\2|' \ + -e 's|^\( *\)version=.* (git)"\( *\\*\)$$|\1version="'"`cat $<-version.txt`"' (configured, shell='"$$POSIX_SHELL"')"\2|' \ -e '/^# FIND REAL PARENT DIRECTORY$$/,/^# END OF FIND REAL PARENT DIRECTORY$$/d' \ -e 's!^\( *\)runtime=.*!\1runtime='\''${PREFIX}/share/vimpager'\''!' \ -e 's!^\( *\)vimcat=.*!\1vimcat='\''${PREFIX}/bin/vimcat'\''!' \ diff --git a/vimcat b/vimcat index 123eb24..de4937a 100755 --- a/vimcat +++ b/vimcat @@ -359,7 +359,6 @@ squeeze_blank_lines() { : endif : endif : endif -: endif : endwhile : endif