diff options
Diffstat (limited to 'meta/recipes-devtools/guilt/files/guilt.patch')
-rw-r--r-- | meta/recipes-devtools/guilt/files/guilt.patch | 317 |
1 files changed, 317 insertions, 0 deletions
diff --git a/meta/recipes-devtools/guilt/files/guilt.patch b/meta/recipes-devtools/guilt/files/guilt.patch new file mode 100644 index 0000000000..a3352cf810 --- /dev/null +++ b/meta/recipes-devtools/guilt/files/guilt.patch | |||
@@ -0,0 +1,317 @@ | |||
1 | guilt: enhanced patch queue management | ||
2 | |||
3 | guilt prefers to track the status and series of patches | ||
4 | under .git/patches. But this location doesn't allow the | ||
5 | status of a quilt queue to be committed to a secondary | ||
6 | repository and later restored. | ||
7 | |||
8 | This change does three things: | ||
9 | |||
10 | - allows GUILT_BASE to be changed (with a default to "wrs") | ||
11 | - allows shadow tracking of the patches (for rebase) | ||
12 | - enhances the header detection and creation of patches | ||
13 | as they are pushed onto the tree. | ||
14 | |||
15 | Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com> | ||
16 | |||
17 | --- | ||
18 | guilt | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- | ||
19 | 1 file changed, 159 insertions(+), 24 deletions(-) | ||
20 | |||
21 | --- a/guilt | ||
22 | +++ b/guilt | ||
23 | @@ -153,14 +153,16 @@ get_branch() | ||
24 | |||
25 | verify_branch() | ||
26 | { | ||
27 | - [ ! -d "$GIT_DIR/patches" ] && | ||
28 | + [ ! -d "$GUILT_DIR" ] && | ||
29 | die "Patches directory doesn't exist, try guilt-init" | ||
30 | - [ ! -d "$GIT_DIR/patches/$branch" ] && | ||
31 | + [ ! -d "$GUILT_DIR/$branch" ] && | ||
32 | die "Branch $branch is not initialized, try guilt-init" | ||
33 | - [ ! -f "$GIT_DIR/patches/$branch/series" ] && | ||
34 | + [ ! -f "$GUILT_DIR/$branch/series" ] && | ||
35 | die "Branch $branch does not have a series file" | ||
36 | - [ ! -f "$GIT_DIR/patches/$branch/status" ] && | ||
37 | + [ ! -f "$GUILT_DIR/$branch/status" ] && | ||
38 | die "Branch $branch does not have a status file" | ||
39 | + [ -f "$GUILT_DIR/$branch/applied" ] && | ||
40 | + die "Warning: Branch $branch has 'applied' file - guilt is not compatible with stgit" | ||
41 | [ -f "$GIT_DIR/patches/$branch/applied" ] && | ||
42 | die "Warning: Branch $branch has 'applied' file - guilt is not compatible with stgit" | ||
43 | } | ||
44 | @@ -339,6 +341,17 @@ BEGIN{} | ||
45 | ' | ||
46 | } | ||
47 | |||
48 | +# usage: do_get_only_patch patchfile | ||
49 | +# similar to do_get_patch except everything leading up to | ||
50 | +# the first diff line and after the last chunk are removed | ||
51 | +do_get_only_patch() | ||
52 | +{ | ||
53 | + cat "$1" | awk ' | ||
54 | +BEGIN{} | ||
55 | +/^(diff )/,/^(-- |END{})/ | ||
56 | +' | sed '/^-- *$/D' | ||
57 | +} | ||
58 | + | ||
59 | # usage: do_get_header patchfile | ||
60 | do_get_header() | ||
61 | { | ||
62 | @@ -352,8 +365,13 @@ do_get_header() | ||
63 | BEGIN{skip=0} | ||
64 | /^Subject:/ && (NR==1){print substr($0, 10); next} | ||
65 | /^From:/{skip=1; next} | ||
66 | +/^Author:/{skip=1; next} | ||
67 | +/^Date:/{skip=1; next} | ||
68 | +/^commit/{skip=1; next} | ||
69 | /^[ \t\f\n\r\v]*$/ && (skip==1){skip=0; next} | ||
70 | /^(diff |---$|--- )/{exit} | ||
71 | +/^diff --git/{exit} | ||
72 | +/^Index: /{exit} | ||
73 | {print $0} | ||
74 | END{} | ||
75 | ' | ||
76 | @@ -415,6 +433,15 @@ series_insert_patch() | ||
77 | mv "$series.tmp" "$series" | ||
78 | } | ||
79 | |||
80 | +series_append_patch() | ||
81 | +{ | ||
82 | + # unlike series_insert_patch, which inserts the passed | ||
83 | + # patch after the current top patch, this function always | ||
84 | + # appends the patch to the series | ||
85 | + | ||
86 | + echo $1 >> "$series" | ||
87 | +} | ||
88 | + | ||
89 | # usage: series_remove_patch <patchname> | ||
90 | series_remove_patch() | ||
91 | { | ||
92 | @@ -473,8 +500,7 @@ remove_patch_refs() | ||
93 | # usage: pop_many_patches <commitish> <number of patches> | ||
94 | pop_many_patches() | ||
95 | { | ||
96 | - assert_head_check | ||
97 | - | ||
98 | + head_check "`tail -1 < "$applied" | cut -d: -f 1`" | ||
99 | ( | ||
100 | cd_to_toplevel | ||
101 | |||
102 | @@ -508,50 +534,149 @@ remove_ref() | ||
103 | ) | ||
104 | } | ||
105 | |||
106 | +prep_patch() | ||
107 | +{ | ||
108 | + patch=$1; | ||
109 | + tgt=$2; | ||
110 | + | ||
111 | + if test -f $patch; then | ||
112 | + case $patch in | ||
113 | + *.gz) gzip -dc $patch > $tgt ;; | ||
114 | + *.bz2) bzip2 -dc $patch > $tgt ;; | ||
115 | + *) cp $patch $tgt ;; | ||
116 | + esac; | ||
117 | + fi; | ||
118 | +} | ||
119 | + | ||
120 | # usage: commit patchname parent | ||
121 | commit() | ||
122 | { | ||
123 | ( | ||
124 | TMP_MSG=`get_tmp_file msg` | ||
125 | + TMP_PATCH=`get_tmp_file patch` | ||
126 | + TMP_PATCH_OUT=`get_tmp_file patch_out` | ||
127 | + TMP_INFO=`get_tmp_file info` | ||
128 | |||
129 | p="$GUILT_DIR/$branch/$1" | ||
130 | pname="$1" | ||
131 | + prep_patch "$p" "$TMP_PATCH" | ||
132 | + p=$TMP_PATCH | ||
133 | + | ||
134 | cd_to_toplevel | ||
135 | |||
136 | git diff-files --name-only | (while read n; do git update-index "$n" ; done) | ||
137 | |||
138 | + # borrowed from git-am | ||
139 | + header_type=git | ||
140 | + git mailinfo "$TMP_MSG" "$TMP_PATCH_OUT" \ | ||
141 | + <"$p" >"$TMP_INFO"; | ||
142 | + | ||
143 | + # skip pine's internal folder data | ||
144 | + grep '^Author: Mail System Internal Data$' \ | ||
145 | + <"$TMP_INFO" >/dev/null | ||
146 | + | ||
147 | + git stripspace < "$TMP_MSG" > "$TMP_MSG.clean" | ||
148 | + mv "$TMP_MSG.clean" "$TMP_MSG" | ||
149 | + git stripspace < "$TMP_INFO" > "$TMP_INFO.clean" | ||
150 | + mv "$TMP_INFO.clean" "$TMP_INFO" | ||
151 | + | ||
152 | + # If mailinfo couldn't get something , try another way | ||
153 | # grab a commit message out of the patch | ||
154 | - do_get_header "$p" > "$TMP_MSG" | ||
155 | + if [ ! -s "$TMP_MSG" ] || [ ! -s "$TMP_INFO" ]; then | ||
156 | + do_get_header "$p" > "$TMP_MSG" | ||
157 | + header_type=guilt | ||
158 | + fi | ||
159 | |||
160 | - # make a default commit message if patch doesn't contain one | ||
161 | - [ ! -s "$TMP_MSG" ] && echo "patch $pname" > "$TMP_MSG" | ||
162 | + # last try: make a default commit message if patch doesn't contain one | ||
163 | + [ ! -s "$TMP_MSG" ] && echo "auto_msg: patch $pname" > "$TMP_MSG" | ||
164 | |||
165 | - # extract a From line from the patch header, and set | ||
166 | - # GIT_AUTHOR_{NAME,EMAIL} | ||
167 | - author_str=`sed -n -e '/^From:/ { s/^From: //; p; q; }; /^(diff |---$|--- )/ q' "$p"` | ||
168 | - if [ ! -z "$author_str" ]; then | ||
169 | + | ||
170 | + if [ "$header_type" = "guilt" ]; then | ||
171 | + | ||
172 | + # extract a From line from the patch header, and set | ||
173 | + # GIT_AUTHOR_{NAME,EMAIL} | ||
174 | + author_str=`sed -n -e '/^From:/ { s/^From: //; p; q }; /^(diff |---)/ q' "$p"` | ||
175 | + if [ ! -z "$author_str" ]; then | ||
176 | GIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'` | ||
177 | export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-" "}" | ||
178 | export GIT_AUTHOR_EMAIL="`echo $author_str | sed -e 's/[^<]*//'`" | ||
179 | - fi | ||
180 | + fi | ||
181 | + | ||
182 | + | ||
183 | + # check in the patch for a subject | ||
184 | + SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$p")" | ||
185 | + if [ -z "$SUBJECT" ]; then | ||
186 | + # if we can't find a subject in the patch, then let's construct | ||
187 | + # one from the header of the patch itself | ||
188 | + SUBJECT=`cat "$TMP_MSG" | head -n 1` | ||
189 | + if [ ${#SUBJECT} -gt 60 ]; then | ||
190 | + SUBJECT=${SUBJECT: -60} | ||
191 | + fi | ||
192 | + fi | ||
193 | + | ||
194 | + if [ -z "$SUBJECT" ]; then | ||
195 | + # if we are *still* without a subject, then just use | ||
196 | + # the patch name | ||
197 | + SUBJECT=`echo $1 | sed 's%^patch *%%'` | ||
198 | + | ||
199 | + if [ ${#SUBJECT} -gt 60 ]; then | ||
200 | + SUBJECT=${SUBJECT: -60} | ||
201 | + fi | ||
202 | + fi | ||
203 | |||
204 | - # must strip nano-second part otherwise git gets very | ||
205 | - # confused, and makes up strange timestamps from the past | ||
206 | - # (chances are it decides to interpret it as a unix | ||
207 | - # timestamp). | ||
208 | - export GIT_AUTHOR_DATE="`stat -c %y "$p" | sed -e ' | ||
209 | + SUBJECT=`echo $SUBJECT | sed s'%^ *%%'` | ||
210 | + | ||
211 | + if [ ! -z "$SUBJECT" ]; then | ||
212 | + echo "$SUBJECT" >> $TMP_MSG.subject | ||
213 | + echo "" >> $TMP_MSG.subject | ||
214 | + cat "$TMP_MSG" >> $TMP_MSG.subject | ||
215 | + mv "$TMP_MSG.subject" "$TMP_MSG" | ||
216 | + fi | ||
217 | + | ||
218 | + # must strip nano-second part otherwise git gets very | ||
219 | + # confused, and makes up strange timestamps from the past | ||
220 | + # (chances are it decides to interpret it as a unix | ||
221 | + # timestamp). | ||
222 | + export GIT_AUTHOR_DATE="`stat -c %y "$p" | sed -e '\ | ||
223 | s/^\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\) \([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)\.[0-9]* \(.*\)$/\1-\2-\3 \4:\5:\6 \7/'`" | ||
224 | - export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" | ||
225 | + export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" | ||
226 | + else | ||
227 | + # using git headers, closely related to git-am | ||
228 | + | ||
229 | + GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$TMP_INFO")" | ||
230 | + GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$TMP_INFO")" | ||
231 | + GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$TMP_INFO")" | ||
232 | + if test -z "$GIT_AUTHOR_EMAIL" | ||
233 | + then | ||
234 | + echo "Warning: patch does not have a valid e-mail address." | ||
235 | + GIT_AUTHOR_EMAIL=$GIT_AUTHOR_NAME | ||
236 | + fi | ||
237 | + | ||
238 | + SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$TMP_INFO")" | ||
239 | + if [ ! -z "$SUBJECT" ]; then | ||
240 | + echo "$SUBJECT" >> $TMP_MSG.subject | ||
241 | + echo "" >> $TMP_MSG.subject | ||
242 | + cat "$TMP_MSG" >> $TMP_MSG.subject | ||
243 | + mv "$TMP_MSG.subject" "$TMP_MSG" | ||
244 | + fi | ||
245 | + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE | ||
246 | + fi | ||
247 | |||
248 | # commit | ||
249 | treeish=`git write-tree` | ||
250 | commitish=`git commit-tree $treeish -p $2 < "$TMP_MSG"` | ||
251 | + if [ ! $? -eq 0 ]; then | ||
252 | + echo "ERROR. Could not commit tree" | ||
253 | + git-reset --hard HEAD^ | ||
254 | + exit 1 | ||
255 | + fi | ||
256 | git update-ref HEAD $commitish | ||
257 | |||
258 | # mark patch as applied | ||
259 | git update-ref "refs/patches/$branch/$pname" HEAD | ||
260 | |||
261 | - rm -f "$TMP_MSG" | ||
262 | + rm -f "$TMP_MSG" "$TMP_LOG" "$TMP_PATCH" "$TMP_INFO" "$TMP_PATCH_OUT" | ||
263 | + | ||
264 | ) | ||
265 | } | ||
266 | |||
267 | @@ -568,7 +693,7 @@ push_patch() | ||
268 | bail_action="$2" | ||
269 | reject="--reject" | ||
270 | |||
271 | - assert_head_check | ||
272 | + head_check "`tail -1 < "$applied" | cut -d: -f 1`" | ||
273 | cd_to_toplevel | ||
274 | |||
275 | # apply the patch if and only if there is something to apply | ||
276 | @@ -671,7 +796,7 @@ refresh_patch() | ||
277 | # incldiffstat | ||
278 | __refresh_patch() | ||
279 | { | ||
280 | - assert_head_check | ||
281 | + head_check "`tail -1 < "$applied" | cut -d: -f 1`" | ||
282 | |||
283 | ( | ||
284 | TMP_DIFF=`get_tmp_file diff` | ||
285 | @@ -711,6 +836,10 @@ __refresh_patch() | ||
286 | |||
287 | head -n "-$N" < "$applied" > "$applied.tmp" | ||
288 | mv "$applied.tmp" "$applied" | ||
289 | + | ||
290 | + # update the shadow status. | ||
291 | + ref=`cat $GIT_DIR/refs/tags/${branch}_top` | ||
292 | + echo "$ref:$1" >> $applied_shadow | ||
293 | ) | ||
294 | } | ||
295 | |||
296 | @@ -791,7 +920,12 @@ diffstat=`git config --bool guilt.diffst | ||
297 | # The following gets run every time this file is source'd | ||
298 | # | ||
299 | |||
300 | -GUILT_DIR="$GIT_DIR/patches" | ||
301 | + | ||
302 | +# GUILT_DIR="$GIT_DIR/patches" | ||
303 | +if [ -z "$GUILT_BASE" ]; then | ||
304 | + GUILT_BASE=wrs | ||
305 | +fi | ||
306 | +GUILT_DIR="$GUILT_BASE/patches" | ||
307 | |||
308 | branch=`get_branch` | ||
309 | |||
310 | @@ -814,6 +948,7 @@ fi | ||
311 | # very useful files | ||
312 | series="$GUILT_DIR/$branch/series" | ||
313 | applied="$GUILT_DIR/$branch/status" | ||
314 | +applied_shadow="$GUILT_DIR/$branch/shadow_status" | ||
315 | guards_file="$GUILT_DIR/$branch/guards" | ||
316 | |||
317 | # determine a pager to use for anything interactive (fall back to more) | ||