From: Aneesh Kumar K.V Date: Wed, 13 Aug 2008 15:15:11 +0000 (+0530) Subject: topgit: Implement tg-import X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=commitdiff_plain;h=93f96bf4e70062d1e4ad9c012c838c13ef1db37b;hp=459c340fd5ac765ff1e5d82895b59b53b028aaca topgit: Implement tg-import This can be used to import a set of commits between range specified by range1..range2 This should help us to convert an already existing quilt, stgit branches to topgit managed one Signed-off-by: Aneesh Kumar K.V --- diff --git a/README b/README index 8299027..514f3ed 100644 --- a/README +++ b/README @@ -352,6 +352,13 @@ tg export TODO: For quilt exporting, use a temporary branch and remove it when done - this would allow producing conflict-less series +tg import +~~~~~~~~ + Import the commits between the given revision range into + a topgit managed branch + + Usage: tg import rev1..rev2 + tg update ~~~~~~~~~ Update the current topic branch wrt. changes in the branches diff --git a/tg-import.sh b/tg-import.sh new file mode 100644 index 0000000..6c991c5 --- /dev/null +++ b/tg-import.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# TopGit - A different patch queue manager +# GPLv2 + + +tg_get_commit_msg() +{ + commit="$1" + git log -1 --pretty=format:"From: %an <%ae>%n%n%s%n%n%b" "$commit" +} + +tg_get_branch_name() +{ + # nice sed script from git-format-patch.sh + commit="$1" + titleScript=' + s/[^-a-z.A-Z_0-9]/-/g + s/\.\.\.*/\./g + s/\.*$// + s/--*/-/g + s/^-// + s/-$// + q +' + git log -1 --pretty=format:"%s" "$commit" | sed -e "$titleScript" +} + +tg_process_commit() +{ + commit="$1" + branch_name=$(tg_get_branch_name "$commit") + echo "Importing $commit to $branch_name" + tg create tp/"$branch_name" + git read-tree "$commit" + tg_get_commit_msg "$commit" > .topmsg + git add -f .topmsg .topdeps + git commit -C "$commit" +} + +# nice arg verification stolen from git-format-patch.sh +for revpair +do + case "$revpair" in + ?*..?*) + rev1=`expr "z$revpair" : 'z\(.*\)\.\.'` + rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'` + ;; + *) + die "Unknow range spec $revpair" + ;; + esac + git rev-parse --verify "$rev1^0" >/dev/null 2>&1 || + die "Not a valid rev $rev1 ($revpair)" + git rev-parse --verify "$rev2^0" >/dev/null 2>&1 || + die "Not a valid rev $rev2 ($revpair)" + git cherry -v "$rev1" "$rev2" | + while read sign rev comment + do + case "$sign" in + '-') + info "Merged already: $comment" + ;; + *) + tg_process_commit "$rev" + ;; + esac + done +done