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