From 30c68814451d71716a8c6349584c82efe305e52f Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Mon, 15 Apr 2019 06:15:04 +0000 Subject: [PATCH] =?UTF-8?q?scripts/cherry=5Fpick=5Fpull.sh:=20=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7=E5=8A=A0=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 多行subject全取出,不截断 - 与PYTHONENCODING, locale设置无关,直接写utf-8输出 --- scripts/cherry_pick_pull.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/cherry_pick_pull.sh b/scripts/cherry_pick_pull.sh index f0e22870af..a7884803c4 100755 --- a/scripts/cherry_pick_pull.sh +++ b/scripts/cherry_pick_pull.sh @@ -156,6 +156,32 @@ EOF hub pull-request -F "${prtext}" -h "${GITHUB_USER}:${NEWBRANCH}" -b "${MAIN_REPO_ORG}:${rel}" } +function extract-subject { + local patch="$1" + + python -c ' +import os +import email.parser +import email.header +with open("'"$patch"'", "r") as f: + m = email.parser.Parser().parse(f, headersonly=True) +subj = m["subject"] +subj = email.header.decode_header(subj) +s = u"" +for txt, enc in subj: + txt = txt.decode(enc) if enc else txt + txt = txt.decode("ascii") if isinstance(txt, bytes) else txt + txt = txt.replace(u"\n", u"") + if txt.startswith(u"[PATCH"): + i = txt.index(u"]") + txt = txt[i+1:] + s += txt +s = s.strip() + u"\n" +s = s.encode("utf-8") # write out utf-8 bytes whatsoever +os.write(1, s) +' +} + git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}" cleanbranch="${NEWBRANCHUNIQ}" @@ -194,10 +220,7 @@ for pull in "${PULLS[@]}"; do } # set the subject - subject=$(grep -m 1 "^Subject" "/tmp/${pull}.patch" | sed -e 's/Subject: \[PATCH//g' | sed 's/.*] //') - subject_=$(echo "$subject" | python -c 'from email.header import decode_header as f; import sys; \ - s=sys.stdin.read(); v=f(s)[0]; print(v[0].decode(v[1]) if v[1] else v[0])') - [ -z "$subject_" ] || subject="$subject_" + subject=$(extract-subject "/tmp/${pull}.patch") SUBJECTS+=("#${pull}: ${subject}") # remove the patch file from /tmp