[SCM] Debian Qt/KDE packaging tools branch, master, updated. master/0.5.1-2-gcb0a75b

Modestas Vainius modax-guest at alioth.debian.org
Fri Oct 16 14:06:41 UTC 2009


The following commit has been merged in the master branch:
commit cb0a75b00254157b5417a494be114b13ccdf837d
Author: Modestas Vainius <modestas at vainius.eu>
Date:   Fri Oct 16 17:02:55 2009 +0300

    Initial version of pkgkde-vcs tool with git tag support.
    
    This commit adds a pkgkde-vcs helper tool for performing various common tasks
    when packaging with version control system repositories. As of this commit the
    only VCS supported is Git which supports 'tag' subcommand for tagging debian
    package releases when as they are uploaded Debian.
---
 Makefile          |    8 ++-
 debian/changelog  |    4 +
 debian/copyright  |    3 +-
 vcs/pkgkde-vcs    |  175 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 vcs/vcslib/git.sh |   82 +++++++++++++++++++++++++
 5 files changed, 270 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 2a355cb..52a9d4e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
 PERLLIBDIR := $(shell perl -MConfig -e 'print $$Config{vendorlib}')
 SYMBOLSHELPER_DIR := symbolshelper
 DEBHELPER_DIR := debhelper
+VCS_DIR := vcs
 
 BINDIR := $(DESTDIR)/usr/bin
 MANDIR := $(DESTDIR)/usr/share/man
-#DATADIR := $(DESTDIR)/usr/share/pkg-kde-tools
+DATADIR := $(DESTDIR)/usr/share/pkg-kde-tools
 
 build:
 	# Nothing do build
@@ -25,3 +26,8 @@ install:
 	# Debhelper addons
 	cd $(DEBHELPER_DIR) && find Debian -type f -name "*.pm" -exec \
 	    install -D -m 0644 {} $(DESTDIR)/$(PERLLIBDIR)/{} \;
+	
+	# pkgkde-vcs
+	install -d $(DATADIR)/vcs
+	install -m 0755 $(VCS_DIR)/pkgkde-vcs $(BINDIR)
+	cd $(VCS_DIR)/vcslib && find . -type f -exec install -D -m 0644 {} $(DATADIR)/vcs/{} \;
diff --git a/debian/changelog b/debian/changelog
index fcc9fd7..2fca54b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,9 @@
 pkg-kde-tools (0.5.2~pre1) UNRELEASED; urgency=low
 
+  * Add pkgkde-vcs helper tool for performing various common tasks
+    when packaging with version control system repositories. As of this commit
+    the only VCS supported is Git which supports 'tag' subcommand for tagging
+    debian package releases when as they are uploaded Debian.
 
  -- Modestas Vainius <modestas at vainius.eu>  Fri, 16 Oct 2009 16:47:42 +0300
 
