{"thread":{"id":"27483","subject":"[PATCH/RFC] contrib: git-c2t converts tag creating commits to tags","startedAt":"2011-05-27T13:52:59Z","lastAt":"2011-05-27T13:55:33Z","messageCount":2,"participants":["Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"168872","messageId":"59fe17310157f99d5f20173ed65408d9e1f33462.1306504356.git.git@drmicha.warpmail.net","threadId":"27483","inReplyTo":null,"subject":"[PATCH/RFC] contrib: git-c2t converts tag creating commits to tags","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-05-27T13:52:59Z","receivedAt":"2011-05-27T13:52:59Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Introduce git-c2t <commit> <tag> which converts a commit object <commit>\ninto a tag object (and tags it with <tagname>), under the provision that\n<commit> has exactly one parent and has the same tree. That tag points\nat the parent commit.\n\nThis is useful for converting \"tag creating commits\" such as those\nproduced by git-svn into proper git tags. Tag creating commits typically\ncreate a \"1-commit side branch\" whereas the tag created by c2t points at\nthe pseudo fork point (the commit being tagged).\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n contrib/git-c2t.sh |   46 ++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 46 insertions(+), 0 deletions(-)\n create mode 100755 contrib/git-c2t.sh\n\ndiff --git a/contrib/git-c2t.sh b/contrib/git-c2t.sh\nnew file mode 100755\nindex 0000000..14c9bf0\n--- /dev/null\n+++ b/contrib/git-c2t.sh\n@@ -0,0 +1,46 @@\n+#!/bin/sh\n+\n+die () {\n+\techo \"$@\"\n+\trm -f \"$tagfile\"\n+ \texit 1\n+}\n+\n+warn () {\n+\techo \"$@\"\n+}\n+\n+test $# -eq 2 || die \"Usage: $0 <commit> <tagname>\"\n+\n+tagname=\"$2\"\n+commit=\"$1\"\n+\n+git rev-parse --verify -q \"$commit\" >/dev/null || die \"Cannot parse $commit.\"\n+\n+test x$(git cat-file -t $commit) == \"xcommit\" || die \"$commit is no commit.\"\n+\n+tagfile=$(mktemp)\n+\n+git cat-file commit \"$commit\" | {\n+\tread drop tree\n+\ttest $drop == \"tree\" || die \"No tree.\"\n+\tread drop parent\n+\ttest $drop = \"parent\" || die \"No parent.\"\n+\tread drop author\n+\ttest $drop == \"author\" || die \"No author.\"\n+\tread drop committer\n+\ttest $drop == \"committer\" || die \"No committer.\"\n+\ttest \"$author\" == \"$committer\" || warn \"author $author != committer $committer, taking author.\"\n+\tptree=$(git cat-file -p $parent|fgrep tree|head -1|cut -d' ' -f2)\n+\ttest $ptree == $tree || die \"commit $commit introduces a diff.\"\n+\tcat <<EOF >$tagfile\n+object $parent\n+type commit\n+tag $tagname\n+tagger $author\n+EOF\n+\tcat >>$tagfile\n+\thash=$(git hash-object -t tag -w \"$tagfile\")\n+\tgit tag \"$tagname\" $hash\n+}\n+rm -f $tagfile\n-- \n1.7.5.3.688.g647459\n"},{"id":"168873","messageId":"59fe17310157f99d5f20173ed65408d9e1f33462.1306504473.git.git@drmicha.warpmail.net","threadId":"27483","inReplyTo":"59fe17310157f99d5f20173ed65408d9e1f33462.1306504356.git.git@drmicha.warpmail.net","subject":"[PATCH/RFC] contrib: git-c2t converts tag creating commits to tags","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-05-27T13:55:33Z","receivedAt":"2011-05-27T13:55:33Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Introduce git-c2t <commit> <tag> which converts a commit object <commit>\ninto a tag object (and tags it with <tagname>), under the provision that\n<commit> has exactly one parent and has the same tree. That tag points\nat the parent commit.\n\nThis is useful for converting \"tag creating commits\" such as those\nproduced by git-svn into proper git tags. Tag creating commits typically\ncreate a \"1-commit side branch\" whereas the tag created by c2t points at\nthe pseudo fork point (the commit being tagged).\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n[And here with the notes, sorry.]\nThis is super useful for me but I dunno whether it should live in contrib/\n(or a subdir thereof).\n\nAlso, it is not that polished. I'd be happy to put it somewhere else if that's\nmore appropriate. (Noting again that we miss make install contrib/feature.)\n---\n contrib/git-c2t.sh |   46 ++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 46 insertions(+), 0 deletions(-)\n create mode 100755 contrib/git-c2t.sh\n\ndiff --git a/contrib/git-c2t.sh b/contrib/git-c2t.sh\nnew file mode 100755\nindex 0000000..14c9bf0\n--- /dev/null\n+++ b/contrib/git-c2t.sh\n@@ -0,0 +1,46 @@\n+#!/bin/sh\n+\n+die () {\n+\techo \"$@\"\n+\trm -f \"$tagfile\"\n+ \texit 1\n+}\n+\n+warn () {\n+\techo \"$@\"\n+}\n+\n+test $# -eq 2 || die \"Usage: $0 <commit> <tagname>\"\n+\n+tagname=\"$2\"\n+commit=\"$1\"\n+\n+git rev-parse --verify -q \"$commit\" >/dev/null || die \"Cannot parse $commit.\"\n+\n+test x$(git cat-file -t $commit) == \"xcommit\" || die \"$commit is no commit.\"\n+\n+tagfile=$(mktemp)\n+\n+git cat-file commit \"$commit\" | {\n+\tread drop tree\n+\ttest $drop == \"tree\" || die \"No tree.\"\n+\tread drop parent\n+\ttest $drop = \"parent\" || die \"No parent.\"\n+\tread drop author\n+\ttest $drop == \"author\" || die \"No author.\"\n+\tread drop committer\n+\ttest $drop == \"committer\" || die \"No committer.\"\n+\ttest \"$author\" == \"$committer\" || warn \"author $author != committer $committer, taking author.\"\n+\tptree=$(git cat-file -p $parent|fgrep tree|head -1|cut -d' ' -f2)\n+\ttest $ptree == $tree || die \"commit $commit introduces a diff.\"\n+\tcat <<EOF >$tagfile\n+object $parent\n+type commit\n+tag $tagname\n+tagger $author\n+EOF\n+\tcat >>$tagfile\n+\thash=$(git hash-object -t tag -w \"$tagfile\")\n+\tgit tag \"$tagname\" $hash\n+}\n+rm -f $tagfile\n-- \n1.7.5.3.688.g647459\n"}]}