Commit | Line | Data |
---|---|---|
d3d8f361 EB |
1 | #!/bin/sh |
2 | USAGE='--author <author> --patches </path/to/quilt/patch/directory>' | |
3 | SUBDIRECTORY_ON=Yes | |
4 | . git-sh-setup | |
5 | ||
6 | quilt_author="" | |
7 | while case "$#" in 0) break;; esac | |
8 | do | |
9 | case "$1" in | |
10 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) | |
11 | quilt_author=$(expr "$1" : '-[^=]*\(.*\)') | |
12 | shift | |
13 | ;; | |
14 | ||
15 | --au|--aut|--auth|--autho|--author) | |
16 | case "$#" in 1) usage ;; esac | |
17 | shift | |
18 | quilt_author="$1" | |
19 | shift | |
20 | ;; | |
21 | ||
22 | --pa=*|--pat=*|--patc=*|--patch=*|--patche=*|--patches=*) | |
23 | QUILT_PATCHES=$(expr "$1" : '-[^=]*\(.*\)') | |
24 | shift | |
25 | ;; | |
26 | ||
27 | --pa|--pat|--patc|--patch|--patche|--patches) | |
28 | case "$#" in 1) usage ;; esac | |
29 | shift | |
30 | QUILT_PATCHES="$1" | |
31 | shift | |
32 | ;; | |
33 | ||
34 | *) | |
35 | break | |
36 | ;; | |
37 | esac | |
38 | done | |
39 | ||
40 | # Quilt Author | |
41 | if [ -n "$quilt_author" ] ; then | |
42 | quilt_author_name=$(expr "z$quilt_author" : 'z\(.*[^ ]\) *<.*') && | |
43 | quilt_author_email=$(expr "z$quilt_author" : '.*<\([^>]*\)') && | |
44 | test '' != "$quilt_author_name" && | |
45 | test '' != "$quilt_author_email" || | |
46 | die "malformatted --author parameter" | |
47 | fi | |
48 | ||
49 | # Quilt patch directory | |
50 | : ${QUILT_PATCHES:=patches} | |
51 | if ! [ -d "$QUILT_PATCHES" ] ; then | |
52 | echo "The \"$QUILT_PATCHES\" directory does not exist." | |
53 | exit 1 | |
54 | fi | |
55 | ||
56 | # Temporay directories | |
57 | tmp_dir=.dotest | |
58 | tmp_msg="$tmp_dir/msg" | |
59 | tmp_patch="$tmp_dir/patch" | |
60 | tmp_info="$tmp_dir/info" | |
61 | ||
62 | ||
63 | # Find the intial commit | |
64 | commit=$(git-rev-parse HEAD) | |
65 | ||
66 | mkdir $tmp_dir || exit 2 | |
67 | for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do | |
68 | echo $patch_name | |
69 | (cat $QUILT_PATCHES/$patch_name | git-mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3 | |
70 | ||
71 | # Parse the author information | |
72 | export GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info") | |
73 | export GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info") | |
74 | while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do | |
75 | if [ -n "$quilt_author" ] ; then | |
76 | GIT_AUTHOR_NAME="$quilt_author_name"; | |
77 | GIT_AUTHOR_EMAIL="$quilt_author_email"; | |
78 | else | |
79 | echo "No author found in $patch_name"; | |
80 | echo "---" | |
81 | cat $tmp_msg | |
82 | echo -n "Author: "; | |
83 | read patch_author | |
84 | ||
85 | echo "$patch_author" | |
86 | ||
87 | patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') && | |
88 | patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') && | |
89 | test '' != "$patch_author_name" && | |
90 | test '' != "$patch_author_email" && | |
91 | GIT_AUTHOR_NAME="$patch_author_name" && | |
92 | GIT_AUTHOR_EMAIL="$patch_author_email" | |
93 | fi | |
94 | done | |
95 | export GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info") | |
96 | export SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info") | |
97 | if [ -z "$SUBJECT" ] ; then | |
98 | SUBJECT=$(echo $patch_name | sed -e 's/.patch$//') | |
99 | fi | |
100 | ||
101 | git-apply --index -C1 "$tmp_patch" && | |
102 | tree=$(git-write-tree) && | |
103 | commit=$((echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) && | |
104 | git-update-ref HEAD $commit || exit 4 | |
105 | done | |
106 | rm -rf $tmp_dir || exit 5 |