diff --git a/debian/copyright b/debian/copyright
index 7d51b7c..2083a6c 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -39,9 +39,10 @@ Public License can be found in `/usr/share/common-licenses/GPL-2'.
 The follwing license and copyright applies to the contents of:
 
   - "symbolshelper" directory;
+  - "vcs" directory;
   - dh_sameversiondep script.
 
-  |  Copyright © 2008 Modestas Vainius <modestas at vainius.eu>
+  |  Copyright © 2008-2009 Modestas Vainius <modestas at vainius.eu>
   |
   |  This program is free software: you can redistribute it and/or modify
   |  it under the terms of the GNU General Public License as published by
diff --git a/vcs/pkgkde-vcs b/vcs/pkgkde-vcs
new file mode 100755
index 0000000..08dc6cb
--- /dev/null
+++ b/vcs/pkgkde-vcs
@@ -0,0 +1,175 @@
+#!/bin/sh
+
+# Copyright (C) 2009 Modestas Vainius <modestas at vainius.eu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+# Tag debian package release
+
+info()
+{
+    echo "pkgkde-vcs: $*"
+}
+
+die()
+{
+    info "fatal: $*" >&2
+    exit 1
+}
+
+# Determine VCS type of the repository in the current directory and echo
+# its type to standard output.
+# Supports Git at the moment
+determine_vcs()
+{
+    if which git > /dev/null && git rev-parse --git-dir >/dev/null 2>/dev/null; then
+        echo git
+        return 0
+    fi
+    return 1
+}
+
+# Determine LIBDIR. Supports both running in-source and installed
+# version.
+determine_libdir()
+{
+    local libdir
+    libdir=`dirname $0 2>/dev/null`
+    if [ -n "$libdir" ] && [ -d "$libdir/vcslib" ]; then
+        echo "$libdir/vcslib"
+        return 0
+    else
+        libdir="/usr/share/pkg-kde-tools/vcs"
+        if [ -d "$libdir" ]; then
+            echo "$libdir"
+            return 0
+        fi
+    fi
+    return 1
+}
+
+# Run the command prompting for confirmation if necessary
+runcmd()
+{
+    local ans exitval
+    if [ -n "$OPT_VERBOSE" ] || [ -z "$OPT_YES" ]; then
+        echo "$" "$*" >&2
+    fi
+    if [ -z "$OPT_YES" ]; then
+        echo -n "Run the command above? [Y/n]: "
+        while true; do
+            read ans
+            if [ "$ans" = "Y" ] || [ "$ans" = "y" ] || [ -z "$ans" ]; then
+                break
+            elif [ "$ans" = "N" ] || [ "$ans" = "n" ]; then
+                info "Cancelled by user." >&2
+                exit 2
+            else
+                echo -n "Enter Y (default) or N: "
+            fi
+        done
+    fi
+
+    # Run the command
+    "$@"
+    exitval="$?"
+    if [ "$exitval" -eq "0" ]; then
+        return 0
+    else
+        info "Command failed with $exitval" >&2
+        exit $exitval
+    fi
+}
+
+_get_deb_field()
+{
+    cat | grep "^$1:" | sed "s/^$1:[[:space:]]*\(.*\)\$/\1/"
+}
+
+# Given path to the package root (where debian/ subdirectory is), set some
+# informational variables (DEB_* namespace) about the package
+get_debian_package_info()
+{
+    local rootdir _pchangelog
+    rootdir="$1"
+
+    if [ -f "$rootdir/debian/changelog" ]; then
+        _pchangelog="$(dpkg-parsechangelog "-l$rootdir/debian/changelog")"
+        DEB_VERSION="$(echo "$_pchangelog" | _get_deb_field 'Version')"
+        if [ -n "$DEB_VERSION" ]; then
+            DEB_VERSION_WO_EPOCH=$(echo $DEB_VERSION | sed 's/^[[:digit:]]\+://')
+        else
+            die "unable to determine package version."
+        fi
+        DEB_SOURCE="$(echo "$_pchangelog" | _get_deb_field 'Source')"
+        DEB_DISTRIBUTION="$(echo "$_pchangelog" | _get_deb_field 'Distribution')"
+    else
+        die "debian/changelog could not be found in $rootdir"
+    fi
+}
+
+is_valid_package_root()
+{
+    test -f "$1/debian/changelog" && test -f "$1/debian/control"
+}
+
+is_distribution_valid()
+{
+    local distro
+    test -n "$1" || distro="$DEB_DISTRIBUTION"
+    if [ "$(expr match "$distro" '^\(\(stable\|testing\)\(-security\|-proposed-updates\)\|\(lenny\|squeeze\)-backports\|unstable\|experimental\)$')" = "$distro" ]; then
+        return 0
+    fi
+    return 1
+}
+
+# Parse common options
+OPT_VERBOSE=
+OPT_YES=
+
+while getopts ":vy" name; do
+    case "$name" in
+        v)  OPT_VERBOSE=1 ;;
+        y)  OPT_YES=1 ;;
+        ?)  if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
+        :)  die "$OPTARG option is missing a required argument" ;;
+    esac
+done
+
+if [ "$OPTIND" -gt 1 ]; then
+    shift "$(($OPTIND-1))"
+    OPTIND=1
+fi
+
+# Determine VCS type and source its library script
+
+VCS=$(determine_vcs)
+case "$VCS" in
+    "")
+        die "unable to determine VCS type or VCS tools (git, svn) are not installed."
+        ;;
+    *)
+        # Load VCS script file. Determines LIBDIR in the process
+        if LIBDIR=$(determine_libdir) && [ $? -eq 0 ]; then
+            if [ -f "$LIBDIR/$VCS.sh" ]; then
+                . "$LIBDIR/$VCS.sh"
+            else
+                die "$VCS VCS is NOT supported (via $LIBDIR)."
+            fi
+        else
+            die "unable to determine pkgkde-vcs library directory."
+        fi
+        ;;
+esac
+
+exit 0
diff --git a/vcs/vcslib/git.sh b/vcs/vcslib/git.sh
new file mode 100644
index 0000000..6320fb3
--- /dev/null
+++ b/vcs/vcslib/git.sh
@@ -0,0 +1,82 @@
+# Copyright (C) 2009 Modestas Vainius <modestas at vainius.eu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+# Tag debian package release
+
+# Git library for pkgkde-vcs
+
+git_tag()
+{
+    local tag_path tag_msg
+
+    is_distribution_valid || die "invalid Debian distribution for tagging - $DEB_DISTRIBUTION"
+    git_is_working_tree_clean || die "working tree is dirty. Commit changes before tagging."
+
+    tag_path="debian/`git_compat_debver $DEB_VERSION_WO_EPOCH`"
+    tag_msg="$DEB_VERSION/$DEB_DISTRIBUTION"
+
+    runcmd git tag $tag_path -m "$tag_msg" "$@"
+}
+
+git_compat_debver()
+{
+    echo "$1" | tr "~" "-"
+}
+
+git_is_working_tree_clean()
+{
+    git update-index --refresh > /dev/null && git diff-index --quiet HEAD
+}
+
+
+PACKAGE_ROOT="$(readlink -f "$(git rev-parse --git-dir)/..")"
+
+# Do some envinronment sanity checks first
+if [ "$(git rev-parse --is-bare-repository)" = "true" ]; then
+    die "bare Git repositories are not supported."
+fi
+
+is_valid_package_root "$PACKAGE_ROOT" || 
+    die "$PACKAGE_ROOT does NOT appear to be a a valid debian packaging repository"
+
+# Get subcommand name
+test "$#" -gt 0  || die "subcommand is NOT specified"
+subcmd="$1"; shift
+
+# Get info about debian package
+get_debian_package_info "$PACKAGE_ROOT"
+
+# Parse remaining command line (or -- if any) options
+while getopts ":" name; do
+    case "$name" in
+        ?)  if [ -n "$OPTARG" ]; then OPTIND=$(($OPTIND-1)); fi; break;;
+        :)  die "$OPTARG option is missing a required argument" ;;
+    esac
+done
+
+if [ "$OPTIND" -gt 1 ]; then
+    shift "$(($OPTIND-1))"
+fi
+
+# Execute subcommand
+case "$subcmd" in
+    tag)
+        git_tag "$@"
+        ;;
+    *)
+        die "unsupported pkgkde-vcs Git subcommand: $subcmd"
+        ;;
+esac
+
+exit 0

-- 
Debian Qt/KDE packaging tools



More information about the pkg-kde-commits mailing list