chiark / gitweb /
git-debpush: factor out find_last_tag()
authorSean Whitton <spwhitton@spwhitton.name>
Wed, 17 Jul 2019 07:20:13 +0000 (08:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jul 2019 13:12:27 +0000 (14:12 +0100)
Also determine the last debian/ tag earlier, for use by sanity checks.

No functional change.

Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
git-debpush

index c8295798cab4c408d5fa70be2a2ca41105aad6d9..969ee619f49f69372f4a11ad70f4cd275b5e26ac 100755 (executable)
@@ -73,6 +73,19 @@ fail_check () {
     fi
 }
 
+find_last_tag () {
+    local prefix=$1
+
+    set +o pipefail             # perl will SIGPIPE git-log(1) here
+    git log --pretty=format:'%D' --decorate=full "$branch" \
+        | perl -wne 'use Dpkg::Version;
+            @pieces = split /, /, $_;
+            @debian_tag_vs = sort { version_compare($b, $a) }
+                map { m|tag: refs/tags/'"$prefix"'(.+)| ? $1 : () } @pieces;
+            if (@debian_tag_vs) { print "'"$prefix"'$debian_tag_vs[0]\n"; exit }'
+    set -o pipefail
+}
+
 # ---- Parse command line
 
 getopt=$(getopt -s bash -o 'nfu:' \
@@ -185,6 +198,10 @@ target=$(cd $temp; dpkg-parsechangelog -SDistribution)
 rm -rf "$temp"
 trap - EXIT
 
+# ---- Gather git history information
+
+last_debian_tag=$(find_last_tag "debian/")
+
 # ---- Useful sanity checks
 
 if [ "$target" = "UNRELEASED" ]; then
@@ -258,15 +275,9 @@ debian_tag="$distro/$git_version"
 # If the user didn't supply a quilt mode, look for it in a previous
 # tag made by this script
 if [ "x$quilt_mode" = "x" ] && [ "$format" = "3.0 (quilt)" ]; then
-    set +o pipefail             # perl will SIGPIPE git-log(1) here
-    tag=$(git log --pretty=format:'%D' --decorate=full "$branch" \
-        | perl -wne 'use Dpkg::Version;
-               @pieces = split /, /, $_;
-               @debian_tag_vs = sort {version_compare($b, $a)}
-                    map { m|tag: refs/tags/debian/(.+)| ? $1 : () } @pieces;
-               if (@debian_tag_vs) { print "debian/$debian_tag_vs[0]\n"; exit }')
-    if [ "x$tag" != "x" ]; then
-        quilt_mode=$(git cat-file -p $(git rev-parse "$tag") \
+    set +o pipefail             # perl will SIGPIPE git-cat-file(1) here
+    if [ "x$last_debian_tag" != "x" ]; then
+        quilt_mode=$(git cat-file -p $(git rev-parse "$last_debian_tag") \
                          | perl -wne \
                                 'm/^\[dgit.*--quilt=([a-z+]+).*\]$/;
                                  if ($1) { print "$1\n"; exit }')