From: Michael J Gruber Date: Fri, 27 May 2011 13:55:33 GMT Subject: [PATCH/RFC] contrib: git-c2t converts tag creating commits to tags Message-ID: <59fe17310157f99d5f20173ed65408d9e1f33462.1306504473.git.git@drmicha.warpmail.net> In-Reply-To: <59fe17310157f99d5f20173ed65408d9e1f33462.1306504356.git.git@drmicha.warpmail.net> Introduce git-c2t which converts a commit object into a tag object (and tags it with ), under the provision that 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 --- [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 " + +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 <$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