blob: 167d79fea809b918e81c2228ee27baa5fab23db4 [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
9patches= path to the quilt series and patches
10"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060011SUBDIRECTORY_ON=Yes
12. git-sh-setup
13
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060014dry_run=""
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060015quilt_author=""
David Kastrup822f7c72007-09-23 22:42:08 +020016while test $# != 0
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060017do
18 case "$1" in
Pierre Habouzite01fbf12007-11-04 11:31:01 +010019 --author)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060020 shift
21 quilt_author="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060022 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010023 -n|--dry-run)
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060024 dry_run=1
25 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010026 --patches)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060027 shift
Andy Whitcroft9e384b42007-11-12 12:07:40 +000028 QUILT_PATCHES="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060029 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010030 --)
31 shift
32 break;;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060033 *)
Pierre Habouzite01fbf12007-11-04 11:31:01 +010034 usage
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060035 ;;
36 esac
Pierre Habouzite01fbf12007-11-04 11:31:01 +010037 shift
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060038done
39
40# Quilt Author
41if [ -n "$quilt_author" ] ; then
42 quilt_author_name=$(expr "z$quilt_author" : 'z\(.*[^ ]\) *<.*') &&
43 quilt_author_email=$(expr "z$quilt_author" : '.*<\([^>]*\)') &&
44 test '' != "$quilt_author_name" &&
45 test '' != "$quilt_author_email" ||
Pavel Roskin82e5a822006-07-10 01:50:18 -040046 die "malformed --author parameter"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060047fi
48
49# Quilt patch directory
50: ${QUILT_PATCHES:=patches}
51if ! [ -d "$QUILT_PATCHES" ] ; then
52 echo "The \"$QUILT_PATCHES\" directory does not exist."
53 exit 1
54fi
55
Pavel Roskin3dff5372007-02-03 23:49:16 -050056# Temporary directories
Johannes Schindelin51ef1da2008-07-21 12:51:02 +020057tmp_dir="$GIT_DIR"/rebase-apply
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060058tmp_msg="$tmp_dir/msg"
59tmp_patch="$tmp_dir/patch"
60tmp_info="$tmp_dir/info"
61
62
Stefano Lattarini41ccfdd2013-04-12 00:36:10 +020063# Find the initial commit
Junio C Hamano5be60072007-07-02 22:52:14 -070064commit=$(git rev-parse HEAD)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060065
66mkdir $tmp_dir || exit 2
Gerrit Pape6ab149e2009-02-24 09:00:06 +000067while read patch_name level garbage <&3
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010068do
69 case "$patch_name" in ''|'#'*) continue;; esac
70 case "$level" in
Junio C Hamano18d077c2008-03-12 21:07:19 -070071 -p*) ;;
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010072 ''|'#'*)
73 level=;;
74 *)
75 echo "unable to parse patch level, ignoring it."
76 level=;;
77 esac
78 case "$garbage" in
79 ''|'#'*);;
80 *)
81 echo "trailing garbage found in series file: $garbage"
82 exit 1;;
83 esac
Dan Nicholson9f569fe2007-09-27 13:30:59 -070084 if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
85 echo "$patch_name doesn't exist. Skipping."
86 continue
87 fi
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060088 echo $patch_name
Josh Triplett9d6f2202007-07-14 01:05:43 -070089 git mailinfo "$tmp_msg" "$tmp_patch" \
90 <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
91 test -s "$tmp_patch" || {
Junio C Hamano7d4f4a22007-04-24 14:27:00 -070092 echo "Patch is empty. Was it split wrong?"
Linus Torvalds1fa9bf32007-04-13 14:34:18 -070093 exit 1
Don Zickus87ab7992007-03-12 15:52:04 -040094 }
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060095
96 # Parse the author information
Johannes Schindelin3addc942007-11-28 15:56:11 +000097 GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
98 GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
99 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600100 while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
101 if [ -n "$quilt_author" ] ; then
102 GIT_AUTHOR_NAME="$quilt_author_name";
103 GIT_AUTHOR_EMAIL="$quilt_author_email";
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600104 elif [ -n "$dry_run" ]; then
105 echo "No author found in $patch_name" >&2;
106 GIT_AUTHOR_NAME="dry-run-not-found";
107 GIT_AUTHOR_EMAIL="dry-run-not-found";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600108 else
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600109 echo "No author found in $patch_name" >&2;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600110 echo "---"
111 cat $tmp_msg
Jason Riedy2aad9572007-01-15 17:31:29 -0800112 printf "Author: ";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600113 read patch_author
114
115 echo "$patch_author"
116
117 patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') &&
118 patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') &&
119 test '' != "$patch_author_name" &&
120 test '' != "$patch_author_email" &&
121 GIT_AUTHOR_NAME="$patch_author_name" &&
122 GIT_AUTHOR_EMAIL="$patch_author_email"
123 fi
124 done
Johannes Schindelin3addc942007-11-28 15:56:11 +0000125 GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info")
126 SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info")
127 export GIT_AUTHOR_DATE SUBJECT
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600128 if [ -z "$SUBJECT" ] ; then
129 SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
130 fi
131
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600132 if [ -z "$dry_run" ] ; then
Junio C Hamano18d077c2008-03-12 21:07:19 -0700133 git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700134 tree=$(git write-tree) &&
135 commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
136 git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600137 fi
Gerrit Pape6ab149e2009-02-24 09:00:06 +0000138done 3<"$QUILT_PATCHES/series"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600139rm -rf $tmp_dir || exit 5