.gitignore: Add tg-import, tg-remote
[topgit.git] / tg-import.sh
blob6a4f79ea27e0116814c271b03046a3f2eb874da4
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 get_commit_msg()
29 commit="$1"
30 git log -1 --pretty=format:"From: %an <%ae>%n%n%s%n%n%b" "$commit"
33 get_branch_name()
35 # nice sed script from git-format-patch.sh
36 commit="$1"
37 titleScript='
38 s/[^-a-z.A-Z_0-9]/-/g
39 s/\.\.\.*/\./g
40 s/\.*$//
41 s/--*/-/g
42 s/^-//
43 s/-$//
46 git log -1 --pretty=format:"%s" "$commit" | sed -e "$titleScript"
49 process_commit()
51 commit="$1"
52 branch_name=$(get_branch_name "$commit")
53 info "---- Importing $commit to $branch_prefix$branch_name"
54 tg create "$branch_prefix""$branch_name"
55 git read-tree "$commit"
56 get_commit_msg "$commit" > .topmsg
57 git add -f .topmsg .topdeps
58 git commit -C "$commit"
59 info "++++ Importing $commit finished"
62 # nice arg verification stolen from git-format-patch.sh
63 for revpair in $ranges
65 case "$revpair" in
66 ?*..?*)
67 rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
68 rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
71 die "Unknow range spec $revpair"
73 esac
74 git rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
75 die "Not a valid rev $rev1 ($revpair)"
76 git rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
77 die "Not a valid rev $rev2 ($revpair)"
78 git cherry -v "$rev1" "$rev2" |
79 while read sign rev comment
81 case "$sign" in
82 '-')
83 info "Merged already: $comment"
86 process_commit "$rev"
88 esac
89 done
90 done