ref: e43ded677ea2a176f637ce90a6fa1b2ec038d09b
dir: /import/
#!/bin/rc rfork ne . /sys/lib/git/common.rc diffpath=/tmp/gitimport.$pid.diff fn sigexit { rm -f $diffpath } fn apply @{ /$cputype/bin/git/fs email='' name='' msg='' parents='-p'^`{/$cputype/bin/git/query HEAD} branch=`{/$cputypeb/in/git/branch} if(test -e /mnt/git/branch/$branch/tree) refpath=.git/refs/$branch if not if(test -e /mnt/git/object/$branch/tree) refpath=.git/HEAD if not die 'invalid branch:' $branch awk ' BEGIN{ state="headers" } state=="headers" && /^From:/ { sub(/^From:[ \t]*/, "", $0); name=$0; email=$0; sub(/[ \t]*<.*$/, "", name); sub(/.*</, "", email); sub(/>/, "", email); } state=="headers" && /^Date:/{ sub(/^Date:[ \t]*/, "", $0) date=$0 } state=="headers" && /^Subject:/{ sub(/^Subject:[ \t]*(\[PATCH( [0-9]+\/[0-9]+)?\])*[ \t]*/, "", $0); gotmsg = 1 print > "/env/msg" } state=="headers" && /^$/ { state="body" next } (state=="headers" || state=="body") && (/^diff/ || /^---[ ]*$/){ state="diff" print > ENVIRON["diffpath"] } state=="body" { if(didthis == 0){ printf "\n" > "/env/msg" didthis = 1 } print > "/env/msg" } state=="diff" { print > ENVIRON["diffpath"] } END{ if(state != "diff") exit("malformed patch: " state); if(name == "" || email == "" || date == "" || gotmsg == "") exit("missing headers"); printf "%s", name > "/env/name" printf "%s", email > "/env/email" printf "%s", date > "/env/date" } ' || die 'could not import:' $status # force re-reading env rc -c ' echo applying $msg | sed 1q date=`{seconds $date} files=`$nl{ape/patch -Ep1 < $diffpath | sed ''s/^patching file `(.*)''''/\1/''} for(f in $files){ if(test -e $f) /$cputype/bin/git/add $f if not /$cputype/bin/git/add -r $f } /$cputype/bin/git/walk -fRMA $files hash=`{/$cputype/bin/git/save -n $name -e $email -m $msg -d $date $parents $files} echo $hash > $refpath ' } gitup flagfmt=''; args='file ...' eval `''{aux/getflags $*} || exec aux/usage patches=(/fd/0) if(! ~ $#* 0) patches=$* for(f in $patches) apply < $f || die $status exit ''