<div dir="ltr">Overall this is great! I definitely think it's easier to read, test, and maintain than the Makefile approach. But I suppose we'll find out how others feel...<br><div class="gmail_extra"><br><div class="gmail_quote">
On Tue, Aug 6, 2013 at 6:51 PM, Stefan Tauner <span dir="ltr"><<a href="mailto:stefan.tauner@student.tuwien.ac.at" target="_blank">stefan.tauner@student.tuwien.ac.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
- remove bashism<br>
- simplify some git-related code<br>
- there is only one sane time format.<br>
- vastly improve git_url() to print the correct remote url and<br>
"nearest" branch<br>
- add "-dirty" to local revisions if there are uncommitted changes<br>
- indicate in local revisions how many git-only commits were done<br>
since branching from upstream svn<br>
- fix svn_revision() fallback to svn info and remove git-svn<br>
- print leading r in script instead of hardcode it in the makefile;<br>
no more "0.9.7-runknown"<br>
<br>
Signed-off-by: Stefan Tauner <<a href="mailto:stefan.tauner@student.tuwien.ac.at">stefan.tauner@student.tuwien.ac.at</a>><br>
---<br>
Makefile | 2 +-<br>
util/getrevision.sh | 156 +++++++++++++++++++++++++++++-----------------------<br>
2 files changed, 89 insertions(+), 69 deletions(-)<br>
<br>
diff --git a/Makefile b/Makefile<br>
index da0d0da..e1a4474 100644<br>
--- a/Makefile<br>
+++ b/Makefile<br>
@@ -329,7 +329,7 @@ CLI_OBJS = cli_classic.o cli_output.o print.o<br>
SVNVERSION := $(shell ./util/getrevision.sh -u)<br>
<br>
RELEASE := 0.9.6.1<br>
-VERSION := $(RELEASE)-r$(SVNVERSION)<br>
+VERSION := $(RELEASE)-$(SVNVERSION)<br>
RELEASENAME ?= $(VERSION)<br>
<br>
SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'<br>
diff --git a/util/getrevision.sh b/util/getrevision.sh<br>
index 678d66b..95a57fe 100755<br>
--- a/util/getrevision.sh<br>
+++ b/util/getrevision.sh<br>
@@ -5,6 +5,7 @@<br>
# Copyright (C) 2005 coresystems GmbH <<a href="mailto:stepan@coresystems.de">stepan@coresystems.de</a>><br>
# Copyright (C) 2009,2010 Carl-Daniel Hailfinger<br>
# Copyright (C) 2010 Chromium OS Authors<br>
+# Copyright (C) 2013 Stefan Tauner<br>
#<br>
# This program is free software; you can redistribute it and/or modify<br>
# it under the terms of the GNU General Public License as published by<br>
@@ -23,18 +24,17 @@<br>
<br>
EXIT_SUCCESS=0<br>
EXIT_FAILURE=1<br>
+date_format="+%Y-%m-%dT%H:%M:%S%z" # There is only one valid timeformat FFS! ISO 8601<br>
<br>
svn_revision() {<br>
LC_ALL=C svnversion -cn . 2>/dev/null | \<br>
- sed -e "s/.*://" -e "s/\([0-9]*\).*/\1/" | \<br>
- grep "[0-9]" ||<br>
+ sed -e "s/.*://" -e "s/\([0-9]*\).*/r\1/" | \<br>
+ grep "r[0-9]" ||<br>
LC_ALL=C svn info . 2>/dev/null | \<br>
- awk '/^Revision:/ {print $$2 }' | \<br>
- grep "[0-9]" ||<br>
- LC_ALL=C git svn info . 2>/dev/null | \<br>
- awk '/^Revision:/ {print $$2 }' | \<br>
- grep "[0-9]" ||<br>
- echo ''<br>
+ grep "Last Changed Rev:" | \<br>
+ sed -e "s/^Last Changed Rev: *//" -e "s/\([0-9]*\).*/r\1/" | \<br>
+ grep "r[0-9]" ||<br>
+ echo "unknown"<br>
}<br>
<br>
svn_url() {<br>
@@ -45,74 +45,81 @@ svn_url() {<br>
)<br>
}<br>
<br>
+svn_has_local_changes() {<br>
+ svn status | egrep '^ *[ADMR] *' > /dev/null<br>
+}<br>
+<br>
svn_timestamp() {<br>
- local date_format="+%Y-%m-%d %H:%M:%S"<br>
local timestamp<br>
<br>
- # are there local changes in the client?<br>
- if svn status | egrep '^ *[ADMR] *' > /dev/null ; then<br>
- timestamp=$(date "${date_format} +")<br>
+ if svn_has_local_changes ; then<br>
+ timestamp=$(date "${date_format}")<br>
else<br>
# No local changes, get date of the last log record.<br>
local last_commit_date=$(svn info | grep '^Last Changed Date:' | \<br>
awk '{print $4" "$5" "$6}')<br>
- timestamp=$(date --utc --date "${last_commit_date}" \<br>
- "${date_format} UTC")<br>
+ timestamp=$(date -d "${last_commit_date}" "${date_format}")<br>
fi<br>
<br>
echo "${timestamp}"<br>
}<br>
<br>
-git_revision() {<br>
- echo $(git log --oneline | head -1 | awk '{print $1}')<br>
-}<br>
-<br>
-# Retrieve svn revision using git log data (for git mirrors)<br>
+# Retrieve svn revision using git log data (for git-svn mirrors)<br>
gitsvn_revision() {<br>
local r<br>
<br>
- git log|<br>
- grep git-svn-id|<br>
- sed 's/.*git-svn-id:[[:blank:]]*\([^@]\+\)@[0-9]\+[[:blank:]]\+\([^[:blank:]]\+\)/\1 \2/'|<br>
- sort|<br>
- uniq|<br>
- read url uuid<br>
-<br>
- r=$(git log --grep="git-svn-id.*$uuid"| grep git-svn-id | \<br>
- sed 's/.*@//;s/[[:blank:]].*//'| \<br>
- sort -n | \<br>
- tail -1)<br>
+ # If this is a "native" git-svn clone we could use git svn log like so<br>
+ # if [ -e .git/svn/.metadata ]; then<br>
+ # r=$(git svn log --oneline -1 | sed 's/^r//;s/[[:blank:]].*//')<br>
+ # else<br>
+ r=$(git log --grep git-svn-id -1 | \<br>
+ grep git-svn-id | \<br>
+ sed 's/.*@/r/;s/[[:blank:]].*//')<br>
+ # fi<br>
<br>
echo "${r}"<br>
}<br>
<br>
+git_has_local_changes() {<br>
+ git update-index -q --refresh<br>
+ ! git diff-index --quiet HEAD --<br>
+}<br>
+<br>
git_timestamp() {<br>
- local date_format="+%b %d %Y %H:%M:%S"<br>
local timestamp<br>
<br>
- # are there local changes in the client?<br>
- if git status | \<br>
- egrep '^# Change(s to be committed|d but not updated):$' > /dev/null<br>
- then<br>
- timestamp=$(date "${date_format} +")<br>
+ # are there local changes?<br>
+ if git_has_local_changes ; then<br>
+ timestamp=$(date "${date_format}")<br>
else<br>
- # No local changes, get date of the last log record.<br>
- local last_commit_date=$(git log | head -3 | grep '^Date:' | \<br>
- awk '{print $3" "$4" "$6" "$5" "$7}')<br>
- timestamp=$(date --utc --date "${last_commit_date}" \<br>
- "${date_format} UTC")<br>
+ # No local changes, get date of the last commit<br>
+ timestamp=$(date -d "$(git log --pretty=format:"%cD" -1)" "${date_format}")<br>
fi<br>
<br>
echo "${timestamp}"<br>
}<br>
<br>
git_url() {<br>
- # Only the first line of `git remote' is considered.<br>
- echo $(LC_ALL=C git remote show origin 2>/dev/null |<br>
- grep 'Fetch URL:' |<br>
- sed 's/.*URL:[[:blank:]]*//' |<br>
- grep ^.<br>
- )<br>
+ # get all remote branches containing the last commit<br>
+ branches=$(git branch -r --contains HEAD | cut -c 3-)<br>
+ if [ -z "$branches" ] ; then<br>
+ echo "No remote branch contains current HEAD">&2<br>
+ return<br>
+ fi<br>
+<br>
+ # find "nearest" branch<br>
+ local diff=9000<br>
+ local target=<br>
+ for branch in $branches ; do<br>
+ curdiff=$(git rev-list --count HEAD..$branch)<br>
+ if [ $curdiff -ge $diff ] ; then<br>
+ continue<br>
+ fi<br>
+ diff=$curdiff<br>
+ target=$branch<br>
+ done<br>
+<br>
+ echo "$(git ls-remote --exit-code --get-url ${target%/*}) ${target#*/}"<br>
}<br></blockquote><div><br></div><div>I am seeing a lot of errors when trying this. The version in the previous patch worked, though it kept the http:// prefix which is kind of superfluous.</div><div><br></div><div>Try cloning <a href="http://git.chromium.org/chromiumos/third_party/flashrom.git">http://git.chromium.org/chromiumos/third_party/flashrom.git</a> . </div>
<div><br></div><div><div>$ sh getrevision.sh -U</div><div>fatal: ambiguous argument 'HEAD..->': unknown revision or path not in the working tree.</div><div>Use '--' to separate paths from revisions, like this:</div>
<div>'git <command> [<revision>...] -- [<file>...]'</div><div>getrevision.sh: line 115: [: -ge: unary operator expected</div><div>getrevision.sh: line 115: [: 0: unary operator expected</div><div>
<a href="http://git.chromium.org/chromiumos/third_party/flashrom.git">http://git.chromium.org/chromiumos/third_party/flashrom.git</a> master</div></div><div><br></div><div>What about something like:</div><div>git ls-remote --exit-code --get-url | sed 's/.*\/\///'</div>
<div><br></div><div>That looks simpler and works better, at least in my testing...</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
scm_url() {<br>
@@ -142,16 +149,26 @@ timestamp() {<br>
echo ${t}<br>
}<br>
<br>
-# Retrieve local SCM revision info. This is useful if we're working in<br>
-# a even different SCM than upstream.<br>
+<br>
+# Retrieve local SCM revision info. This is useful if we're working in a different SCM than upstream and/or<br>
+# have local changes.<br>
#<br>
-# If local copy is svn, then there is nothing to do here.<br>
-# If local copy is git, then retrieve useful git revision info<br>
local_revision() {<br>
local r<br>
<br>
- if [ -d ".git" ] ; then<br>
- r=$(git_revision)<br>
+ if [ -d ".svn" ] ; then<br>
+ r=$(svn_has_local_changes && echo "-dirty")<br>
+ elif [ -d ".git" ] ; then<br>
+ r=$(git rev-parse --short HEAD)<br>
+<br>
+ local svn_base=$(git log --grep git-svn-id -1 --format='%h')<br>
+ if [ "$svn_base" != "" ] ; then<br>
+ r="$r-$(git rev-list --count $svn_base..HEAD)"<br>
+ fi<br>
+<br>
+ if git_has_local_changes ; then<br>
+ r="$r-dirty"<br>
+ fi<br>
fi<br>
<br>
echo ${r}<br>
@@ -168,6 +185,8 @@ upstream_revision() {<br>
r=$(svn_revision)<br>
elif [ -d ".git" ] ; then<br>
r=$(gitsvn_revision)<br>
+ else<br>
+ r="unknown"<br>
fi<br>
<br>
echo "${r}"<br>
@@ -180,48 +199,49 @@ show_help() {<br>
Options<br>
-h or --help<br>
Display this message.<br>
+ -l or --local<br>
+ local revision (if different from upstream) and an indicator for uncommitted changes<br>
-u or --upstream<br>
upstream flashrom revision<br>
- -l or --local<br>
- local revision (if different from upstream)<br>
- -t or --timestamp<br>
- timestamp of most recent modification<br>
-U or --url<br>
url associated with local copy of flashrom<br>
+ -t or --timestamp<br>
+ timestamp of most recent modification<br>
"<br>
return<br>
}<br>
<br>
-if [ ! -n "${1}" ]<br>
-then<br>
+if [ -z "${1}" ] ; then<br>
show_help;<br>
echo "No options specified";<br>
- exit ${EXIT_SUCCESS}<br>
+ exit ${EXIT_FAILURE}<br>
fi<br>
<br>
# The is the main loop<br>
-while [[ ${1} = -* ]];<br>
+while [ $# -gt 0 ];<br>
do<br>
case ${1} in<br>
-h|--help)<br>
show_help;<br>
shift;;<br>
- -u|--upstream)<br>
- echo "$(upstream_revision)";<br>
- shift;;<br>
-l|--local)<br>
echo "$(local_revision)";<br>
shift;;<br>
- -t|--timestamp)<br>
- echo "$(timestamp)";<br>
+ -u|--upstream)<br>
+ echo "$(upstream_revision)";<br>
shift;;<br>
-U|--url)<br>
echo "$(scm_url)";<br>
shift;;<br>
- *)<br>
+ -t|--timestamp)<br>
+ echo "$(timestamp)";<br>
+ shift;;<br>
+ -*)<br>
show_help;<br>
echo "invalid option: ${1}"<br>
- exit ${EXIT_FAILURE}<br>
+ exit ${EXIT_FAILURE};;<br>
+ *)<br>
+ shift;; # ignore arguments not starting with -<br>
esac;<br>
done<br>
<span class=""><font color="#888888"><br>
--<br>
Kind regards, Stefan Tauner<br>
<br>
<br>
_______________________________________________<br>
flashrom mailing list<br>
<a href="mailto:flashrom@flashrom.org">flashrom@flashrom.org</a><br>
<a href="http://www.flashrom.org/mailman/listinfo/flashrom" target="_blank">http://www.flashrom.org/mailman/listinfo/flashrom</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>David Hendricks (dhendrix)<br>Systems Software Engineer, Google Inc.
</div></div>