{"thread":{"id":"14964","subject":"[PATCH] topgit: Implement tg-import","startedAt":"2008-08-12T16:35:43Z","lastAt":"2008-08-12T17:31:50Z","messageCount":2,"participants":["aneesh.kumar@gmail.com","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"86948","messageId":"1218558943-14398-1-git-send-email-aneesh.kumar@gmail.com","threadId":"14964","inReplyTo":null,"subject":"[PATCH] topgit: Implement tg-import","fromName":"","fromEmail":"aneesh.kumar@gmail.com","sentAt":"2008-08-12T16:35:43Z","receivedAt":"2008-08-12T16:35:43Z","isPatch":true,"sender":{"key":"aneesh.kumar@gmail.com","avatar":"https://gravatar.com/avatar/0621fc0b2f14ead1e9024382f16053a808c148596da30c1b92572fa075621f68?d=mp&s=160"},"body":"From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n\nThis can be used to import a set of commits\nbetween range specified by range1..range2\nThis should help us to convert an already\nexisting quilt, stgit branches to topgit\nmanaged one\n\nSigned-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n\n---\n tg-import.sh |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 97 insertions(+), 0 deletions(-)\n create mode 100644 tg-import.sh\n\ndiff --git a/tg-import.sh b/tg-import.sh\nnew file mode 100644\nindex 0000000..0158f3b\n--- /dev/null\n+++ b/tg-import.sh\n@@ -0,0 +1,97 @@\n+#!/bin/bash\n+#derived out of git-format-patch.sh\n+\n+function die()\n+{\n+\techo >&2 \"$@\"\n+\texit 1\n+}\n+\n+function tg_get_commit_msg\n+{\n+\tcommit=$1\n+commitScript='\n+\t1,/^$/d\n+\t: loop\n+\t/^$/b loop\n+\t: body\n+\tp\n+\tn\n+\tb body'\n+\tauthor=$(git cat-file commit \"$commit\" | grep author |\n+\t\tcut -d \">\" -f 1 | sed -ne \"s/author//gp\")\n+\techo \"From: \"$author\">\"\n+\tgit cat-file commit \"$commit\" | sed -ne \"$commitScript\"\n+}\n+\n+function tg_get_patch\n+{\n+\tgit show $1\n+}\n+\n+function tg_get_branch_name\n+{\n+\n+titleScript='\n+\t1,/^$/d\n+\t: loop\n+\t/^$/b loop\n+\ts/[^-a-z.A-Z_0-9]/-/g\n+        s/\\.\\.\\.*/\\./g\n+\ts/\\.*$//\n+\ts/--*/-/g\n+\ts/^-//\n+\ts/-$//\n+\tq\n+'\n+\tcommit=$1\n+\ttitle=$(git cat-file commit \"$commit\" | sed -e \"$titleScript\")\n+\techo ${title}\n+}\n+\n+tmp=.tmp-series$$\n+trap 'rm -f $tmp-*' 0 1 2 3 15\n+\n+series=$tmp-series\n+# Now we have what we want in $@\n+for revpair\n+do\n+\tcase \"$revpair\" in\n+\t?*..?*)\n+\t\trev1=`expr \"z$revpair\" : 'z\\(.*\\)\\.\\.'`\n+\t\trev2=`expr \"z$revpair\" : 'z.*\\.\\.\\(.*\\)'`\n+\t\t;;\n+\t*)\n+\t\techo >&2 \"Unknow range spec $revpair\"\n+\t\texit\n+\t\t;;\n+\tesac\n+\tgit rev-parse --verify \"$rev1^0\" >/dev/null 2>&1 ||\n+\t\tdie \"Not a valid rev $rev1 ($revpair)\"\n+\tgit rev-parse --verify \"$rev2^0\" >/dev/null 2>&1 ||\n+\t\tdie \"Not a valid rev $rev2 ($revpair)\"\n+\tgit cherry -v \"$rev1\" \"$rev2\" |\n+\twhile read sign rev comment\n+\tdo\n+\t\tcase \"$sign\" in\n+\t\t'-')\n+\t\t\techo >&2 \"Merged already: $comment\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\techo $rev\n+\t\t\t;;\n+\t\tesac\n+\tdone\n+done >$series\n+\n+while read commit\n+do\n+\tbranch_name=$(tg_get_branch_name $commit)\n+\techo \"Importing $commit to $branch_name\"\n+\ttg create tp/$branch_name\n+\ttg_get_commit_msg $commit > .topmsg\n+\tgit add .topmsg\n+\tgit commit -a -m \"Add the commit message for the topic branch\"\n+\ttg_get_patch $commit | patch -p1\n+\tgit commit -a -m \"Import the initial patch to the topic branch\"\n+done < $series\n-- \n1.6.0.rc0.42.g186458.dirty\n"},{"id":"86950","messageId":"20080812173150.GM32184@machine.or.cz","threadId":"14964","inReplyTo":"1218558943-14398-1-git-send-email-aneesh.kumar@gmail.com","subject":"Re: [PATCH] topgit: Implement tg-import","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-08-12T17:31:50Z","receivedAt":"2008-08-12T17:31:50Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi,\n\nOn Tue, Aug 12, 2008 at 10:05:43PM +0530, aneesh.kumar@gmail.com wrote:\n> From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n> \n> This can be used to import a set of commits\n> between range specified by range1..range2\n> This should help us to convert an already\n> existing quilt, stgit branches to topgit\n> managed one\n> \n> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n\n  thanks, unfortunately this script still needs work.\n\n> ---\n>  tg-import.sh |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 files changed, 97 insertions(+), 0 deletions(-)\n>  create mode 100644 tg-import.sh\n\n  There seems to be no documentation.\n\n> diff --git a/tg-import.sh b/tg-import.sh\n> new file mode 100644\n> index 0000000..0158f3b\n> --- /dev/null\n> +++ b/tg-import.sh\n> @@ -0,0 +1,97 @@\n> +#!/bin/bash\n> +#derived out of git-format-patch.sh\n\n  I feel this is a wrong approach - it should be derived from some of\nthe tg scripts instead. Please use the common header and options\nparsing infrastructure. Also, please adjust your script to be non-bash\nspecific.\n\n> +function die()\n> +{\n> +\techo >&2 \"$@\"\n> +\texit 1\n> +}\n\n  We already have this function.\n\n> +function tg_get_commit_msg\n> +{\n> +\tcommit=$1\n\n  Please quote variables use; this also applies to the rest of the\nscript.\n\n> +commitScript='\n\n  Indentation?\n\n> +\t1,/^$/d\n> +\t: loop\n> +\t/^$/b loop\n> +\t: body\n> +\tp\n> +\tn\n> +\tb body'\n> +\tauthor=$(git cat-file commit \"$commit\" | grep author |\n> +\t\tcut -d \">\" -f 1 | sed -ne \"s/author//gp\")\n> +\techo \"From: \"$author\">\"\n> +\tgit cat-file commit \"$commit\" | sed -ne \"$commitScript\"\n> +}\n\n  Wouldn't it be much more convenient to just use\n\n\tgit log -1 --pretty=format:\"From: %an <%ae>%nSubject: %s%n%n%b\"\n\n> +function tg_get_patch\n> +{\n> +\tgit show $1\n> +}\n> +\n> +function tg_get_branch_name\n> +{\n> +\n> +titleScript='\n> +\t1,/^$/d\n> +\t: loop\n> +\t/^$/b loop\n> +\ts/[^-a-z.A-Z_0-9]/-/g\n> +        s/\\.\\.\\.*/\\./g\n> +\ts/\\.*$//\n> +\ts/--*/-/g\n> +\ts/^-//\n> +\ts/-$//\n> +\tq\n> +'\n\nYou should document the origin of this snippet.\n\n> +\tcommit=$1\n> +\ttitle=$(git cat-file commit \"$commit\" | sed -e \"$titleScript\")\n> +\techo ${title}\n> +}\n> +\n> +tmp=.tmp-series$$\n\nPlease use mktemp.\n\nDo you actually need the tmp file at all?\n\n> +trap 'rm -f $tmp-*' 0 1 2 3 15\n> +\n> +series=$tmp-series\n> +# Now we have what we want in $@\n\nWe didn't before?\n\n> +for revpair\n> +do\n> +\tcase \"$revpair\" in\n> +\t?*..?*)\n> +\t\trev1=`expr \"z$revpair\" : 'z\\(.*\\)\\.\\.'`\n> +\t\trev2=`expr \"z$revpair\" : 'z.*\\.\\.\\(.*\\)'`\n> +\t\t;;\n> +\t*)\n> +\t\techo >&2 \"Unknow range spec $revpair\"\n> +\t\texit\n\ndie?\n\n> +\t\t;;\n> +\tesac\n> +\tgit rev-parse --verify \"$rev1^0\" >/dev/null 2>&1 ||\n> +\t\tdie \"Not a valid rev $rev1 ($revpair)\"\n> +\tgit rev-parse --verify \"$rev2^0\" >/dev/null 2>&1 ||\n> +\t\tdie \"Not a valid rev $rev2 ($revpair)\"\n> +\tgit cherry -v \"$rev1\" \"$rev2\" |\n> +\twhile read sign rev comment\n> +\tdo\n> +\t\tcase \"$sign\" in\n> +\t\t'-')\n> +\t\t\techo >&2 \"Merged already: $comment\"\n\ninfo?\n\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\techo $rev\n\nDoes it make sense to print it all out now?\n\n> +\t\t\t;;\n> +\t\tesac\n> +\tdone\n> +done >$series\n\nWhy do we need all the rev-parses? Is the git cherry checking really\nuseful?\n\nThis flattens the commit structure, which is another problem; the commit\nrelationships should rather be described in the .topdeps files. Using\ngit log --parents should give us that information?\n\n> +while read commit\n> +do\n\nWhy do you actually loop twice?\n\n> +\tbranch_name=$(tg_get_branch_name $commit)\n> +\techo \"Importing $commit to $branch_name\"\n> +\ttg create tp/$branch_name\n\nMake this configurable?\n\n> +\ttg_get_commit_msg $commit > .topmsg\n> +\tgit add .topmsg\n> +\tgit commit -a -m \"Add the commit message for the topic branch\"\n> +\ttg_get_patch $commit | patch -p1\n\nAlso, I don't think reimplementing git rebase here is good idea at all.\nI would just imagine the script to do something like\n\n\tgit rev-list ^HEAD lastcommit | while read commit; do\n\t\ttg create tp/$branch_name\n\t\tgit read-tree $commit\n\t\tgit add .top*\n\t\tgit commit -C $commit\n\tdone\n\nSo allow only to import commits that are _on top_ of the same commit the\ntopic branches system is going to be based on.\n\n> +\tgit commit -a -m \"Import the initial patch to the topic branch\"\n\nWhy two commits?\n\n> +done < $series\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nThe next generation of interesting software will be done\non the Macintosh, not the IBM PC.  -- Bill Gates\n"}]}