]>
Commit | Line | Data |
---|---|---|
d3d8f361 | 1 | #!/bin/sh |
e01fbf1a | 2 | OPTIONS_KEEPDASHDASH= |
51ba8ce3 | 3 | OPTIONS_STUCKLONG= |
e01fbf1a | 4 | OPTIONS_SPEC="\ |
1b1dd23f | 5 | git quiltimport [options] |
e01fbf1a PH |
6 | -- |
7 | n,dry-run dry run | |
8 | author= author name and email address for patches without any | |
ff60ffdc JH |
9 | patches= path to the quilt patches |
10 | series= path to the quilt series file | |
1eadaa39 | 11 | keep-non-patch Pass -b to git mailinfo |
e01fbf1a | 12 | " |
d3d8f361 EB |
13 | SUBDIRECTORY_ON=Yes |
14 | . git-sh-setup | |
15 | ||
d3bd4ee1 | 16 | dry_run="" |
d3d8f361 | 17 | quilt_author="" |
822f7c73 | 18 | while test $# != 0 |
d3d8f361 EB |
19 | do |
20 | case "$1" in | |
e01fbf1a | 21 | --author) |
d3d8f361 EB |
22 | shift |
23 | quilt_author="$1" | |
d3d8f361 | 24 | ;; |
e01fbf1a | 25 | -n|--dry-run) |
d3bd4ee1 EB |
26 | dry_run=1 |
27 | ;; | |
e01fbf1a | 28 | --patches) |
d3d8f361 | 29 | shift |
9e384b45 | 30 | QUILT_PATCHES="$1" |
d3d8f361 | 31 | ;; |
ff60ffdc JH |
32 | --series) |
33 | shift | |
34 | QUILT_SERIES="$1" | |
35 | ;; | |
1eadaa39 LA |
36 | --keep-non-patch) |
37 | MAILINFO_OPT="-b" | |
38 | ;; | |
e01fbf1a PH |
39 | --) |
40 | shift | |
41 | break;; | |
d3d8f361 | 42 | *) |
e01fbf1a | 43 | usage |
d3d8f361 EB |
44 | ;; |
45 | esac | |
e01fbf1a | 46 | shift |
d3d8f361 EB |
47 | done |
48 | ||
49 | # Quilt Author | |
50 | if [ -n "$quilt_author" ] ; then | |
51 | quilt_author_name=$(expr "z$quilt_author" : 'z\(.*[^ ]\) *<.*') && | |
52 | quilt_author_email=$(expr "z$quilt_author" : '.*<\([^>]*\)') && | |
53 | test '' != "$quilt_author_name" && | |
54 | test '' != "$quilt_author_email" || | |
82e5a82f | 55 | die "malformed --author parameter" |
d3d8f361 EB |
56 | fi |
57 | ||
58 | # Quilt patch directory | |
59 | : ${QUILT_PATCHES:=patches} | |
60 | if ! [ -d "$QUILT_PATCHES" ] ; then | |
61 | echo "The \"$QUILT_PATCHES\" directory does not exist." | |
62 | exit 1 | |
63 | fi | |
64 | ||
ff60ffdc JH |
65 | # Quilt series file |
66 | : ${QUILT_SERIES:=$QUILT_PATCHES/series} | |
67 | if ! [ -e "$QUILT_SERIES" ] ; then | |
68 | echo "The \"$QUILT_SERIES\" file does not exist." | |
69 | exit 1 | |
70 | fi | |
71 | ||
3dff5379 | 72 | # Temporary directories |
51ef1daa | 73 | tmp_dir="$GIT_DIR"/rebase-apply |
d3d8f361 EB |
74 | tmp_msg="$tmp_dir/msg" |
75 | tmp_patch="$tmp_dir/patch" | |
76 | tmp_info="$tmp_dir/info" | |
77 | ||
78 | ||
41ccfdd9 | 79 | # Find the initial commit |
5be60078 | 80 | commit=$(git rev-parse HEAD) |
d3d8f361 EB |
81 | |
82 | mkdir $tmp_dir || exit 2 | |
6ab149ea | 83 | while read patch_name level garbage <&3 |
9dd5bded PH |
84 | do |
85 | case "$patch_name" in ''|'#'*) continue;; esac | |
86 | case "$level" in | |
18d077c1 | 87 | -p*) ;; |
9dd5bded PH |
88 | ''|'#'*) |
89 | level=;; | |
90 | *) | |
91 | echo "unable to parse patch level, ignoring it." | |
92 | level=;; | |
93 | esac | |
94 | case "$garbage" in | |
95 | ''|'#'*);; | |
96 | *) | |
97 | echo "trailing garbage found in series file: $garbage" | |
98 | exit 1;; | |
99 | esac | |
9f569fe5 DN |
100 | if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then |
101 | echo "$patch_name doesn't exist. Skipping." | |
102 | continue | |
103 | fi | |
d3d8f361 | 104 | echo $patch_name |
1eadaa39 | 105 | git mailinfo $MAILINFO_OPT "$tmp_msg" "$tmp_patch" \ |
9d6f220c JT |
106 | <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3 |
107 | test -s "$tmp_patch" || { | |
7d4f4a2f | 108 | echo "Patch is empty. Was it split wrong?" |
1fa9bf36 | 109 | exit 1 |
87ab7992 | 110 | } |
d3d8f361 EB |
111 | |
112 | # Parse the author information | |
3addc94a JS |
113 | GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info") |
114 | GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info") | |
115 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL | |
d3d8f361 EB |
116 | while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do |
117 | if [ -n "$quilt_author" ] ; then | |
118 | GIT_AUTHOR_NAME="$quilt_author_name"; | |
119 | GIT_AUTHOR_EMAIL="$quilt_author_email"; | |
d3bd4ee1 EB |
120 | elif [ -n "$dry_run" ]; then |
121 | echo "No author found in $patch_name" >&2; | |
122 | GIT_AUTHOR_NAME="dry-run-not-found"; | |
123 | GIT_AUTHOR_EMAIL="dry-run-not-found"; | |
d3d8f361 | 124 | else |
d3bd4ee1 | 125 | echo "No author found in $patch_name" >&2; |
d3d8f361 EB |
126 | echo "---" |
127 | cat $tmp_msg | |
2aad957a | 128 | printf "Author: "; |
d3d8f361 EB |
129 | read patch_author |
130 | ||
131 | echo "$patch_author" | |
132 | ||
133 | patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') && | |
134 | patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') && | |
135 | test '' != "$patch_author_name" && | |
136 | test '' != "$patch_author_email" && | |
137 | GIT_AUTHOR_NAME="$patch_author_name" && | |
138 | GIT_AUTHOR_EMAIL="$patch_author_email" | |
139 | fi | |
140 | done | |
3addc94a JS |
141 | GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info") |
142 | SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info") | |
143 | export GIT_AUTHOR_DATE SUBJECT | |
d3d8f361 EB |
144 | if [ -z "$SUBJECT" ] ; then |
145 | SUBJECT=$(echo $patch_name | sed -e 's/.patch$//') | |
146 | fi | |
147 | ||
d3bd4ee1 | 148 | if [ -z "$dry_run" ] ; then |
18d077c1 | 149 | git apply --index -C1 ${level:+"$level"} "$tmp_patch" && |
5be60078 JH |
150 | tree=$(git write-tree) && |
151 | commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) && | |
152 | git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 | |
d3bd4ee1 | 153 | fi |
ff60ffdc | 154 | done 3<"$QUILT_SERIES" |
d3d8f361 | 155 | rm -rf $tmp_dir || exit 5 |