[LEDE-DEV] [PATCH] scripts: getver.sh: use sha1 as base and drop r* format

Rafał Miłecki zajec5 at gmail.com
Thu Jun 15 05:17:56 PDT 2017


From: Rafał Miłecki <rafal at milecki.pl>

Counting commits to determine revision number is a wrong idea when there
are branches in a project. This could generate the same revision for
different git commits, e.g.:

For master branch:
./scripts/getver.sh bb9d2aa868
r3438-bb9d2aa868

For lede-17.01 branch:
./scripts/getver.sh 2e206c79cc
r3438-2e206c79cc

Let's use git's sha1 instead and add amount of local commits on top of
this, e.g.:
./scripts/getver.sh
c00fbaf670+3

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 scripts/getver.sh | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/scripts/getver.sh b/scripts/getver.sh
index 9175f411db..17b3dd64ae 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -27,20 +27,18 @@ try_git() {
 		BRANCH="$(git rev-parse --abbrev-ref HEAD)"
 		ORIGIN="$(git rev-parse --verify --symbolic-full-name ${BRANCH}@{u} 2>/dev/null)"
 		[ -n "$ORIGIN" ] || ORIGIN="$(git rev-parse --verify --symbolic-full-name master@{u} 2>/dev/null)"
-		REV="$(git rev-list ${REBOOT}..$GET_REV | wc -l | awk '{print $1}')"
 
 		if [ -n "$ORIGIN" ]; then
 			UPSTREAM_BASE="$(git merge-base $GET_REV $ORIGIN)"
-			UPSTREAM_REV="$(git rev-list ${REBOOT}..$UPSTREAM_BASE | wc -l | awk '{print $1}')"
+			UPSTREAM_BASE_ABBR="$(git log -n 1 --format="%h" $UPSTREAM_BASE)"
+			LOCAL_COMMITS="$(git rev-list ${UPSTREAM_BASE}..$GET_REV | wc -l | awk '{print $1}')"
 		else
-			UPSTREAM_REV=0
+			UPSTREAM_BASE_ABBR="unknown"
+			LOCAL_COMMITS="$(git rev-list $GET_REV | wc -l | awk '{print $1}')"
 		fi
+		[ $LOCAL_COMMITS -eq 0 ] && LOCAL_COMMITS=""
 
-		if [ "$REV" -gt "$UPSTREAM_REV" ]; then
-			REV="${UPSTREAM_REV}+$((REV - UPSTREAM_REV))"
-		fi
-
-		REV="${REV:+r$REV-$(git log -n 1 --format="%h" $UPSTREAM_BASE)}"
+		REV="$UPSTREAM_BASE_ABBR${LOCAL_COMMITS:++$LOCAL_COMMITS}"
 
 		;;
 	esac
-- 
2.11.0




More information about the Lede-dev mailing list