tg mail: Simplify array usage
[topgit/greenrd.git] / tg-import.sh
blob799efc9a8395228604e1ccf94cc66a0c36144ec9
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # (c) Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 2008
5 # GPLv2
7 branch_prefix=t/
8 ranges=
11 ## Parse options
13 while [ -n "$1" ]; do
14 arg="$1"; shift
15 case "$arg" in
16 -p)
17 branch_prefix="$1"; shift;;
18 -*)
19 echo "Usage: tg [...] import [-p PREFIX] RANGE..." >&2
20 exit 1;;
22 ranges="$ranges $arg";;
23 esac
24 done
27 ## Make sure our tree is clean
29 git update-index --ignore-submodules --refresh || exit
30 [ -z "$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)" ] ||
31 die "the index is not clean"
34 ## Perform import
36 get_commit_msg()
38 commit="$1"
39 git log -1 --pretty=format:"From: %an <%ae>%n%n%s%n%n%b" "$commit"
42 get_branch_name()
44 # nice sed script from git-format-patch.sh
45 commit="$1"
46 titleScript='
47 s/[^-a-z.A-Z_0-9]/-/g
48 s/\.\.\.*/\./g
49 s/\.*$//
50 s/--*/-/g
51 s/^-//
52 s/-$//
55 git log -1 --pretty=format:"%s" "$commit" | sed -e "$titleScript"
58 process_commit()
60 commit="$1"
61 branch_name=$(get_branch_name "$commit")
62 info "---- Importing $commit to $branch_prefix$branch_name"
63 tg create "$branch_prefix""$branch_name"
64 git cherry-pick --no-commit "$commit"
65 get_commit_msg "$commit" > .topmsg
66 git add -f .topmsg .topdeps
67 git commit -C "$commit"
68 info "++++ Importing $commit finished"
71 # nice arg verification stolen from git-format-patch.sh
72 for revpair in $ranges
74 case "$revpair" in
75 ?*..?*)
76 rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
77 rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
80 die "Unknow range spec $revpair"
82 esac
83 git rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
84 die "Not a valid rev $rev1 ($revpair)"
85 git rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
86 die "Not a valid rev $rev2 ($revpair)"
87 git cherry -v "$rev1" "$rev2" |
88 while read sign rev comment
90 case "$sign" in
91 '-')
92 info "Merged already: $comment"
95 process_commit "$rev"
97 esac
98 done
99 done