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