{"thread":{"id":"8741","subject":"[PATCH] git-submodule: Instead of using only annotated tags, use any tag found in .git/refs/tags","startedAt":"2007-06-26T23:40:58Z","lastAt":"2007-06-28T05:27:54Z","messageCount":4,"participants":["Emil Medve","Junio C Hamano","Medve Emilian-EMMEDVE1","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45859","messageId":"11829012583562-git-send-email-Emilian.Medve@Freescale.com","threadId":"8741","inReplyTo":null,"subject":"[PATCH] git-submodule: Instead of using only annotated tags, use any tag found in .git/refs/tags","fromName":"Emil Medve","fromEmail":"emilian.medve@freescale.com","sentAt":"2007-06-26T23:40:58Z","receivedAt":"2007-06-26T23:40:58Z","isPatch":true,"sender":{"key":"emilian.medve@freescale.com","avatar":null},"body":"Some repositories might not use/have annotated tags (for example repositories created with\ngit-cvsimport) and git-submodule status might fail because git-describe might fail to find a tag.\nThis change allows the status of a submodule to be described/displayed relative to lightweight tags\nas well.\n\nSigned-off-by: Emil Medve <Emilian.Medve@Freescale.com>\n---\n git-submodule.sh |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 89a3885..56ea935 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -155,7 +155,7 @@ modules_list()\n \t\t\tsay \"-$sha1 $path\"\n \t\t\tcontinue;\n \t\tfi\n-\t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe $sha1)\n+\t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe --tags $sha1)\n \t\tif git diff-files --quiet -- \"$path\"\n \t\tthen\n \t\t\tsay \" $sha1 $path ($revname)\"\n@@ -163,7 +163,7 @@ modules_list()\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n \t\t\t\tsha1=$(unset GIT_DIR && cd \"$path\" && git-rev-parse --verify HEAD)\n-\t\t\t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe $sha1)\n+\t\t\t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe --tags $sha1)\n \t\t\tfi\n \t\t\tsay \"+$sha1 $path ($revname)\"\n \t\tfi\n-- \n1.5.2.2.549.gaeb59\n"},{"id":"45892","messageId":"7vabulrki3.fsf@assigned-by-dhcp.pobox.com","threadId":"8741","inReplyTo":"11829012583562-git-send-email-Emilian.Medve@Freescale.com","subject":"Re: [PATCH] git-submodule: Instead of using only annotated tags, use any tag found in .git/refs/tags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-27T06:15:16Z","receivedAt":"2007-06-27T06:15:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Emil Medve <Emilian.Medve@Freescale.com> writes:\n\n> Some repositories might not use/have annotated tags (for\n> example repositories created with git-cvsimport) and\n> git-submodule status might fail because git-describe might\n> fail to find a tag.  This change allows the status of a\n> submodule to be described/displayed relative to lightweight\n> tags as well.\n\nCertainly that is an improvement, as $revname is purely for\ncommenting and not being able to describe it is not an excuse to\nfail the command.\n\nBut there may not be any tag at all.  How about something like\nthis on top?\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 56ea935..7b6195b 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -133,6 +133,18 @@ modules_update()\n \tdone\n }\n \n+set_name_rev () {\n+\trevname=$( (\n+\t\tunset GIT_DIR &&\n+\t\tcd \"$1\" && {\n+\t\t\tgit-describe \"$2\" 2>/dev/null ||\n+\t\t\tgit-describe --tags \"$2\" 2>/dev/null ||\n+\t\t\tgit-describe --contains --tags \"$2\"\n+\t\t}\n+\t) )\n+\ttest -z \"$revname\" || revname=\" ($revname)\"\n+}\n+\n #\n # List all submodules, prefixed with:\n #  - submodule not initialized\n@@ -156,16 +168,17 @@ modules_list()\n \t\t\tcontinue;\n \t\tfi\n \t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe --tags $sha1)\n+\t\tset_name_rev \"$path\" $\"sha1\"\n \t\tif git diff-files --quiet -- \"$path\"\n \t\tthen\n-\t\t\tsay \" $sha1 $path ($revname)\"\n+\t\t\tsay \" $sha1 $path$revname\"\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n \t\t\t\tsha1=$(unset GIT_DIR && cd \"$path\" && git-rev-parse --verify HEAD)\n-\t\t\t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe --tags $sha1)\n+\t\t\t\tset_name_rev \"$path\" $\"sha1\"\n \t\t\tfi\n-\t\t\tsay \"+$sha1 $path ($revname)\"\n+\t\t\tsay \"+$sha1 $path$revname\"\n \t\tfi\n \tdone\n }\n"},{"id":"45905","messageId":"598D5675D34BE349929AF5EDE9B03E27011CFD8F@az33exm24.fsl.freescale.net","threadId":"8741","inReplyTo":"7vabulrki3.fsf@assigned-by-dhcp.pobox.com","subject":"RE: [PATCH] git-submodule: Instead of using only annotated tags, use any tag found in .git/refs/tags","fromName":"Medve Emilian-EMMEDVE1","fromEmail":"emilian.medve@freescale.com","sentAt":"2007-06-27T12:20:02Z","receivedAt":"2007-06-27T12:20:02Z","isPatch":true,"sender":{"key":"emilian.medve@freescale.com","avatar":null},"body":"Hello Junio,\n\n\nYou're right and there might be no tag at all, thus --contains might\nreturn an undefined. In the spirit of best effort maybe we should try\n--all (which I don't think that can fail and it will return something\nmore relevant then undefined, i.e. the branch of the commit) if\n--contains returns undefined. I'll submit a patch to reflect this.\nOpinions?\n\nWhile playing with git-describe I noticed that the --all option is maybe\nnot trying first to find a tag as the man page suggests but it goes\ndirectly for .git/refs. Here is some output from my git repo clone with\nyesterday's head on the master branch:\n\n$ git-describe aeb59328453cd4f438345ea79ff04c96bccbbbb8\nv1.5.2.2-549-gaeb5932\n\n$ git-describe --all aeb59328453cd4f438345ea79ff04c96bccbbbb8\nheads/master\n\nDo you think we want to fix that? If yes, I could look into it and\nsubmit a patch.\n\n\n\nCheers,\nEmil.\n\n\nThis e-mail, and any associated attachments have been classified as:\n--------------------------------------------------------------------\n[x] Public\n[ ] Freescale Semiconductor Internal Use Only\n[ ] Freescale Semiconductor Confidential Proprietary\n\n\n-----Original Message-----\nFrom: Junio C Hamano [mailto:gitster@pobox.com] \nSent: Wednesday, June 27, 2007 1:15 AM\nTo: Medve Emilian-EMMEDVE1\nCc: git@vger.kernel.org\nSubject: Re: [PATCH] git-submodule: Instead of using only annotated\ntags, use any tag found in .git/refs/tags\n\nEmil Medve <Emilian.Medve@Freescale.com> writes:\n\n> Some repositories might not use/have annotated tags (for\n> example repositories created with git-cvsimport) and\n> git-submodule status might fail because git-describe might\n> fail to find a tag.  This change allows the status of a\n> submodule to be described/displayed relative to lightweight\n> tags as well.\n\nCertainly that is an improvement, as $revname is purely for\ncommenting and not being able to describe it is not an excuse to\nfail the command.\n\nBut there may not be any tag at all.  How about something like\nthis on top?\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 56ea935..7b6195b 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -133,6 +133,18 @@ modules_update()\n \tdone\n }\n \n+set_name_rev () {\n+\trevname=$( (\n+\t\tunset GIT_DIR &&\n+\t\tcd \"$1\" && {\n+\t\t\tgit-describe \"$2\" 2>/dev/null ||\n+\t\t\tgit-describe --tags \"$2\" 2>/dev/null ||\n+\t\t\tgit-describe --contains --tags \"$2\"\n+\t\t}\n+\t) )\n+\ttest -z \"$revname\" || revname=\" ($revname)\"\n+}\n+\n #\n # List all submodules, prefixed with:\n #  - submodule not initialized\n@@ -156,16 +168,17 @@ modules_list()\n \t\t\tcontinue;\n \t\tfi\n \t\trevname=$(unset GIT_DIR && cd \"$path\" && git-describe\n--tags $sha1)\n+\t\tset_name_rev \"$path\" $\"sha1\"\n \t\tif git diff-files --quiet -- \"$path\"\n \t\tthen\n-\t\t\tsay \" $sha1 $path ($revname)\"\n+\t\t\tsay \" $sha1 $path$revname\"\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n \t\t\t\tsha1=$(unset GIT_DIR && cd \"$path\" &&\ngit-rev-parse --verify HEAD)\n-\t\t\t\trevname=$(unset GIT_DIR && cd \"$path\" &&\ngit-describe --tags $sha1)\n+\t\t\t\tset_name_rev \"$path\" $\"sha1\"\n \t\t\tfi\n-\t\t\tsay \"+$sha1 $path ($revname)\"\n+\t\t\tsay \"+$sha1 $path$revname\"\n \t\tfi\n \tdone\n }\n"},{"id":"45954","messageId":"20070628052754.GJ32223@spearce.org","threadId":"8741","inReplyTo":"598D5675D34BE349929AF5EDE9B03E27011CFD8F@az33exm24.fsl.freescale.net","subject":"Re: [PATCH] git-submodule: Instead of using only annotated tags, use any tag found in .git/refs/tags","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-06-28T05:27:54Z","receivedAt":"2007-06-28T05:27:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Medve Emilian-EMMEDVE1 <Emilian.Medve@freescale.com> wrote:\n> While playing with git-describe I noticed that the --all option is maybe\n> not trying first to find a tag as the man page suggests but it goes\n> directly for .git/refs. Here is some output from my git repo clone with\n> yesterday's head on the master branch:\n> \n> $ git-describe aeb59328453cd4f438345ea79ff04c96bccbbbb8\n> v1.5.2.2-549-gaeb5932\n> \n> $ git-describe --all aeb59328453cd4f438345ea79ff04c96bccbbbb8\n> heads/master\n\nYea.  Look at what's happening.  In the --all case we attach\nheads/master into the ->util field of aeb5's struct commit*.\nSince no annotated tag (a ref with prio 2) and no lightweight tag\n(a ref with prio 1) was found pointing at aeb5 we kept that ->util\nfield pointing at the heads/master ref (which has prio 0).\n\nThe --all and --tags options are about selecting what refs can\nappear in that ->util field.  That's _all_ they do.\n\nLater in describe() at l.151 we immediately display a ref if there\nis one in the ->util field:\n\n    150     n = cmit->util;\n    151     if (n) {\n    152         printf(\"%s\\n\", n->path);\n    153         return;\n    154     }\n\nSo we're favoring a ref that points directly at a commit over any\nother ref.  We only search if we don't have a ref pointing directly\nat the input commit.  Searching is when ranking really gets involved.\n\n> Do you think we want to fix that? If yes, I could look into it and\n> submit a patch.\n\nI'm not sure.  If we \"fixed\" this then --all would only ever turn\nup a head if no annotated tag exists on the entire history of that\ninput commit.  Because the \"fix\" would be to actually not return\nright away here at l.151, but instead to drop down further into the\nslower loop where we traverse through commits, pick our candidates,\nrank them, and then pick the highest priorty ref that is also\nthe closest.  The annotated tag would always win over the head.\n\nAt which point --all is only ever useful if the repository *never*\nhad an annotated tag along the input branch.  I'm not sure that's\nuseful as a description for a commit.  If no annotated tag exists\nthe raw commit SHA-1 is probably a better description.  Its at\nleast stable with time.  ;-)\n\n\nIn my opinion, git-describe is doing *exactly* what the manual page\nsays it does.  But both the current implementation and the manual\npage were last majorly overhauld by me.  So take my comments about\nthe documentation with a grain of salt.  ;-)\n\n-- \nShawn.\n"}]}