aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2019-03-22 12:03:54 +0100
committerOliver Smith <osmith@sysmocom.de>2019-03-26 10:38:58 +0100
commit3b3a250f6b59df5c52723d5fd49e857a6d483e90 (patch)
treee670096182631f183d8cc8db51911c7cff3ceca2
parentbb714ca04228882a7c24a3a0c393e34ddc17b7c2 (diff)
osmocom-list-commits.sh: move functions to common.sh
Prepare for the upcoming osmocom-build-old-tags-against-master.sh script, which will benefit from querying the last n git tags in advance. Related: OS#3765 Change-Id: I61be4cffb9275cabc1b253f0b298503ad0d3aea4
-rw-r--r--scripts/common.sh61
-rwxr-xr-xscripts/osmocom-list-commits.sh48
2 files changed, 66 insertions, 43 deletions
diff --git a/scripts/common.sh b/scripts/common.sh
new file mode 100644
index 0000000..9f274d7
--- /dev/null
+++ b/scripts/common.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+# Various functions and variables used in multiple osmo-ci shell scripts
+OSMO_GIT_URL="https://git.osmocom.org"
+
+# Print commit of HEAD for an Osmocom git repository, e.g.:
+# "f90496f577e78944ce8db1aa5b900477c1e479b0"
+# $1: repository
+osmo_git_head_commit() {
+ # git output:
+ # f90496f577e78944ce8db1aa5b900477c1e479b0 HEAD
+ ret="$(git ls-remote "$OSMO_GIT_URL/$1" HEAD)"
+ ret="$(echo "$ret" | awk '{print $1}')"
+ echo "$ret"
+}
+
+# Print last tags and related commits for an Osmocom git repository, e.g.:
+# "ec798b89700dcca5c5b28edf1a1cd16ea311f30a refs/tags/1.0.1"
+# $1: Osmocom repository
+# $2: amount of commit, tag pairs to print (default: 1)
+# $3: string to print when there are no tags (default: empty string)
+osmo_git_last_commits_tags() {
+ # git output:
+ # ec798b89700dcca5c5b28edf1a1cd16ea311f30a refs/tags/1.0.1
+ # eab5f594b0a7cf50ad97b039f73beff42cc8312a refs/tags/1.0.1^{}
+ # ...
+ # 41e7cf115d4148a9f34fcb863b68b2d5370e335d refs/tags/1.3.1^{}
+ # 8a9f12dc2f69bf3a4e861cc9a81b71bdc5f13180 refs/tags/3G_2016_09
+ # ee618ecbedec82dfd240334bc87d0d1c806477b0 refs/tags/debian/0.9.13-0_jrsantos.1
+ # a3fdd24af099b449c9856422eb099fb45a5595df refs/tags/debian/0.9.13-0_jrsantos.1^{}
+ # ...
+ ret="$(git ls-remote --tags "$OSMO_GIT_URL/$1")"
+ ret="$(echo "$ret" | grep 'refs/tags/[0-9.]*$' || true)"
+ ret="$(echo "$ret" | sort -V -t/ -k3)"
+ ret="$(echo "$ret" | tail -n "$2")"
+
+ if [ -n "$ret" ]; then
+ echo "$ret"
+ else
+ echo "$3"
+ fi
+}
+
+# Print last commits for an Osmocom git repository, e.g.:
+# "ec798b89700dcca5c5b28edf1a1cd16ea311f30a"
+# $1: repository
+# $2: amount of commits to print (default: 1)
+# $3: string to print when there are no tags (default: empty string)
+osmo_git_last_commits() {
+ ret="$(osmo_git_last_commits_tags "$1" "$2" "$3")"
+ echo "$ret" | awk '{print $1}'
+}
+
+# Print last tags for an Osmocom git repository, e.g.:
+# "1.0.1"
+# $1: repository
+# $2: amount of commits to print (default: 1)
+# $3: string to print when there are no tags (default: empty string)
+osmo_git_last_tags() {
+ ret="$(osmo_git_last_commits_tags "$1" "$2" "$3")"
+ echo "$ret" | cut -d/ -f 3
+}
diff --git a/scripts/osmocom-list-commits.sh b/scripts/osmocom-list-commits.sh
index 886cb03..e0d3eb0 100755
--- a/scripts/osmocom-list-commits.sh
+++ b/scripts/osmocom-list-commits.sh
@@ -2,8 +2,8 @@
# Environment variables:
# * NO_HEADER: do not output the header line when set
+. "$(dirname "$0")/common.sh"
FORMAT_STR="%-22s %-42s %9s %-40s %s\n"
-URL="https://git.osmocom.org"
REPOS="
libasn1c
libosmo-abis
@@ -27,43 +27,6 @@ REPOS="
osmocom-bb
"
-# Print commit of HEAD for an Osmocom git repository, e.g.:
-# "f90496f577e78944ce8db1aa5b900477c1e479b0"
-# $1: repository
-get_head_commit() {
- # git output:
- # f90496f577e78944ce8db1aa5b900477c1e479b0 HEAD
- ret="$(git ls-remote "$URL/$1" HEAD)"
- ret="$(echo "$ret" | awk '{print $1}')"
- echo "$ret"
-}
-
-# Print last tag and related commit for an Osmocom git repository, e.g.:
-# "ec798b89700dcca5c5b28edf1a1cd16ea311f30a refs/tags/1.0.1"
-# Print "-" when no tags were found.
-# $1: repository
-get_last() {
- # git output:
- # ec798b89700dcca5c5b28edf1a1cd16ea311f30a refs/tags/1.0.1
- # eab5f594b0a7cf50ad97b039f73beff42cc8312a refs/tags/1.0.1^{}
- # ...
- # 41e7cf115d4148a9f34fcb863b68b2d5370e335d refs/tags/1.3.1^{}
- # 8a9f12dc2f69bf3a4e861cc9a81b71bdc5f13180 refs/tags/3G_2016_09
- # ee618ecbedec82dfd240334bc87d0d1c806477b0 refs/tags/debian/0.9.13-0_jrsantos.1
- # a3fdd24af099b449c9856422eb099fb45a5595df refs/tags/debian/0.9.13-0_jrsantos.1^{}
- # ...
- ret="$(git ls-remote --tags "$URL/$1")"
- ret="$(echo "$ret" | grep 'refs/tags/[0-9.]*$' || true)"
- ret="$(echo "$ret" | sort -V -t/ -k3)"
- ret="$(echo "$ret" | tail -n 1)"
-
- if [ -n "$ret" ]; then
- echo "$ret"
- else
- echo "-"
- fi
-}
-
# Header
if [ -z "$NO_HEADER" ]; then
printf "$FORMAT_STR" "# repository" "clone URL" "last tag" "last tag commit" "HEAD commit"
@@ -71,14 +34,13 @@ fi
# Table
for repo in $REPOS; do
- last="$(get_last "$repo")"
- last_tag="$(echo "$last" | cut -d/ -f 3)"
- last_commit="$(echo "$last" | awk '{print $1}')"
- head_commit="$(get_head_commit "$repo")"
+ last_tag="$(osmo_git_last_tags "$repo" 1 "-")"
+ last_commit="$(osmo_git_last_commits "$repo" 1 "-")"
+ head_commit="$(osmo_git_head_commit "$repo")"
printf "$FORMAT_STR" \
"$repo.git" \
- "$URL/$repo" \
+ "$OSMO_GIT_URL/$repo" \
"$last_tag" \
"$last_commit" \
"$head_commit"