Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 139 lines (127 sloc) 3.348 kb
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
1 #!/bin/sh
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
2 OPTIONS_KEEPDASHDASH=
3 OPTIONS_SPEC="\
1b1dd23 @sbeyer Make usage strings dash-less
sbeyer authored
4 git quiltimport [options]
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
5 --
6 n,dry-run dry run
7 author= author name and email address for patches without any
8 patches= path to the quilt series and patches
9 "
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
10 SUBDIRECTORY_ON=Yes
11 . git-sh-setup
12
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
13 dry_run=""
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
14 quilt_author=""
822f7c7 Supplant the "while case ... break ;; esac" idiom
David Kastrup authored
15 while test $# != 0
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
16 do
17 case "$1" in
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
18 --author)
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
19 shift
20 quilt_author="$1"
21 ;;
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
22 -n|--dry-run)
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
23 dry_run=1
24 ;;
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
25 --patches)
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
26 shift
9e384b4 @awhitcroft git-quiltimport.sh fix --patches handling
awhitcroft authored
27 QUILT_PATCHES="$1"
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
28 ;;
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
29 --)
30 shift
31 break;;
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
32 *)
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
33 usage
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
34 ;;
35 esac
e01fbf1 @MadCoder Migrate git-quiltimport.sh to use git-rev-parse --parseopt
MadCoder authored
36 shift
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
37 done
38
39 # Quilt Author
40 if [ -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" ||
82e5a82 @proski Fix more typos, primarily in the code
proski authored
45 die "malformed --author parameter"
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
46 fi
47
48 # Quilt patch directory
49 : ${QUILT_PATCHES:=patches}
50 if ! [ -d "$QUILT_PATCHES" ] ; then
51 echo "The \"$QUILT_PATCHES\" directory does not exist."
52 exit 1
53 fi
54
3dff537 @proski Assorted typo fixes
proski authored
55 # Temporary directories
51ef1da @dscho Rename .git/rebase to .git/rebase-apply
dscho authored
56 tmp_dir="$GIT_DIR"/rebase-apply
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
57 tmp_msg="$tmp_dir/msg"
58 tmp_patch="$tmp_dir/patch"
59 tmp_info="$tmp_dir/info"
60
61
62 # Find the intial commit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
63 commit=$(git rev-parse HEAD)
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
64
65 mkdir $tmp_dir || exit 2
6ab149e git-quiltimport: preserve standard input to be able to read user input
Gerrit Pape authored
66 while read patch_name level garbage <&3
9dd5bde @MadCoder git-quiltimport: better parser to grok "enhanced" series files.
MadCoder authored
67 do
68 case "$patch_name" in ''|'#'*) continue;; esac
69 case "$level" in
18d077c @gitster quiltimport: fix misquoting of parsed -p<num> parameter
authored
70 -p*) ;;
9dd5bde @MadCoder git-quiltimport: better parser to grok "enhanced" series files.
MadCoder authored
71 ''|'#'*)
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
9f569fe @dbnicholson quiltimport: Skip non-existent patches
dbnicholson authored
83 if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
84 echo "$patch_name doesn't exist. Skipping."
85 continue
86 fi
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
87 echo $patch_name
9d6f220 @joshtriplett Remove useless uses of cat, and replace with filename arguments
joshtriplett authored
88 git mailinfo "$tmp_msg" "$tmp_patch" \
89 <"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
90 test -s "$tmp_patch" || {
7d4f4a2 applymbox & quiltimport: typofix.
Junio C Hamano authored
91 echo "Patch is empty. Was it split wrong?"
1fa9bf3 @torvalds git-quiltimport complaining yet still working
torvalds authored
92 exit 1
87ab799 builtin-mailinfo.c infrastrcture changes
Don Zickus authored
93 }
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
94
95 # Parse the author information
3addc94 @dscho Replace instances of export VAR=VAL with VAR=VAL; export VAR
dscho authored
96 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
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
99 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";
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
103 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";
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
107 else
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
108 echo "No author found in $patch_name" >&2;
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
109 echo "---"
110 cat $tmp_msg
2aad957 Replace "echo -n" with printf in shell scripts.
Jason Riedy authored
111 printf "Author: ";
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
112 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
3addc94 @dscho Replace instances of export VAR=VAL with VAR=VAL; export VAR
dscho authored
124 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
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
127 if [ -z "$SUBJECT" ] ; then
128 SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
129 fi
130
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
131 if [ -z "$dry_run" ] ; then
18d077c @gitster quiltimport: fix misquoting of parsed -p<num> parameter
authored
132 git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
authored
133 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
d3bd4ee @ebiederm Implement a --dry-run option to git-quiltimport
ebiederm authored
136 fi
6ab149e git-quiltimport: preserve standard input to be able to read user input
Gerrit Pape authored
137 done 3<"$QUILT_PATCHES/series"
d3d8f36 @ebiederm Implement git-quiltimport
ebiederm authored
138 rm -rf $tmp_dir || exit 5
Something went wrong with that request. Please try again.