[pbuilder] 02/03: modules: add a get822field() function

Mattia Rizzolo mattia at debian.org
Fri Jan 13 19:04:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository pbuilder.

commit cc1f525731379ccae7eb61769f5634f5c42df458
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Fri Jan 6 16:15:56 2017 +0000

    modules: add a get822field() function
    
    Just get the content of the given field in a deb822-formatted file.
    
    Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
 pbuilder-modules | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/pbuilder-modules b/pbuilder-modules
index 1e4efe5..051750a 100644
--- a/pbuilder-modules
+++ b/pbuilder-modules
@@ -849,6 +849,60 @@ function install_packages_for_optional_features() {
     fi
 }
 
+function get822field() {
+    local field="$1"
+    local file="$2"
+
+    sed -n '
+# Skip PGP header
+/^-----BEGIN PGP SIGNED MESSAGE-----$/ {
+    : pgploop
+    n
+    /^$/ b leadloop
+    b pgploop
+}
+
+# Skip empty lines/comments
+: leadloop
+/^[ \t]*$/ {
+    n
+    b leadloop
+}
+/^#/ {
+    n
+    b leadloop
+}
+
+# First line of paragraph
+: paraloop
+# Strip field name from line if present
+s/^'"$field"': *//i
+# If field present, print contents
+# Note the h; t loop; here rather than t store; so that there is no leading
+# newline in the hold space. This will store unmatched lines in the hold space,
+# but that does not matter as the first matched line will overwrite it.
+h
+t loop
+# Otherwise, check for end of paragraph or ignore
+/^[ \t]*$/q
+n
+b paraloop
+
+: store
+H
+: loop
+$ b done
+n
+/^#/ b loop
+/^[ \t]/ b store
+: done
+x
+p
+n
+b paraloop' \
+    "$file"
+}
+
 #==========================================================================
 # hooks stuff
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/pbuilder.git



More information about the Pbuilder-maint mailing list