[PATCH] topgit: Implement tg-import

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] topgit: Implement tg-import

Aneesh Kumar K.V
From: Aneesh Kumar K.V <[hidden email]>

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 <[hidden email]>
---
 Makefile     |    2 +-
 README       |    7 ++++++
 tg-import.sh |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletions(-)
 create mode 100644 tg-import.sh

diff --git a/Makefile b/Makefile
index 6eade1e..95624ac 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ sharedir = $(PREFIX)/share/topgit
 hooksdir = $(cmddir)/hooks
 
 
-commands_in = tg-create.sh tg-delete.sh tg-export.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh
+commands_in = tg-create.sh tg-delete.sh tg-export.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh tg-import.sh
 hooks_in = hooks/pre-commit.sh
 
 commands_out = $(patsubst %.sh,%,$(commands_in))
diff --git a/README b/README
index b58a1b4..8b8f4d7 100644
--- a/README
+++ b/README
@@ -330,6 +330,13 @@ tg export
  TODO: Make stripping of [PATCH] and other prefixes configurable
  TODO: --mbox option for other mode of operation
 
+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
--
1.6.0.rc0.42.g186458.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html