chiark / gitweb /
topgit: Implement tg-import
authorAneesh Kumar K.V <aneesh.kumar@gmail.com>
Wed, 13 Aug 2008 15:15:11 +0000 (20:45 +0530)
committerPetr Baudis <pasky@suse.cz>
Tue, 9 Sep 2008 21:57:36 +0000 (23:57 +0200)
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 <aneesh.kumar@gmail.com>
README
tg-import.sh [new file with mode: 0644]

diff --git a/README b/README
index 8299027e97ac579823695cdd6e3b67566a8d10f6..514f3ed45c25ce696f35f5b9eb7708aa3263b638 100644 (file)
--- 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
 
        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
 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 (file)
index 0000000..6c991c5
--- /dev/null
@@ -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