File: quilt-patches-deb-export-hook

package info (click to toggle)
gitpkg 0.31%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: sh: 1,365; makefile: 34
file content (109 lines) | stat: -rw-r--r-- 3,770 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# This script reads a list of revision ranges suitable for git format-patch
# from the $patch_list file, one per line, and exports them to the $patch_dir
# directory in a form suitable for (format 3.0) quilt packages.
# It is not required for creating such packages, but permits you to separate
# out individual patches however you please from the default single patch
# that is otherwise created by dpkg-source.

# The revision ranges may include $DEB_REF and/or $UPSTREAM_REF, which
# will be substituted according to the version of the package being
# exported.  These variables are derived from $DEB_VERSION and
# $UPSTREAM_VERSION by applying sanitise_git_ref (see gitpkg(1) for
# more on these three things).  You can also use DEB_VERSION and
# UPSTREAM_VERSION directly, but this is discouraged, and might go
# away in a future version.

# To enable this hook, use:
# git config gitpkg.deb-export-hook /usr/share/gitpkg/hooks/quilt-patches-deb-export-hook
#
#
# It can also be invoked independently of gitpkg, such as from within your
# project makefile or debian/rules, with something like:
#
# PATCH_EXPORT_SCRIPT=/usr/share/gitpkg/hooks/quilt-patches-deb-export-hook
# export-patches:
#	[ ! -r debian/patches ] || \
#	grep "^\#.*$(notdir $(PATCH_EXPORT_SCRIPT))" debian/patches/series
#	rm -rf debian/patches
#	bash $(PATCH_EXPORT_SCRIPT)

# Import the sanitise_git_ref function
. /usr/share/gitpkg/hooks/repo-config-helper


patch_list=debian/source/git-patches
patch_dir=debian/patches


if [ ! -r "$patch_list" ]; then
    echo "No $patch_list file, I guess you've pushed them all upstream."
    echo "Good Work!"
    exit 0
fi

if [ -e "$patch_dir" ]; then
    echo "Uh oh.  You already have a $patch_dir here."
    echo "You probably don't want us to scribble on that without asking."
    exit 1
fi

if [ -z "$REPO_DIR" ]; then
    # support running as a free-standing script, without gitpkg
    DEB_VERSION="$(dpkg-parsechangelog | sed -rne 's/^Version: ([^:]+:)?//p')"
    UPSTREAM_VERSION="${DEB_VERSION%-*}"
    REPO_DIR=.
fi;

DEB_REF=$(sanitise_git_ref $DEB_VERSION)
UPSTREAM_REF="${DEB_REF%-*}"

do_patches (){
    while read -r line
    do
	[ -n "$line" ] || continue
	case $line in
	    \#*)
		;;
	    *)
		count=$(wc -l "$patch_dir/series" | cut -f1 -d' ')
		if PATCHES="$(git --git-dir "$REPO_DIR/.git" format-patch --no-signature --start-number $count -N -o "$patch_dir" "$line")"; then
		    if [ -n "$PATCHES" ]; then
			echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >> "$patch_dir/series"
		    else
			echo "Warning: no patches from $line"
		    fi
		else
		    echo "git --git-dir '$REPO_DIR/.git' format-patch --no-signature --start-number $count -N -o '$patch_dir' '$line'"
		    echo "failed."
		    exit 1
		fi
	esac
    done
}

mkdir -p "$patch_dir" || exit 1
echo "# $patch_list exported from git by quilt-patches-deb-export-hook" > "$patch_dir/series"

(sed -e "s/\$DEB_VERSION/$DEB_VERSION/g"		\
    -e "s/\${DEB_VERSION}/$DEB_VERSION/g"		\
    -e "s/\$UPSTREAM_VERSION/$UPSTREAM_VERSION/g"	\
    -e "s/\${UPSTREAM_VERSION}/$UPSTREAM_VERSION/g"	\
    -e "s/\$DEB_REF/$DEB_REF/g"				\
    -e "s/\${DEB_REF}/$DEB_REF/g"			\
    -e "s/\$UPSTREAM_REF/$UPSTREAM_REF/g"		\
    -e "s/\${UPSTREAM_REF}/$UPSTREAM_REF/g"		\
    < "$patch_list" ; echo ) | do_patches || exit 1


count=$(wc -l "$patch_dir/series" | cut -f1 -d' ')

# We remove the patch_list file if no patches were actually exported,
# to avoid triggering the lintian check about them not being exported.
# This might happen if people list a wildcard revision that doesn't
# have any changes outstanding for a particular release version.
if [ $count -eq 1 ]; then
    echo "No patches generated from $patch_list"
    rm -rf "$patch_dir"
    rm "$patch_list"
fi