blob: 9a6ba2b9874e12d31adeba354d8d44436ceadaf3 [file] [log] [blame]
Eric W. Biedermand3d8f362006-05-17 12:44:40 -06001#!/bin/sh
Pierre Habouzite01fbf12007-11-04 11:31:01 +01002OPTIONS_KEEPDASHDASH=
3OPTIONS_SPEC="\
Stephan Beyer1b1dd232008-07-13 15:36:15 +02004git quiltimport [options]
Pierre Habouzite01fbf12007-11-04 11:31:01 +01005--
6n,dry-run dry run
7author= author name and email address for patches without any
8patches= path to the quilt series and patches
9"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060010SUBDIRECTORY_ON=Yes
11. git-sh-setup
12
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060013dry_run=""
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060014quilt_author=""
David Kastrup822f7c72007-09-23 22:42:08 +020015while test $# != 0
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060016do
17 case "$1" in
Pierre Habouzite01fbf12007-11-04 11:31:01 +010018 --author)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060019 shift
20 quilt_author="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060021 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010022 -n|--dry-run)
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -060023 dry_run=1
24 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010025 --patches)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060026 shift
Andy Whitcroft9e384b42007-11-12 12:07:40 +000027 QUILT_PATCHES="$1"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060028 ;;
Pierre Habouzite01fbf12007-11-04 11:31:01 +010029 --)
30 shift
31 break;;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060032 *)
Pierre Habouzite01fbf12007-11-04 11:31:01 +010033 usage
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060034 ;;
35 esac
Pierre Habouzite01fbf12007-11-04 11:31:01 +010036 shift
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060037done
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" ||
Pavel Roskin82e5a822006-07-10 01:50:18 -040045 die "malformed --author parameter"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060046fi
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
Pavel Roskin3dff5372007-02-03 23:49:16 -050055# Temporary directories
Johannes Schindelin51ef1da2008-07-21 12:51:02 +020056tmp_dir="$GIT_DIR"/rebase-apply
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060057tmp_msg="$tmp_dir/msg"
58tmp_patch="$tmp_dir/patch"
59tmp_info="$tmp_dir/info"
60
61
62# Find the intial commit
Junio C Hamano5be60072007-07-02 22:52:14 -070063commit=$(git rev-parse HEAD)
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060064
65mkdir $tmp_dir || exit 2
Gerrit Pape6ab149e2009-02-24 09:00:06 +000066while read patch_name level garbage <&3
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010067do
68 case "$patch_name" in ''|'#'*) continue;; esac
69 case "$level" in
Junio C Hamano18d077c2008-03-12 21:07:19 -070070 -p*) ;;
Pierre Habouzit9dd5bde2008-03-08 19:27:09 +010071 ''|'#'*)
72 level=;;
73 *)
74 echo "unable to parse patch level, ignoring it."
75 level=;;
76 esac
77 case "$garbage" in
78 ''|'#'*);;
79 *)
80 echo "trailing garbage found in series file: $garbage"
81 exit 1;;
82 esac
Dan Nicholson9f569fe2007-09-27 13:30:59 -070083 if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
84 echo "$patch_name doesn't exist. Skipping."
85 continue
86 fi
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060087 echo $patch_name
Josh Triplett9d6f2202007-07-14 01:05:43 -070088 git mailinfo "$tmp_msg" "$tmp_patch" \
89 <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
90 test -s "$tmp_patch" || {
Junio C Hamano7d4f4a22007-04-24 14:27:00 -070091 echo "Patch is empty. Was it split wrong?"
Linus Torvalds1fa9bf32007-04-13 14:34:18 -070092 exit 1
Don Zickus87ab7992007-03-12 15:52:04 -040093 }
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060094
95 # Parse the author information
Johannes Schindelin3addc942007-11-28 15:56:11 +000096 GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
97 GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
98 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
Eric W. Biedermand3d8f362006-05-17 12:44:40 -060099 while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
100 if [ -n "$quilt_author" ] ; then
101 GIT_AUTHOR_NAME="$quilt_author_name";
102 GIT_AUTHOR_EMAIL="$quilt_author_email";
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600103 elif [ -n "$dry_run" ]; then
104 echo "No author found in $patch_name" >&2;
105 GIT_AUTHOR_NAME="dry-run-not-found";
106 GIT_AUTHOR_EMAIL="dry-run-not-found";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600107 else
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600108 echo "No author found in $patch_name" >&2;
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600109 echo "---"
110 cat $tmp_msg
Jason Riedy2aad9572007-01-15 17:31:29 -0800111 printf "Author: ";
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600112 read patch_author
113
114 echo "$patch_author"
115
116 patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') &&
117 patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') &&
118 test '' != "$patch_author_name" &&
119 test '' != "$patch_author_email" &&
120 GIT_AUTHOR_NAME="$patch_author_name" &&
121 GIT_AUTHOR_EMAIL="$patch_author_email"
122 fi
123 done
Johannes Schindelin3addc942007-11-28 15:56:11 +0000124 GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info")
125 SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info")
126 export GIT_AUTHOR_DATE SUBJECT
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600127 if [ -z "$SUBJECT" ] ; then
128 SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
129 fi
130
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600131 if [ -z "$dry_run" ] ; then
Junio C Hamano18d077c2008-03-12 21:07:19 -0700132 git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
Junio C Hamano5be60072007-07-02 22:52:14 -0700133 tree=$(git write-tree) &&
134 commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
135 git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
Eric W. Biedermand3bd4ee2006-05-17 14:10:25 -0600136 fi
Gerrit Pape6ab149e2009-02-24 09:00:06 +0000137done 3<"$QUILT_PATCHES/series"
Eric W. Biedermand3d8f362006-05-17 12:44:40 -0600138rm -rf $tmp_dir || exit 5