Implement git-quiltimport
Importing a quilt patch series into git is not very difficult but parsing the patch descriptions and all of the other minutia take a bit of effort to get right, so this automates it. Since git and quilt complement each other it makes sense to make it easy to go back and forth between the two. If a patch is encountered that it cannot derive the author from the user is asked. Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric W. Biederman committed
May 17, 2006 at 12:44 UTC
d3d8f361a8c6beb5647e0d963a1460a505324494
3 files changed
+162
-1
Documentation/git-quiltimport.txt
new
+55
@@ -0,0 +1,55 @@
1
+git-quiltimport(1)
2
+================
3
+
4
+NAME
5
+----
6
+git-quiltimport - Applies a quilt patchset onto the current branch
7
+
8
+
9
+SYNOPSIS
10
+--------
11
+[verse]
12
+'git-quiltimport' [--author <author>] [--patches <dir>]
13
+
14
+
15
+DESCRIPTION
16
+-----------
17
+Applies a quilt patchset onto the current git branch, preserving
18
+the patch boundaries, patch order, and patch descriptions present
19
+in the quilt patchset.
20
+
21
+For each patch the code attempts to extract the author from the
22
+patch description. If that fails it falls back to the author
23
+specified with --author. If the --author flag was not given
24
+the patch description is displayed and the user is asked to
25
+interactively enter the author of the patch.
26
+
27
+If a subject is not found in the patch description the patch name is
28
+preserved as the 1 line subject in the git description.
29
+
30
+OPTIONS
31
+-------
32
+--author Author Name <Author Email>::
33
+ The author name and email address to use when no author
34
+ information can be found in the patch description.
35
+
36
+--patches <dir>::
37
+ The directory to find the quilt patches and the
38
+ quilt series file.
39
+
40
+ The default for the patch directory is patches
41
+ or the value of the $QUILT_PATCHES environment
42
+ variable.
43
+
44
+Author
45
+------
46
+Written by Eric Biederman <ebiederm@lnxi.com>
47
+
48
+Documentation
49
+--------------
50
+Documentation by Eric Biederman <ebiederm@lnxi.com>
51
+
52
+GIT
53
+---
54
+Part of the gitlink:git[7] suite
55
+
Makefile
+1
-1
@@ -125,7 +125,7 @@ SCRIPT_SH = \
125
git-applymbox.sh git-applypatch.sh git-am.sh \
126
git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
127
git-merge-resolve.sh git-merge-ours.sh \
128
- git-lost-found.sh
128
+ git-lost-found.sh git-quiltimport.sh
129
130
SCRIPT_PERL = \
131
git-archimport.perl git-cvsimport.perl git-relink.perl \
git-quiltimport.sh
new
+106
@@ -0,0 +1,106 @@
1
+#!/bin/sh
2
+USAGE='--author <author> --patches </path/to/quilt/patch/directory>'
3
+SUBDIRECTORY_ON=Yes
4
+. git-sh-setup
5
+
6
+quilt_author=""
7
+while case "$#" in 0) break;; esac
8
+do
9
+ case "$1" in
10
+ --au=*|--aut=*|--auth=*|--autho=*|--author=*)
11
+ quilt_author=$(expr "$1" : '-[^=]*\(.*\)')
12
+ shift
13
+ ;;
14
+
15
+ --au|--aut|--auth|--autho|--author)
16
+ case "$#" in 1) usage ;; esac
17
+ shift
18
+ quilt_author="$1"
19
+ shift
20
+ ;;
21
+
22
+ --pa=*|--pat=*|--patc=*|--patch=*|--patche=*|--patches=*)
23
+ QUILT_PATCHES=$(expr "$1" : '-[^=]*\(.*\)')
24
+ shift
25
+ ;;
26
+
27
+ --pa|--pat|--patc|--patch|--patche|--patches)
28
+ case "$#" in 1) usage ;; esac
29
+ shift
30
+ QUILT_PATCHES="$1"
31
+ shift
32
+ ;;
33
+
34
+ *)
35
+ break
36
+ ;;
37
+ esac
38
+done
39
+
40
+# Quilt Author
41
+if [ -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" ||
46
+ die "malformatted --author parameter"
47
+fi
48
+
49
+# Quilt patch directory
50
+: ${QUILT_PATCHES:=patches}
51
+if ! [ -d "$QUILT_PATCHES" ] ; then
52
+ echo "The \"$QUILT_PATCHES\" directory does not exist."
53
+ exit 1
54
+fi
55
+
56
+# Temporay directories
57
+tmp_dir=.dotest
58
+tmp_msg="$tmp_dir/msg"
59
+tmp_patch="$tmp_dir/patch"
60
+tmp_info="$tmp_dir/info"
61
+
62
+
63
+# Find the intial commit
64
+commit=$(git-rev-parse HEAD)
65
+
66
+mkdir $tmp_dir || exit 2
67
+for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
68
+ echo $patch_name
69
+ (cat $QUILT_PATCHES/$patch_name | git-mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3
70
+
71
+ # Parse the author information
72
+ export GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
73
+ export GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
74
+ while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
75
+ if [ -n "$quilt_author" ] ; then
76
+ GIT_AUTHOR_NAME="$quilt_author_name";
77
+ GIT_AUTHOR_EMAIL="$quilt_author_email";
78
+ else
79
+ echo "No author found in $patch_name";
80
+ echo "---"
81
+ cat $tmp_msg
82
+ echo -n "Author: ";
83
+ read patch_author
84
+
85
+ echo "$patch_author"
86
+
87
+ patch_author_name=$(expr "z$patch_author" : 'z\(.*[^ ]\) *<.*') &&
88
+ patch_author_email=$(expr "z$patch_author" : '.*<\([^>]*\)') &&
89
+ test '' != "$patch_author_name" &&
90
+ test '' != "$patch_author_email" &&
91
+ GIT_AUTHOR_NAME="$patch_author_name" &&
92
+ GIT_AUTHOR_EMAIL="$patch_author_email"
93
+ fi
94
+ done
95
+ export GIT_AUTHOR_DATE=$(sed -ne 's/Date: //p' "$tmp_info")
96
+ export SUBJECT=$(sed -ne 's/Subject: //p' "$tmp_info")
97
+ if [ -z "$SUBJECT" ] ; then
98
+ SUBJECT=$(echo $patch_name | sed -e 's/.patch$//')
99
+ fi
100
+
101
+ git-apply --index -C1 "$tmp_patch" &&
102
+ tree=$(git-write-tree) &&
103
+ commit=$((echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) &&
104
+ git-update-ref HEAD $commit || exit 4
105
+done
106
+rm -rf $tmp_dir || exit 5