git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] topgit: Implement tg-import

From
aneesh.kumar@gmail.com <aneesh.kumar@gmail.com>
Date
Aug 12, 2008, 16:35 UTC
Message-ID
<1218558943-14398-1-git-send-email-aneesh.kumar@gmail.com>
From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

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>
---
 tg-import.sh |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)
 create mode 100644 tg-import.sh
diff --git a/tg-import.sh b/tg-import.sh
new file mode 100644
index 0000000..0158f3b
--- /dev/null
+++ b/tg-import.sh
@@ -0,0 +1,97 @@
+#!/bin/bash
+#derived out of git-format-patch.sh
+
+function die()
+{
+	echo >&2 "$@"
+	exit 1
+}
+
+function tg_get_commit_msg
+{
+	commit=$1
+commitScript='
+	1,/^$/d
+	: loop
+	/^$/b loop
+	: body
+	p
+	n
+	b body'
+	author=$(git cat-file commit "$commit" | grep author |
+		cut -d ">" -f 1 | sed -ne "s/author//gp")
+	echo "From: "$author">"
+	git cat-file commit "$commit" | sed -ne "$commitScript"
+}
+
+function tg_get_patch
+{
+	git show $1
+}
+
+function tg_get_branch_name
+{
+
+titleScript='
+	1,/^$/d
+	: loop
+	/^$/b loop
+	s/[^-a-z.A-Z_0-9]/-/g
+        s/\.\.\.*/\./g
+	s/\.*$//
+	s/--*/-/g
+	s/^-//
+	s/-$//
+	q
+'
+	commit=$1
+	title=$(git cat-file commit "$commit" | sed -e "$titleScript")
+	echo ${title}
+}
+
+tmp=.tmp-series$$
+trap 'rm -f $tmp-*' 0 1 2 3 15
+
+series=$tmp-series
+# Now we have what we want in $@
+for revpair
+do
+	case "$revpair" in
+	?*..?*)
+		rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
+		rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
+		;;
+	*)
+		echo >&2 "Unknow range spec $revpair"
+		exit
+		;;
+	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
+		'-')
+			echo >&2 "Merged already: $comment"
+			;;
+		*)
+			echo $rev
+			;;
+		esac
+	done
+done >$series
+
+while read commit
+do
+	branch_name=$(tg_get_branch_name $commit)
+	echo "Importing $commit to $branch_name"
+	tg create tp/$branch_name
+	tg_get_commit_msg $commit > .topmsg
+	git add .topmsg
+	git commit -a -m "Add the commit message for the topic branch"
+	tg_get_patch $commit | patch -p1
+	git commit -a -m "Import the initial patch to the topic branch"
+done < $series
-- 
1.6.0.rc0.42.g186458.dirty
Next: Petr Baudis
Message 1 of 2 in “topgit: Implement tg-import”
  1. topgit: Implement tg-importaneesh.kumar@gmail.com, Aug 12, 2008
  2. Petr BaudisAug 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.