{"thread":{"id":"13535","subject":"How can I tell if a SHA1 is a submodule reference?","startedAt":"2008-05-15T19:39:03Z","lastAt":"2008-05-15T20:56:02Z","messageCount":5,"participants":["Robin Luckey","Avery Pennarun","Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"77067","messageId":"7F242E8F-13CF-4BE5-B3E6-85F285391658@ohloh.net","threadId":"13535","inReplyTo":null,"subject":"How can I tell if a SHA1 is a submodule reference?","fromName":"Robin Luckey","fromEmail":"robin@ohloh.net","sentAt":"2008-05-15T19:39:03Z","receivedAt":"2008-05-15T19:39:03Z","isPatch":false,"sender":{"key":"robin@ohloh.net","avatar":null},"body":"I am parsing the output of git-diff-tree to create some code analysis  \nreports.\n\nWhen a user adds a submodule to a repository, git-diff-tree reports  \nthe SHA1 of the commit from the submodule.\n\nHowever, if I subsequently try to pass this SHA1 to git-cat-file, or  \nindeed any other git command I have tried, I receive an error:\n\nerror: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e\nfatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e\n\nThis makes sense to me, since these objects are not stored locally;  \nthey are stored in the submodule repository.\n\nHowever, is there a simple and reliable way for me to know which SHA1  \nhashes refer to such submodule objects? I'd like to simply ignore them.\n\nMy ideal feature would be that `git cat-file -t` would respond with  \n`submodule`, but of course this does not happen. Long term, an '-- \ningore-submodules' flag for git would be great since I wouldn't see  \nthese hashes in the first place.\n\nHowever, today, given an arbitrary hash, how can I tell whether it is  \na submodule commit?\n\nThanks,\nRobin\n"},{"id":"77069","messageId":"32541b130805151312p7a08a0b7id7c12bc8a04e2aca@mail.gmail.com","threadId":"13535","inReplyTo":"7F242E8F-13CF-4BE5-B3E6-85F285391658@ohloh.net","subject":"Re: How can I tell if a SHA1 is a submodule reference?","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-05-15T20:12:10Z","receivedAt":"2008-05-15T20:12:10Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On 5/15/08, Robin Luckey <robin@ohloh.net> wrote:\n>  However, is there a simple and reliable way for me to know which SHA1\n> hashes refer to such submodule objects? I'd like to simply ignore them.\n\nI don't think there's a straightforward way to do this given *just*\nthe SHA1, in the same way that you can't know the path corresponding\nto a blob given just its SHA1.\n\nHowever, if you're looking at a tree that refers to a SHA1, the tree\nwill reference a submodule object as a \"commit\" instead of a \"tree\" or\n\"blob\".  git-ls-tree output looks something like this:\n\n160000 commit ba75ff608fabafeaafeb48d55b125440b5a665bc\tmy_subdir\n\nI think it's reasonable to say that if it's type commit, then it's a\nsubmodule.  (Note that simply being a submodule doesn't *necessarily*\nimply that it'll be unavailable; some people like to store all the\nsubmodule objects in the local repository.)\n\nHave fun,\n\nAvery\n"},{"id":"77070","messageId":"alpine.LFD.1.10.0805151311050.3019@woody.linux-foundation.org","threadId":"13535","inReplyTo":"7F242E8F-13CF-4BE5-B3E6-85F285391658@ohloh.net","subject":"Re: How can I tell if a SHA1 is a submodule reference?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-05-15T20:13:24Z","receivedAt":"2008-05-15T20:13:24Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 15 May 2008, Robin Luckey wrote:\n>\n> I am parsing the output of git-diff-tree to create some code analysis reports.\n> \n> When a user adds a submodule to a repository, git-diff-tree reports the SHA1\n> of the commit from the submodule.\n> \n> However, if I subsequently try to pass this SHA1 to git-cat-file, or indeed\n> any other git command I have tried, I receive an error:\n> \n> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e\n> fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e\n> \n> This makes sense to me, since these objects are not stored locally; they are\n> stored in the submodule repository.\n> \n> However, is there a simple and reliable way for me to know which SHA1 hashes\n> refer to such submodule objects? I'd like to simply ignore them.\n\nOnly if you still have the tree references they came from.\n\nIn other words, once you *only* have the SHA1, you're kind of screwed, \nbecause by that time you've lost the context, and the SHA1 itself contains \nno information about what kind of thing it is.\n\nBut when running git-diff-tree, you still have the source of the SHA1, and \nthe tree entry in particular. The tree entry will have a \"gitlink\" marker, \nie the \"mode\" will be 0160000. \n\n\t\t\tLinus\n"},{"id":"77071","messageId":"7vabirgvyg.fsf@gitster.siamese.dyndns.org","threadId":"13535","inReplyTo":"7F242E8F-13CF-4BE5-B3E6-85F285391658@ohloh.net","subject":"Re: How can I tell if a SHA1 is a submodule reference?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-15T20:21:11Z","receivedAt":"2008-05-15T20:21:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robin Luckey <robin@ohloh.net> writes:\n\n> I am parsing the output of git-diff-tree to create some code analysis\n> reports.\n>\n> When a user adds a submodule to a repository, git-diff-tree reports\n> the SHA1 of the commit from the submodule.\n>\n> However, if I subsequently try to pass this SHA1 to git-cat-file, or\n> indeed any other git command I have tried, I receive an error:\n>\n> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e\n> fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e\n>\n> This makes sense to me, since these objects are not stored locally;\n> they are stored in the submodule repository.\n>\n> However, is there a simple and reliable way for me to know which SHA1\n> hashes refer to such submodule objects? I'd like to simply ignore them.\n\nI presume you are reading \"diff-tree --raw\" format output.  The mode bits\nfor submodules (aka gitlinks) are 160000, as opposed to either 100644 or\n100755 for regular files and 120000 for symbolic links.\n"},{"id":"77074","messageId":"90B9CF74-40E1-4469-AFF9-D8D349F6C80D@ohloh.net","threadId":"13535","inReplyTo":"7vabirgvyg.fsf@gitster.siamese.dyndns.org","subject":"Re: How can I tell if a SHA1 is a submodule reference?","fromName":"Robin Luckey","fromEmail":"robin@ohloh.net","sentAt":"2008-05-15T20:56:02Z","receivedAt":"2008-05-15T20:56:02Z","isPatch":false,"sender":{"key":"robin@ohloh.net","avatar":null},"body":"Thanks for the replies -- checking the mode bits was the ticket.\n\nRobin\n\nOn May 15, 2008, at 1:21 PM, Junio C Hamano wrote:\n\n> Robin Luckey <robin@ohloh.net> writes:\n>\n>> I am parsing the output of git-diff-tree to create some code analysis\n>> reports.\n>>\n>> When a user adds a submodule to a repository, git-diff-tree reports\n>> the SHA1 of the commit from the submodule.\n>>\n>> However, if I subsequently try to pass this SHA1 to git-cat-file, or\n>> indeed any other git command I have tried, I receive an error:\n>>\n>> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e\n>> fatal: Not a valid object name  \n>> b0f8c354b142e27333abd0f175544b71a0cc444e\n>>\n>> This makes sense to me, since these objects are not stored locally;\n>> they are stored in the submodule repository.\n>>\n>> However, is there a simple and reliable way for me to know which SHA1\n>> hashes refer to such submodule objects? I'd like to simply ignore  \n>> them.\n>\n> I presume you are reading \"diff-tree --raw\" format output.  The mode  \n> bits\n> for submodules (aka gitlinks) are 160000, as opposed to either  \n> 100644 or\n> 100755 for regular files and 120000 for symbolic links.\n>\n>\n"}]}