]>
Commit | Line | Data |
---|---|---|
d3d8f361 | 1 | #!/bin/sh |
d3bd4ee1 | 2 | USAGE='--dry-run --author <author> --patches </path/to/quilt/patch/directory>' |
d3d8f361 EB |
3 | SUBDIRECTORY_ON=Yes |
4 | . git-sh-setup | |
5 | ||
d3bd4ee1 | 6 | dry_run="" |
d3d8f361 | 7 | quilt_author="" |
822f7c73 | 8 | while test $# != 0 |
d3d8f361 EB |
9 | do |
10 | case "$1" in | |
11 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) | |
8096fae7 | 12 | quilt_author=$(expr "z$1" : 'z-[^=]*\(.*\)') |
d3d8f361 EB |
13 | shift |
14 | ;; | |
15 | ||
16 | --au|--aut|--auth|--autho|--author) | |
17 | case "$#" in 1) usage ;; esac | |
18 | shift | |
19 | quilt_author="$1" | |
20 | shift | |
21 | ;; | |
22 | ||
d3bd4ee1 EB |
23 | --dry-run) |
24 | shift | |
25 | dry_run=1 | |
26 | ;; | |
27 | ||
d3d8f361 | 28 | --pa=*|--pat=*|--patc=*|--patch=*|--patche=*|--patches=*) |
8096fae7 | 29 | QUILT_PATCHES=$(expr "z$1" : 'z-[^=]*\(.*\)') |
d3d8f361 EB |
30 | shift |
31 | ;; | |
32 | ||
33 | --pa|--pat|--patc|--patch|--patche|--patches) | |
34 | case "$#" in 1) usage ;; esac | |
35 | shift | |
36 | QUILT_PATCHES="$1" | |
37 | shift | |
38 | ;; | |
39 | ||
40 | *) | |
41 | break | |
42 | ;; | |
43 | esac | |
44 | done | |
45 | ||
46 | # Quilt Author | |
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" || | |
82e5a82f | 52 | die "malformed --author parameter" |
d3d8f361 EB |
53 | fi |
54 | ||
55 | # Quilt patch directory | |
56 | : ${QUILT_PATCHES:=patches} | |
57 | if ! [ -d "$QUILT_PATCHES" ] ; then | |
58 | echo "The \"$QUILT_PATCHES\" directory does not exist." | |
59 | exit 1 | |
60 | fi | |
61 | ||
3dff5379 | 62 | # Temporary directories |
d3d8f361 EB |
63 | tmp_dir=.dotest |
64 | tmp_msg="$tmp_dir/msg" | |
65 | tmp_patch="$tmp_dir/patch" | |
66 | tmp_info="$tmp_dir/info" | |
67 | ||
68 | ||
69 | # Find the intial commit | |
5be60078 | 70 | commit=$(git rev-parse HEAD) |
d3d8f361 EB |
71 | |
72 | mkdir $tmp_dir || exit 2 | |
9d6f220c | 73 | for patch_name in $(grep -v '^#' < "$QUILT_PATCHES/series" ); do |
9f569fe5 DN |
74 | if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then |
75 | echo "$patch_name doesn't exist. Skipping." | |
76 | continue | |
77 | fi | |
d3d8f361 | 78 | echo $patch_name |
9d6f220c JT |
79 | git mailinfo "$tmp_msg" "$tmp_patch" \ |
80 | <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3 | |
81 | test -s "$tmp_patch" || { | |
7d4f4a2f | 82 | echo "Patch is empty. Was it split wrong?" |
1fa9bf36 | 83 | exit 1 |
87ab7992 | 84 | } |
d3d8f361 EB |
85 | |
86 | # Parse the author information | |
87 | export GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info") | |
88 | export GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info") | |
89 | while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do | |
90 | if [ -n "$quilt_author" ] ; then | |
91 | GIT_AUTHOR_NAME="$quilt_author_name"; | |
92 | GIT_AUTHOR_EMAIL="$quilt_author_email"; | |
d3bd4ee1 EB |
93 | elif [ -n "$dry_run" ]; then |
94 | echo "No author found in $patch_name" >&2; | |
95 | GIT_AUTHOR_NAME="dry-run-not-found"; | |
96 | GIT_AUTHOR_EMAIL="dry-run-not-found"; | |
d3d8f361 | 97 | else |
d3bd4ee1 | 98 | echo "No author found in $patch_name" >&2; |
d3d8f361 EB |
99 | echo "---" |
100 | cat $tmp_msg | |
2aad957a | 101 | printf "Author: "; |
d3d8f361 EB |
102 | read patch_author |
103 | ||
104 | echo "$patch_author" | |
105 | ||
106 | patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') && | |
107 | patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') && | |
108 | test '' != "$patch_author_name" && | |
109 | test '' != "$patch_author_email" && | |
110 | GIT_AUTHOR_NAME="$patch_author_name" && | |
111 | GIT_AUTHOR_EMAIL="$patch_author_email" | |
112 | fi | |
113 | done | |
114 | export GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info") | |
115 | export SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info") | |
116 | if [ -z "$SUBJECT" ] ; then | |
117 | SUBJECT=$(echo $patch_name | sed -e 's/.patch$//') | |
118 | fi | |
119 | ||
d3bd4ee1 | 120 | if [ -z "$dry_run" ] ; then |
5be60078 JH |
121 | git apply --index -C1 "$tmp_patch" && |
122 | tree=$(git write-tree) && | |
123 | commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) && | |
124 | git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 | |
d3bd4ee1 | 125 | fi |
d3d8f361 EB |
126 | done |
127 | rm -rf $tmp_dir || exit 5 |