{"thread":{"id":"33180","subject":"[PATCH v2] git-tag: Allow --points-at syntax to create a tag pointing to specified commit","startedAt":"2013-03-14T12:34:54Z","lastAt":"2013-03-14T15:48:25Z","messageCount":4,"participants":["Michal Novotny","John Keeping","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"211289","messageId":"4150f65f3e425d6120ed80c6bec36c1fe209a876.1363264398.git.minovotn@redhat.com","threadId":"33180","inReplyTo":null,"subject":"[PATCH v2] git-tag: Allow --points-at syntax to create a tag pointing to specified commit","fromName":"Michal Novotny","fromEmail":"minovotn@redhat.com","sentAt":"2013-03-14T12:34:54Z","receivedAt":"2013-03-14T12:34:54Z","isPatch":true,"sender":{"key":"minovotn@redhat.com","avatar":null},"body":"This patch adds the option to specify SHA-1 commit hash using --points-at\noption of git tag to create a tag pointing to a historical commit.\n\nThis was pretty easy in the past for the lightweight tags that are just simple\npointers (by creating .git/refs/tags/$tagname with SHA-1 hash) but it was not\npossible for signed and annotated commits.\n\nIt's been tested for all of the tag types mentioned - lightweight tags, signed\ntags and also annotated tags and everything is working fine in all scenarios\nmentioned above.\n\nDifferences between v1 and v2 (this one):\n - The bogus sha1-lookup.h hunk has been removed as it's not required and\n   I accidentally forgot to remove it before posting v1\n\nMichal\n\nSigned-off-by: Michal Novotny <minovotn@redhat.com>\n---\n builtin/tag.c | 32 ++++++++++++++++++++++++++------\n 1 file changed, 26 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex f826688..f642acd 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -437,7 +437,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstruct create_tag_options opt;\n \tchar *cleanup_arg = NULL;\n \tint annotate = 0, force = 0, lines = -1, list = 0,\n-\t\tdelete = 0, verify = 0;\n+\t\tdelete = 0, verify = 0, points_at_commit = 0;\n \tconst char *msgfile = NULL, *keyid = NULL;\n \tstruct msg_arg msg = { 0, STRBUF_INIT };\n \tstruct commit_list *with_commit = NULL;\n@@ -521,8 +521,24 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"-n option is only allowed with -l.\"));\n \tif (with_commit)\n \t\tdie(_(\"--contains option is only allowed with -l.\"));\n-\tif (points_at.nr)\n-\t\tdie(_(\"--points-at option is only allowed with -l.\"));\n+\tif (points_at.nr) {\n+\t\tif (points_at.nr > 1)\n+\t\t\tdie(_(\"--points-at option is only allowed with -l or a single \"\n+\t\t\t\t\"SHA-1 hash is allowed to create a tag to commit.\"));\n+\t\telse {\n+\t\t\tunsigned char *ref = points_at.sha1[0];\n+\n+\t\t\tstruct object *obj = parse_object(ref);\n+\t\t\tif ((obj != NULL) && (obj->type == OBJ_COMMIT)) {\n+\t\t\t\tmemcpy(object, ref, 20);\n+\t\t\t\tpoints_at_commit = 1;\n+\t\t\t}\n+\t\t\telse\n+\t\t\t\tdie(_(\"--points-at option points to an invalid commit\"));\n+\n+\t\t\tfree(ref);\n+\t\t}\n+\t}\n \tif (delete)\n \t\treturn for_each_tag_name(argv, delete_tag);\n \tif (verify)\n@@ -548,12 +564,16 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \n \ttag = argv[0];\n \n-\tobject_ref = argc == 2 ? argv[1] : \"HEAD\";\n \tif (argc > 2)\n \t\tdie(_(\"too many params\"));\n \n-\tif (get_sha1(object_ref, object))\n-\t\tdie(_(\"Failed to resolve '%s' as a valid ref.\"), object_ref);\n+\t/* Option --points-at option is setting this already */\n+\tif (!points_at_commit) {\n+\t\tobject_ref = argc == 2 ? argv[1] : \"HEAD\";\n+\n+\t\tif (get_sha1(object_ref, object))\n+\t\t\tdie(_(\"Failed to resolve '%s' as a valid ref.\"), object_ref);\n+\t}\n \n \tif (strbuf_check_tag_ref(&ref, tag))\n \t\tdie(_(\"'%s' is not a valid tag name.\"), tag);\n-- \n1.7.11.7\n"},{"id":"211293","messageId":"20130314133629.GA4256@serenity.lan","threadId":"33180","inReplyTo":"4150f65f3e425d6120ed80c6bec36c1fe209a876.1363264398.git.minovotn@redhat.com","subject":"Re: [PATCH v2] git-tag: Allow --points-at syntax to create a tag pointing to specified commit","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-03-14T13:36:29Z","receivedAt":"2013-03-14T13:36:29Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Thu, Mar 14, 2013 at 01:34:54PM +0100, Michal Novotny wrote:\n> This patch adds the option to specify SHA-1 commit hash using --points-at\n> option of git tag to create a tag pointing to a historical commit.\n\nWhat does this do that \"git tag <name> <commit>\" doesn't?\n\n> This was pretty easy in the past for the lightweight tags that are just simple\n> pointers (by creating .git/refs/tags/$tagname with SHA-1 hash) but it was not\n> possible for signed and annotated commits.\n> \n> It's been tested for all of the tag types mentioned - lightweight tags, signed\n> tags and also annotated tags and everything is working fine in all scenarios\n> mentioned above.\n> \n> Differences between v1 and v2 (this one):\n>  - The bogus sha1-lookup.h hunk has been removed as it's not required and\n>    I accidentally forgot to remove it before posting v1\n> \n> Michal\n> \n> Signed-off-by: Michal Novotny <minovotn@redhat.com>\n> ---\n>  builtin/tag.c | 32 ++++++++++++++++++++++++++------\n>  1 file changed, 26 insertions(+), 6 deletions(-)\n> \n> diff --git a/builtin/tag.c b/builtin/tag.c\n> index f826688..f642acd 100644\n> --- a/builtin/tag.c\n> +++ b/builtin/tag.c\n> @@ -437,7 +437,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>  \tstruct create_tag_options opt;\n>  \tchar *cleanup_arg = NULL;\n>  \tint annotate = 0, force = 0, lines = -1, list = 0,\n> -\t\tdelete = 0, verify = 0;\n> +\t\tdelete = 0, verify = 0, points_at_commit = 0;\n>  \tconst char *msgfile = NULL, *keyid = NULL;\n>  \tstruct msg_arg msg = { 0, STRBUF_INIT };\n>  \tstruct commit_list *with_commit = NULL;\n> @@ -521,8 +521,24 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>  \t\tdie(_(\"-n option is only allowed with -l.\"));\n>  \tif (with_commit)\n>  \t\tdie(_(\"--contains option is only allowed with -l.\"));\n> -\tif (points_at.nr)\n> -\t\tdie(_(\"--points-at option is only allowed with -l.\"));\n> +\tif (points_at.nr) {\n> +\t\tif (points_at.nr > 1)\n> +\t\t\tdie(_(\"--points-at option is only allowed with -l or a single \"\n> +\t\t\t\t\"SHA-1 hash is allowed to create a tag to commit.\"));\n> +\t\telse {\n> +\t\t\tunsigned char *ref = points_at.sha1[0];\n> +\n> +\t\t\tstruct object *obj = parse_object(ref);\n> +\t\t\tif ((obj != NULL) && (obj->type == OBJ_COMMIT)) {\n> +\t\t\t\tmemcpy(object, ref, 20);\n> +\t\t\t\tpoints_at_commit = 1;\n> +\t\t\t}\n> +\t\t\telse\n> +\t\t\t\tdie(_(\"--points-at option points to an invalid commit\"));\n> +\n> +\t\t\tfree(ref);\n> +\t\t}\n> +\t}\n>  \tif (delete)\n>  \t\treturn for_each_tag_name(argv, delete_tag);\n>  \tif (verify)\n> @@ -548,12 +564,16 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>  \n>  \ttag = argv[0];\n>  \n> -\tobject_ref = argc == 2 ? argv[1] : \"HEAD\";\n>  \tif (argc > 2)\n>  \t\tdie(_(\"too many params\"));\n>  \n> -\tif (get_sha1(object_ref, object))\n> -\t\tdie(_(\"Failed to resolve '%s' as a valid ref.\"), object_ref);\n> +\t/* Option --points-at option is setting this already */\n> +\tif (!points_at_commit) {\n> +\t\tobject_ref = argc == 2 ? argv[1] : \"HEAD\";\n> +\n> +\t\tif (get_sha1(object_ref, object))\n> +\t\t\tdie(_(\"Failed to resolve '%s' as a valid ref.\"), object_ref);\n> +\t}\n>  \n>  \tif (strbuf_check_tag_ref(&ref, tag))\n>  \t\tdie(_(\"'%s' is not a valid tag name.\"), tag);\n> -- \n> 1.7.11.7\n"},{"id":"211297","messageId":"5141E056.3090808@redhat.com","threadId":"33180","inReplyTo":"20130314133629.GA4256@serenity.lan","subject":"Re: [PATCH v2] git-tag: Allow --points-at syntax to create a tag pointing to specified commit","fromName":"Michal Novotny","fromEmail":"minovotn@redhat.com","sentAt":"2013-03-14T14:36:06Z","receivedAt":"2013-03-14T14:36:06Z","isPatch":true,"sender":{"key":"minovotn@redhat.com","avatar":null},"body":"\nOn 03/14/2013 02:36 PM, John Keeping wrote:\n> On Thu, Mar 14, 2013 at 01:34:54PM +0100, Michal Novotny wrote:\n>> This patch adds the option to specify SHA-1 commit hash using --points-at\n>> option of git tag to create a tag pointing to a historical commit.\n> What does this do that \"git tag <name> <commit>\" doesn't?\n\nOh, interesting. It's working now and I didn't know that as it was not\nworking some time ago I've been trying this approach. Maybe it's been\nadded recently as I also saw several sites having different approach of\ntagging to specified commit (usually creating a new branch, tagging\nthere and rebasing etc.).\n\nThanks for information!\nMichal\n\n-- \nMichal Novotny <minovotn@redhat.com>, RHCE, Red Hat\nVirtualization | libvirt-php bindings | php-virt-control.org\n"},{"id":"211306","messageId":"7v38vyyoc6.fsf@alter.siamese.dyndns.org","threadId":"33180","inReplyTo":"5141E056.3090808@redhat.com","subject":"Re: [PATCH v2] git-tag: Allow --points-at syntax to create a tag pointing to specified commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-14T15:48:25Z","receivedAt":"2013-03-14T15:48:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michal Novotny <minovotn@redhat.com> writes:\n\n> Oh, interesting. It's working now and I didn't know that as it was not\n> working some time ago I've been trying this approach. Maybe it's been\n> added recently...\n\nPretty much from the very beginning \"git tag <name> <commit>\" has\nbeen the way to create a tag, with missing <commit> defaulting to\nHEAD.  In retrospect, it _might_ have been a more consistent UI\norganization if the object to point the new tag at were given with a\ncommand line argument like --point-at=<object>, absence of which\ndefaults to HEAD, but it is a bit too late for that.\n\nBy the way, your implementation is wrong and it shows that you are\nnot aware that a tag, either annotated or lightweight, can point at\nany object, not just a commit.\n\n> ... as I also saw several sites having different approach of\n> tagging to specified commit (usually creating a new branch, tagging\n> there and rebasing etc.).\n\nThere are at least two explanations that are more plausible than\nthat.\n\nWhen rebasing an existing branch, especially if you are not familiar\nwith Git and want to be extra cautious, it is not unreasonable to\npractice it by running the rebase on a new branch that you are\nwilling to discard when something goes in an unexpected way.  If the\ntip of that throw-away branch happens to be where you want to tag,\nit is easier to do\n\n\tgit checkout -b new-branch <<some long object name>>\n        git tag return-here\n\nthan\n\n\tgit checkout -b new-branch <<some long object name>>\n        git tag return-here <<the same long object name again>>\n\nSo it is understandable that \"if untold, default to HEAD\" is used in\nsuch a workflow.  After all, we made it to default to HEAD exactly\nbecause that is one of the most common thing to do.\n\nAnother plausible explanation is that these \"sites\" are written by\npeople who do not know what they are writing, which is not a big\nnews in the Internet.\n\nIt would surely be nice to get these \"sites\" fixed.\n"}]}