scripts/getver.sh: fix one more wc -l call
[openwrt/openwrt.git] / scripts / getver.sh
index 5d8788f20200906fa8c0326d2e7e3242b3b1c691..46eee9a04937109c4989e07d6a1c24efcb41e010 100755 (executable)
@@ -19,18 +19,27 @@ try_git() {
        case "$GET_REV" in
        r*)
                GET_REV="$(echo $GET_REV | tr -d 'r')"
-               BASE_REV="$(git rev-list reboot..HEAD | wc -l)"
+               BASE_REV="$(git rev-list reboot..HEAD | wc -l | awk '{print $1}')"
                REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
                ;;
        *)
-               UPSTREAM_BASE="$(git merge-base $GET_REV origin/master)"
-               UPSTREAM_REV="$(git rev-list reboot..$UPSTREAM_BASE | wc -l | awk '{print $1}')"
+               BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+               ORIGIN="$(git rev-parse --symbolic-full-name ${BRANCH}@{u} 2>/dev/null)"
+               [ -n "$ORIGIN" ] || ORIGIN="$(git rev-parse --symbolic-full-name master@{u} 2>/dev/null)"
                REV="$(git rev-list reboot..$GET_REV | wc -l | awk '{print $1}')"
-               if [ -n "$REV" -a -n "$UPSTREAM_REV" -a "$REV" -gt "$UPSTREAM_REV" ]; then
-                       REV="r${UPSTREAM_REV}+$((REV - UPSTREAM_REV))"
+
+               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
-                       REV="${REV:+r$REV}"
+                       UPSTREAM_REV=$REV
+               fi
+
+               if [ "$REV" -gt "$UPSTREAM_REV" ]; then
+                       REV="${UPSTREAM_REV}+$((REV - UPSTREAM_REV))"
                fi
+
+               REV="${REV:+r$REV}"
                ;;
        esac