blob: 6d3a88decdeee3f85d9ee43ef8e716ccd1a6328b [file] [log] [blame]
Eric W. Biedermand3d8f362006-05-17 12:44:40 -06001#!/bin/sh
Pierre Habouzite01fbf12007-11-04 11:31:01 +01002OPTIONS_KEEPDASHDASH=
Nicolas Vigier51ba8ce2014-02-01 02:17:59 +00003OPTIONS_STUCKLONG=
Pierre Habouzite01fbf12007-11-04 11:31:01 +01004OPTIONS_SPEC="\
Stephan Beyer1b1dd232008-07-13 15:36:15 +02005git quiltimport [options]
Pierre Habouzite01fbf12007-11-04 11:31:01 +01006--
7n,dry-run dry run
8author= author name and email address for patches without any
Juerg Haefligerff60ffd2015-08-31 14:06:38 +02009patches= path to the quilt patches
10series= path to the quilt series file
Pierre Habouzite01fbf12007-11-04 11:31:01 +010011"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060012SUBDIRECTORY_ON=Yes
13. git-sh-setup
14
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060015dry_run=""
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060016quilt_author=""
David Kastrup822f7c72007-09-23 22:42:08 +020017while test $# != 0
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060018do
19 case "$1" in
Pierre Habouzite01fbf12007-11-04 11:31:01 +010020 --author)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060021 shift
22 quilt_author="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060023 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010024 -n|--dry-run)
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060025 dry_run=1
26 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010027 --patches)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060028 shift
Andy Whitcroft9e384b42007-11-12 12:07:40 +000029 QUILT_PATCHES="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060030 ;;
Juerg Haefligerff60ffd2015-08-31 14:06:38 +020031 --series)
32 shift
33 QUILT_SERIES="$1"
34 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010035 --)
36 shift
37 break;;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060038 *)
Pierre Habouzite01fbf12007-11-04 11:31:01 +010039 usage
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060040 ;;
41 esac
Pierre Habouzite01fbf12007-11-04 11:31:01 +010042 shift
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060043done
44
45# Quilt Author
46if [ -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" ||
Pavel Roskin82e5a822006-07-10 01:50:18 -040051 die "malformed --author parameter"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060052fi
53
54# Quilt patch directory
55: ${QUILT_PATCHES:=patches}
56if ! [ -d "$QUILT_PATCHES" ] ; then
57 echo "The \"$QUILT_PATCHES\" directory does not exist."
58 exit 1
59fi
60
Juerg Haefligerff60ffd2015-08-31 14:06:38 +020061# Quilt series file
62: ${QUILT_SERIES:=$QUILT_PATCHES/series}
63if ! [ -e "$QUILT_SERIES" ] ; then
64 echo "The \"$QUILT_SERIES\" file does not exist."
65 exit 1
66fi
67
Pavel Roskin3dff5372007-02-03 23:49:16 -050068# Temporary directories
Johannes Schindelin51ef1da2008-07-21 12:51:02 +020069tmp_dir="$GIT_DIR"/rebase-apply
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060070tmp_msg="$tmp_dir/msg"
71tmp_patch="$tmp_dir/patch"
72tmp_info="$tmp_dir/info"
73
74
Stefano Lattarini41ccfdd2013-04-12 00:36:10 +020075# Find the initial commit
Junio C Hamano5be60072007-07-02 22:52:14 -070076commit=$(git rev-parse HEAD)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060077
78mkdir $tmp_dir || exit 2
Gerrit Pape6ab149e2009-02-24 09:00:06 +000079while read patch_name level garbage <&3
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010080do
81 case "$patch_name" in ''|'#'*) continue;; esac
82 case "$level" in
Junio C Hamano18d077c2008-03-12 21:07:19 -070083 -p*) ;;
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010084 ''|'#'*)
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
Dan Nicholson9f569fe2007-09-27 13:30:59 -070096 if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
97 echo "$patch_name doesn't exist. Skipping."
98 continue
99 fi
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600100 echo $patch_name
Josh Triplett9d6f2202007-07-14 01:05:43 -0700101 git mailinfo "$tmp_msg" "$tmp_patch" \
102 <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
103 test -s "$tmp_patch" || {
Junio C Hamano7d4f4a22007-04-24 14:27:00 -0700104 echo "Patch is empty. Was it split wrong?"
Linus Torvalds1fa9bf32007-04-13 14:34:18 -0700105 exit 1
Don Zickus87ab7992007-03-12 15:52:04 -0400106 }
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600107
108 # Parse the author information
Johannes Schindelin3addc942007-11-28 15:56:11 +0000109 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
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600112 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";
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600116 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";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600120 else
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600121 echo "No author found in $patch_name" >&2;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600122 echo "---"
123 cat $tmp_msg
Jason Riedy2aad9572007-01-15 17:31:29 -0800124 printf "Author: ";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600125 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
Johannes Schindelin3addc942007-11-28 15:56:11 +0000137 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
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600140 if [ -z "$SUBJECT" ] ; then
141 SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
142 fi
143
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600144 if [ -z "$dry_run" ] ; then
Junio C Hamano18d077c2008-03-12 21:07:19 -0700145 git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700146 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
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600149 fi
Juerg Haefligerff60ffd2015-08-31 14:06:38 +0200150done 3<"$QUILT_SERIES"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600151rm -rf $tmp_dir || exit 5