是否有任何命令可以从git补丁文件中发送/发送电子邮件和发送日期,还是必须从解析补丁文件中读取它?
答案 0 :(得分:0)
应该涉及解析,因为git apply
无效:
git apply --summary
正如您在任何t/t4100
/t-apply-*.expect文件中看到的那样,没有提及日期或电子邮件。
话虽如此,由于git format-patch
生成了Unix邮箱格式,您可以使用工具将 mailutils 添加到C中的parse such a file。
或者(更简单),perl script。
while (($line = <F>)) {
# set variables in order
chomp($line);
if ($line =~ /^From /){
$count++;
}
elsif ($line =~ /^Date:/){
($date_text,$date) = split(/:/,$line);
}
elsif ($line =~ /^From:/){
($from_text,$from) = split(/:/,$line);
}
elsif ($line =~ /^Subject:/){
($subject_text,$subject) = split(/:/,$line);
}
答案 1 :(得分:0)
formail命令(我认为通常与procmail一起发布)对于提取电子邮件标题非常有用:
formail -x Date < 0000-Some-commit.patch
与例如ad-hoc解析相比的一个不同之处在VonC的回答中发布的sed或简短的Perl脚本是它处理换行标题行。
Subject: The line is so long that
is has been wrapped.
对于Date,From和To行,这应该是不寻常的,但对于主题行来说是常见的。
甚至formail处理的另一个角落案例是根据RFC 2047编码的标题字段,如果该行包含除US-ASCII之外的任何内容,则必须使用该字段。
我建议您使用可用于您使用的语言的任何电子邮件/ MIME解析库。既然您在问题标题中提到了Python,那么这是一个简短的Python示例,用于从stdin读取git format-patch
创建的文件并打印其中的一些标题:
import email.header
import email.parser
import sys
def decode_header(s):
return ' '.join(
text.decode(charset) if charset else text
for text, charset in email.header.decode_header(s))
message = email.parser.Parser().parse(sys.stdin)
print decode_header(message['From'])
print decode_header(message['Date'])
print decode_header(message['Subject'])