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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxx>
---
[And here with the notes, sorry.]
This is super useful for me but I dunno whether it should live in contrib/
(or a subdir thereof).

Also, it is not that polished. I'd be happy to put it somewhere else if that's
more appropriate. (Noting again that we miss make install contrib/feature.)
---
 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

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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]