mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-20 06:08:08 +00:00
bf3d92f0cd
If something goes wrong and script can't find upstream revision it will return something like: r2220 which looks like a valid upstream revision 2220. We cant' distinguish it from e.g. 2200 upstream commits and 20 local ones. The new format still provides revision number but also points clearly that is may be not the upstream one: r0+2220 Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin < john@phrozen.org>
59 lines
1.4 KiB
Bash
Executable File
59 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
export LANG=C
|
|
export LC_ALL=C
|
|
[ -n "$TOPDIR" ] && cd $TOPDIR
|
|
|
|
GET_REV=$1
|
|
|
|
try_version() {
|
|
[ -f version ] || return 1
|
|
REV="$(cat version)"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_git() {
|
|
REBOOT=ee53a240ac902dc83209008a2671e7fdcf55957a
|
|
git rev-parse --git-dir >/dev/null 2>&1 || return 1
|
|
|
|
[ -n "$GET_REV" ] || GET_REV="HEAD"
|
|
|
|
case "$GET_REV" in
|
|
r*)
|
|
GET_REV="$(echo $GET_REV | tr -d 'r')"
|
|
BASE_REV="$(git rev-list ${REBOOT}..HEAD | wc -l | awk '{print $1}')"
|
|
REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
|
|
;;
|
|
*)
|
|
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}')"
|
|
else
|
|
UPSTREAM_REV=0
|
|
fi
|
|
|
|
if [ "$REV" -gt "$UPSTREAM_REV" ]; then
|
|
REV="${UPSTREAM_REV}+$((REV - UPSTREAM_REV))"
|
|
fi
|
|
|
|
REV="${REV:+r$REV}"
|
|
;;
|
|
esac
|
|
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_hg() {
|
|
[ -d .hg ] || return 1
|
|
REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
|
|
REV="${REV:+r$REV}"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_version || try_git || try_hg || REV="unknown"
|
|
echo "$REV"
|