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

[PATCH/RFC] contrib: git-c2t converts tag creating commits to tags

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
May 27, 2011, 13:52 UTC
Message-ID
<59fe17310157f99d5f20173ed65408d9e1f33462.1306504356.git.git@drmicha.warpmail.net>

Introduce git-c2t <commit> <tag> which converts a commit object <commit> into a tag object (and tags it with <tagname>), under the provision that <commit> has exactly one parent and has the same tree. That tag points at the parent commit.

This is useful for converting "tag creating commits" such as those produced by git-svn into proper git tags. Tag creating commits typically create a "1-commit side branch" whereas the tag created by c2t points at the pseudo fork point (the commit being tagged).

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 contrib/git-c2t.sh |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100755 contrib/git-c2t.sh
diff --git a/contrib/git-c2t.sh b/contrib/git-c2t.sh
new file mode 100755
index 0000000..14c9bf0
--- /dev/null
+++ b/contrib/git-c2t.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+die () {
+	echo "$@"
+	rm -f "$tagfile"
+ 	exit 1
+}
+
+warn () {
+	echo "$@"
+}
+
+test $# -eq 2 || die "Usage: $0 <commit> <tagname>"
+
+tagname="$2"
+commit="$1"
+
+git rev-parse --verify -q "$commit" >/dev/null || die "Cannot parse $commit."
+
+test x$(git cat-file -t $commit) == "xcommit" || die "$commit is no commit."
+
+tagfile=$(mktemp)
+
+git cat-file commit "$commit" | {
+	read drop tree
+	test $drop == "tree" || die "No tree."
+	read drop parent
+	test $drop = "parent" || die "No parent."
+	read drop author
+	test $drop == "author" || die "No author."
+	read drop committer
+	test $drop == "committer" || die "No committer."
+	test "$author" == "$committer" || warn "author $author != committer $committer, taking author."
+	ptree=$(git cat-file -p $parent|fgrep tree|head -1|cut -d' ' -f2)
+	test $ptree == $tree || die "commit $commit introduces a diff."
+	cat <<EOF >$tagfile
+object $parent
+type commit
+tag $tagname
+tagger $author
+EOF
+	cat >>$tagfile
+	hash=$(git hash-object -t tag -w "$tagfile")
+	git tag "$tagname" $hash
+}
+rm -f $tagfile
-- 
1.7.5.3.688.g647459
Next: Michael J Gruber
Message 1 of 2 in “contrib: git-c2t converts tag creating commits to tags”
  1. contrib: git-c2t converts tag creating commits to tagsMichael J Gruber, May 27, 2011
  2. contrib: git-c2t converts tag creating commits to tagsMichael J Gruber, May 27, 2011

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.