Git development
 help / color / mirror / Atom feed
* How can I tell if a SHA1 is a submodule reference?
@ 2008-05-15 19:39 Robin Luckey
  2008-05-15 20:12 ` Avery Pennarun
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Robin Luckey @ 2008-05-15 19:39 UTC (permalink / raw)
  To: git

I am parsing the output of git-diff-tree to create some code analysis  
reports.

When a user adds a submodule to a repository, git-diff-tree reports  
the SHA1 of the commit from the submodule.

However, if I subsequently try to pass this SHA1 to git-cat-file, or  
indeed any other git command I have tried, I receive an error:

error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e
fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e

This makes sense to me, since these objects are not stored locally;  
they are stored in the submodule repository.

However, is there a simple and reliable way for me to know which SHA1  
hashes refer to such submodule objects? I'd like to simply ignore them.

My ideal feature would be that `git cat-file -t` would respond with  
`submodule`, but of course this does not happen. Long term, an '-- 
ingore-submodules' flag for git would be great since I wouldn't see  
these hashes in the first place.

However, today, given an arbitrary hash, how can I tell whether it is  
a submodule commit?

Thanks,
Robin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How can I tell if a SHA1 is a submodule reference?
  2008-05-15 19:39 How can I tell if a SHA1 is a submodule reference? Robin Luckey
@ 2008-05-15 20:12 ` Avery Pennarun
  2008-05-15 20:13 ` Linus Torvalds
  2008-05-15 20:21 ` Junio C Hamano
  2 siblings, 0 replies; 5+ messages in thread
From: Avery Pennarun @ 2008-05-15 20:12 UTC (permalink / raw)
  To: Robin Luckey; +Cc: git

On 5/15/08, Robin Luckey <robin@ohloh.net> wrote:
>  However, is there a simple and reliable way for me to know which SHA1
> hashes refer to such submodule objects? I'd like to simply ignore them.

I don't think there's a straightforward way to do this given *just*
the SHA1, in the same way that you can't know the path corresponding
to a blob given just its SHA1.

However, if you're looking at a tree that refers to a SHA1, the tree
will reference a submodule object as a "commit" instead of a "tree" or
"blob".  git-ls-tree output looks something like this:

160000 commit ba75ff608fabafeaafeb48d55b125440b5a665bc	my_subdir

I think it's reasonable to say that if it's type commit, then it's a
submodule.  (Note that simply being a submodule doesn't *necessarily*
imply that it'll be unavailable; some people like to store all the
submodule objects in the local repository.)

Have fun,

Avery

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How can I tell if a SHA1 is a submodule reference?
  2008-05-15 19:39 How can I tell if a SHA1 is a submodule reference? Robin Luckey
  2008-05-15 20:12 ` Avery Pennarun
@ 2008-05-15 20:13 ` Linus Torvalds
  2008-05-15 20:21 ` Junio C Hamano
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 2008-05-15 20:13 UTC (permalink / raw)
  To: Robin Luckey; +Cc: git



On Thu, 15 May 2008, Robin Luckey wrote:
>
> I am parsing the output of git-diff-tree to create some code analysis reports.
> 
> When a user adds a submodule to a repository, git-diff-tree reports the SHA1
> of the commit from the submodule.
> 
> However, if I subsequently try to pass this SHA1 to git-cat-file, or indeed
> any other git command I have tried, I receive an error:
> 
> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e
> fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e
> 
> This makes sense to me, since these objects are not stored locally; they are
> stored in the submodule repository.
> 
> However, is there a simple and reliable way for me to know which SHA1 hashes
> refer to such submodule objects? I'd like to simply ignore them.

Only if you still have the tree references they came from.

In other words, once you *only* have the SHA1, you're kind of screwed, 
because by that time you've lost the context, and the SHA1 itself contains 
no information about what kind of thing it is.

But when running git-diff-tree, you still have the source of the SHA1, and 
the tree entry in particular. The tree entry will have a "gitlink" marker, 
ie the "mode" will be 0160000. 

			Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How can I tell if a SHA1 is a submodule reference?
  2008-05-15 19:39 How can I tell if a SHA1 is a submodule reference? Robin Luckey
  2008-05-15 20:12 ` Avery Pennarun
  2008-05-15 20:13 ` Linus Torvalds
@ 2008-05-15 20:21 ` Junio C Hamano
  2008-05-15 20:56   ` Robin Luckey
  2 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2008-05-15 20:21 UTC (permalink / raw)
  To: Robin Luckey; +Cc: git

Robin Luckey <robin@ohloh.net> writes:

> I am parsing the output of git-diff-tree to create some code analysis
> reports.
>
> When a user adds a submodule to a repository, git-diff-tree reports
> the SHA1 of the commit from the submodule.
>
> However, if I subsequently try to pass this SHA1 to git-cat-file, or
> indeed any other git command I have tried, I receive an error:
>
> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e
> fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e
>
> This makes sense to me, since these objects are not stored locally;
> they are stored in the submodule repository.
>
> However, is there a simple and reliable way for me to know which SHA1
> hashes refer to such submodule objects? I'd like to simply ignore them.

I presume you are reading "diff-tree --raw" format output.  The mode bits
for submodules (aka gitlinks) are 160000, as opposed to either 100644 or
100755 for regular files and 120000 for symbolic links.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How can I tell if a SHA1 is a submodule reference?
  2008-05-15 20:21 ` Junio C Hamano
@ 2008-05-15 20:56   ` Robin Luckey
  0 siblings, 0 replies; 5+ messages in thread
From: Robin Luckey @ 2008-05-15 20:56 UTC (permalink / raw)
  To: Junio C Hamano, Linus Torvalds, Avery Pennarun; +Cc: git

Thanks for the replies -- checking the mode bits was the ticket.

Robin

On May 15, 2008, at 1:21 PM, Junio C Hamano wrote:

> Robin Luckey <robin@ohloh.net> writes:
>
>> I am parsing the output of git-diff-tree to create some code analysis
>> reports.
>>
>> When a user adds a submodule to a repository, git-diff-tree reports
>> the SHA1 of the commit from the submodule.
>>
>> However, if I subsequently try to pass this SHA1 to git-cat-file, or
>> indeed any other git command I have tried, I receive an error:
>>
>> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e
>> fatal: Not a valid object name  
>> b0f8c354b142e27333abd0f175544b71a0cc444e
>>
>> This makes sense to me, since these objects are not stored locally;
>> they are stored in the submodule repository.
>>
>> However, is there a simple and reliable way for me to know which SHA1
>> hashes refer to such submodule objects? I'd like to simply ignore  
>> them.
>
> I presume you are reading "diff-tree --raw" format output.  The mode  
> bits
> for submodules (aka gitlinks) are 160000, as opposed to either  
> 100644 or
> 100755 for regular files and 120000 for symbolic links.
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-05-15 20:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-15 19:39 How can I tell if a SHA1 is a submodule reference? Robin Luckey
2008-05-15 20:12 ` Avery Pennarun
2008-05-15 20:13 ` Linus Torvalds
2008-05-15 20:21 ` Junio C Hamano
2008-05-15 20:56   ` Robin Luckey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox