2021-05-17 01:49:45 +00:00
|
|
|
#!/bin/rc
|
|
|
|
rfork ne
|
|
|
|
. /sys/lib/git/common.rc
|
|
|
|
|
|
|
|
diffpath=/tmp/gitimport.$pid.diff
|
|
|
|
fn sigexit {
|
|
|
|
rm -f $diffpath
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:47:18 +00:00
|
|
|
|
2021-05-17 01:49:45 +00:00
|
|
|
fn apply @{
|
|
|
|
git/fs
|
2021-09-03 02:47:18 +00:00
|
|
|
amail=''
|
|
|
|
aname=''
|
2021-05-17 01:49:45 +00:00
|
|
|
msg=''
|
2021-09-03 02:47:18 +00:00
|
|
|
whoami
|
2021-05-17 01:49:45 +00:00
|
|
|
parents='-p'^`{git/query HEAD}
|
|
|
|
branch=`{git/branch}
|
2021-05-31 00:46:21 +00:00
|
|
|
if(test -e $gitfs/branch/$branch/tree)
|
2021-05-17 01:49:45 +00:00
|
|
|
refpath=.git/refs/$branch
|
2021-05-31 00:46:21 +00:00
|
|
|
if not if(test -e $gitfs/object/$branch/tree)
|
2021-05-17 01:49:45 +00:00
|
|
|
refpath=.git/HEAD
|
|
|
|
if not
|
|
|
|
die 'invalid branch:' $branch
|
|
|
|
awk '
|
|
|
|
BEGIN{
|
|
|
|
state="headers"
|
|
|
|
}
|
|
|
|
state=="headers" && /^From:/ {
|
|
|
|
sub(/^From:[ \t]*/, "", $0);
|
2021-09-03 02:47:18 +00:00
|
|
|
aname=$0;
|
|
|
|
amail=$0;
|
|
|
|
sub(/[ \t]*<.*$/, "", aname);
|
|
|
|
sub(/^[^<]*</, "", amail);
|
|
|
|
sub(/>[^>]*$/, "", amail);
|
2021-05-17 01:49:45 +00:00
|
|
|
}
|
|
|
|
state=="headers" && /^Date:/{
|
|
|
|
sub(/^Date:[ \t]*/, "", $0)
|
|
|
|
date=$0
|
|
|
|
}
|
|
|
|
state=="headers" && /^Subject:/{
|
2021-06-15 21:29:22 +00:00
|
|
|
sub(/^Subject:[ \t]*(\[[^\]]*\][ \t]*)*/, "", $0);
|
2021-05-17 01:49:45 +00:00
|
|
|
gotmsg = 1
|
|
|
|
print > "/env/msg"
|
|
|
|
}
|
|
|
|
state=="headers" && /^$/ {
|
|
|
|
state="body"
|
|
|
|
next
|
|
|
|
}
|
2021-09-03 02:47:18 +00:00
|
|
|
(state=="headers" || state=="body") && (/^diff / || /^---( |$)/){
|
2021-05-17 01:49:45 +00:00
|
|
|
state="diff"
|
|
|
|
}
|
|
|
|
state=="body" {
|
|
|
|
print > "/env/msg"
|
|
|
|
}
|
|
|
|
state=="diff" {
|
|
|
|
print > ENVIRON["diffpath"]
|
|
|
|
}
|
|
|
|
END{
|
|
|
|
if(state != "diff")
|
|
|
|
exit("malformed patch: " state);
|
2021-09-03 02:47:18 +00:00
|
|
|
if(aname == "" || amail == "" || date == "" || gotmsg == "")
|
2021-05-17 01:49:45 +00:00
|
|
|
exit("missing headers");
|
2021-09-03 02:47:18 +00:00
|
|
|
printf "%s", aname > "/env/aname"
|
|
|
|
printf "%s", amail > "/env/amail"
|
2021-05-17 01:49:45 +00:00
|
|
|
printf "%s", date > "/env/date"
|
|
|
|
}
|
|
|
|
' || die 'could not import:' $status
|
|
|
|
|
|
|
|
# force re-reading env
|
|
|
|
rc -c '
|
|
|
|
echo applying $msg | sed 1q
|
|
|
|
date=`{seconds $date}
|
|
|
|
if(! files=`$nl{ape/patch -Ep1 < $diffpath | grep ''^patching file'' | sed ''s/^patching file `(.*)''''/\1/''})
|
|
|
|
die ''patch failed''
|
|
|
|
for(f in $files){
|
|
|
|
if(test -e $f)
|
|
|
|
git/add $f
|
|
|
|
if not
|
|
|
|
git/add -r $f
|
|
|
|
}
|
|
|
|
git/walk -fRMA $files
|
|
|
|
if(~ $#nocommit 0){
|
2021-09-03 02:47:18 +00:00
|
|
|
if(hash=`{git/save -n $aname -e $amail -N $name -E $email -m $msg -d $date $parents $files})
|
|
|
|
echo $hash > $refpath
|
2021-05-17 01:49:45 +00:00
|
|
|
}
|
|
|
|
status=''''
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
gitup
|
|
|
|
|
|
|
|
flagfmt='n:nocommit'; args='file ...'
|
|
|
|
eval `''{aux/getflags $*} || exec aux/usage
|
|
|
|
|
|
|
|
patches=(/fd/0)
|
|
|
|
if(! ~ $#* 0)
|
|
|
|
patches=$*
|
2021-06-15 21:29:22 +00:00
|
|
|
for(p in $patches){
|
|
|
|
# upas serves the decoded header and body separately,
|
|
|
|
# so we cat them together when applying a upas message.
|
|
|
|
#
|
|
|
|
# this allows mime-encoded or line-wrapped patches.
|
|
|
|
if(test -d $p && test -f $p/header && test -f $p/body)
|
|
|
|
{{cat $p/header; echo; cat $p/body} | apply} || die $status
|
|
|
|
if not
|
|
|
|
apply < $p || die $status
|
|
|
|
}
|
2021-05-17 01:49:45 +00:00
|
|
|
exit ''
|