Change in osmo-ci[master]: osmocom-list-commits.sh: move functions to common.sh

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Wed Mar 27 09:26:33 UTC 2019


osmith has submitted this change and it was merged. ( https://gerrit.osmocom.org/13412 )

Change subject: osmocom-list-commits.sh: move functions to common.sh
......................................................................

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
---
A scripts/common.sh
M scripts/osmocom-list-commits.sh
2 files changed, 66 insertions(+), 43 deletions(-)

Approvals:
  Max: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  osmith: Verified



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 @@
 	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 @@
 
 # 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"

-- 
To view, visit https://gerrit.osmocom.org/13412
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I61be4cffb9275cabc1b253f0b298503ad0d3aea4
Gerrit-Change-Number: 13412
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190327/80bbd5a0/attachment.htm>


More information about the gerrit-log mailing list