File: header.in

package info (click to toggle)
quilt 0.63-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,868 kB
  • ctags: 153
  • sloc: sh: 5,792; perl: 1,236; lisp: 492; makefile: 431
file content (207 lines) | stat: -rw-r--r-- 4,461 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#! @BASH@

#  This script is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2 as
#  published by the Free Software Foundation.
#
#  See the COPYING and AUTHORS files for more details.

# Read in library functions
if [ "$(type -t patch_file_name)" != function ]
then
	if ! [ -r $QUILT_DIR/scripts/patchfns ]
	then
		echo "Cannot read library $QUILT_DIR/scripts/patchfns" >&2
		exit 1
	fi
	. $QUILT_DIR/scripts/patchfns
fi

: ${EDITOR:=sensible-editor}

usage()
{
	printf $"Usage: quilt header [-a|-r|-e] [--backup] [--dep3] [--strip-diffstat] [--strip-trailing-whitespace] [patch]\n"

	if [ x$1 = x-h ]
	then
		printf $"
Print or change the header of the topmost or specified patch.

-a, -r, -e
	Append to (-a) or replace (-r) the existing patch header, or
	edit (-e) the header in \$EDITOR (%s). If none of these options is
	given, print the patch header.

--strip-diffstat
	Strip diffstat output from the header.

--strip-trailing-whitespace
	Strip trailing whitespace at the end of lines of the header.

--backup
	Create a backup copy of the old version of a patch as patch~.

--dep3
	When editing (-e), insert a template with DEP-3 headers.
	DEP-3 is http://dep.debian.net/deps/dep3/ Patch Tagging Guidelines.
" "$EDITOR"
		exit 0
	else
		exit 1
	fi
}

maybe_strip_trailing_whitespace()
{
	if [ -n "$opt_strip_trailing_whitespace" ]
	then
		sed -e 's:[ '$'\t'']*$::'
	else
		cat
	fi
}

maybe_strip_diffstat()
{
	if [ -n "$opt_strip_diffstat" ]
	then
		strip_diffstat
	else
		cat
	fi
}

options=`getopt -o areh --long backup,dep3,strip-trailing-whitespace,strip-diffstat -- "$@"`

if [ $? -ne 0 ]
then
	usage
fi

eval set -- "$options"

while true
do
	case "$1" in
	-a)
		opt_append=1
		shift ;;
	-r)
		opt_replace=1
		shift ;;
	-e)
		opt_edit=1
		shift ;;
	--backup)
		QUILT_BACKUP=1
		shift ;;
	--dep3)
		opt_use_dep3_headers=1
		shift ;;
	--strip-diffstat)
		opt_strip_diffstat=1
		shift ;;
	--strip-trailing-whitespace)
		opt_strip_trailing_whitespace=1
		shift ;;
	-h)
		usage -h ;;
	--)
		shift
		break ;;
	esac
done

case "$opt_append$opt_replace$opt_edit"
in
''|1)	;;
*)	usage ;;
esac

if [ $# -gt 1 ]
then
	usage
fi

patch=$(find_patch_in_series "$1") || exit 1

patch_file=$(patch_file_name $patch)

if [ -z "$opt_replace" -a -z "$opt_append" -a -z "$opt_edit" ]
then
	[ -e "$patch_file" ] || exit 0

	setup_pager

	cat_file "$patch_file" \
	| patch_header \
	| maybe_strip_diffstat \
	| maybe_strip_trailing_whitespace
else
	patch_file_or_null=/dev/null
	[ -e "$patch_file" ] && patch_file_or_null=$patch_file

	tmp=$(gen_tempfile) || exit 1
	tmp2=$(gen_tempfile) || exit 1
	add_exit_handler "rm -f $tmp $tmp2"

	(	if [ -z "$opt_replace" ]
		then
			cat_file $patch_file_or_null | patch_header
		fi
		if [ -n "$opt_append" -o -n "$opt_replace" ]
		then
			cat
		fi
	) > $tmp

        # If triggered and file is empty, cat dep-3 headers into it
	if [ -n "$opt_use_dep3_headers" -a ! -s $tmp ]
	then
		cat >$tmp <<-END
		Description: <short description, required>
		 <long description that can span multiple lines, optional>
		Author: <name and email of author, optional>
		Origin: <upstream|backport|vendor|other>, <URL, required except if Author is present>
		Bug: <URL to the upstream bug report if any, implies patch has been forwarded, optional>
		Bug-<Vendor>: <URL to the vendor bug report if any, optional>
		Forwarded: <URL|no|not-needed, useless if you have a Bug field, optional>
		Applied-Upstream: <version|URL|commit, identifies patches merged upstream, optional>
		Reviewed-by: <name and email of a reviewer, optional>
		Last-Update: $(LC_ALL=C date +%Y-%m-%d) <YYYY-MM-DD, last update of the meta-information, optional>
		---
		This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
		END
        fi

	if [ -n "$opt_edit" ]
	then
		LANG=$ORIGINAL_LANG $EDITOR "$tmp" || exit 1
	fi

	maybe_strip_diffstat < $tmp \
	| maybe_strip_trailing_whitespace > $tmp2

	cat_file "$patch_file_or_null" | patch_body >> $tmp2 || exit 1

	if ( [ -z "$QUILT_BACKUP" -o ! -e $patch_file ] || \
	       mv $patch_file $patch_file~ ) && \
	       cat_to_new_file $patch_file < $tmp2
	then
		if [ -z "$opt_append" ]
		then
			printf \
$"Replaced header of patch %s\n" "$(print_patch $patch)"
		else
			printf \
$"Appended text to header of patch %s\n" "$(print_patch $patch)"
		fi
	else
		exit 1
	fi
fi
### Local Variables:
### mode: shell-script
### End:
# vim:filetype=sh