2 USAGE='--dry-run --author <author> --patches </path/to/quilt/patch/directory>'
8 while case "$#" in 0) break;; esac
11 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
12 quilt_author=$(expr "z$1" : 'z-[^=]*\(.*\)')
16 --au|--aut|--auth|--autho|--author)
17 case "$#" in 1) usage ;; esac
28 --pa=*|--pat=*|--patc=*|--patch=*|--patche=*|--patches=*)
29 QUILT_PATCHES=$(expr "z$1" : 'z-[^=]*\(.*\)')
33 --pa|--pat|--patc|--patch|--patche|--patches)
34 case "$#" in 1) usage ;; esac
47 if [ -n "$quilt_author" ] ; then
48 quilt_author_name=$(expr "z$quilt_author" : 'z\(.*[^ ]\) *<.*') &&
49 quilt_author_email=$(expr "z$quilt_author" : '.*<\([^>]*\)') &&
50 test '' != "$quilt_author_name" &&
51 test '' != "$quilt_author_email" ||
52 die "malformed --author parameter"
55 # Quilt patch directory
56 : ${QUILT_PATCHES:=patches}
57 if ! [ -d "$QUILT_PATCHES" ] ; then
58 echo "The \"$QUILT_PATCHES\" directory does not exist."
62 # Temporary directories
64 tmp_msg="$tmp_dir/msg"
65 tmp_patch="$tmp_dir/patch"
66 tmp_info="$tmp_dir/info"
69 # Find the intial commit
70 commit=$(git-rev-parse HEAD)
72 mkdir $tmp_dir || exit 2
73 for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
75 (cat $QUILT_PATCHES/$patch_name | git-mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3
76 test -s .dotest/patch || {
77 echo "Patch is empty. Was is split wrong?"
81 # Parse the author information
82 export GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
83 export GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
84 while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
85 if [ -n "$quilt_author" ] ; then
86 GIT_AUTHOR_NAME="$quilt_author_name";
87 GIT_AUTHOR_EMAIL="$quilt_author_email";
88 elif [ -n "$dry_run" ]; then
89 echo "No author found in $patch_name" >&2;
90 GIT_AUTHOR_NAME="dry-run-not-found";
91 GIT_AUTHOR_EMAIL="dry-run-not-found";
93 echo "No author found in $patch_name" >&2;
101 patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') &&
102 patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') &&
103 test '' != "$patch_author_name" &&
104 test '' != "$patch_author_email" &&
105 GIT_AUTHOR_NAME="$patch_author_name" &&
106 GIT_AUTHOR_EMAIL="$patch_author_email"
109 export GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info")
110 export SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info")
111 if [ -z "$SUBJECT" ] ; then
112 SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
115 if [ -z "$dry_run" ] ; then
116 git-apply --index -C1 "$tmp_patch" &&
117 tree=$(git-write-tree) &&
118 commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) &&
119 git-update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
122 rm -rf $tmp_dir || exit 5