mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2025-07-03 00:47:42 +00:00
When doing package support and management it is often the case that knowing the corresponding openwrt repo's release version is useful. For example, when adding package changes to the ASU server, the openwrt revision is used as the cutoff for applying those changes. Knowing a package change's hash in its remote feed repo allows us to look up its change date, which we can now use with getver.sh to approximate the revision in openwrt at which it was made. Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com> Link: https://github.com/openwrt/openwrt/pull/17817 Signed-off-by: Robert Marko <robimarko@gmail.com>
63 lines
1.6 KiB
Bash
Executable File
63 lines
1.6 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 2>/dev/null | wc -l | awk '{print $1}')"
|
|
[ $((BASE_REV - GET_REV)) -ge 0 ] && REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
|
|
;;
|
|
*-*-*) # ISO date format - for approximating when packages were removed or renamed
|
|
GET_REV="$(git log -n 1 --format="%h" --until "$GET_REV")"
|
|
;& # FALLTHROUGH
|
|
*)
|
|
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 main@{u} 2>/dev/null)"
|
|
REV="$(git rev-list ${REBOOT}..$GET_REV 2>/dev/null | 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 2>/dev/null | 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-$(git log -n 1 --format="%h" $UPSTREAM_BASE)}"
|
|
|
|
;;
|
|
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"
|