git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Enumerating all objects in the Git object store
@ 2010-03-26 15:31 Paul Richards
  2010-03-26 15:53 ` Johannes Sixt
  2010-03-27 13:33 ` Michael J Gruber
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Richards @ 2010-03-26 15:31 UTC (permalink / raw)
  To: git

Hi,
I'd like to visualize the objects in a Git repository using Graphviz
and "dot".  I'd like to see commits as circles, trees as triangles,
blobs as rectangles, and have arrows linking these objects showing how
they reference each other in the Git DAG.  For small repositories this
may be a useful way to visualize how Git objects work.

I could not find a pre-existing script to do this so I am considering
writing one.  Is there a way to enumerate all the objects in the Git
object store, and for each one figure out its type (commit, tree, or
blob) and obtain a list of the objects it references?  If not, is
there a way to do this for a single object at a time?  (I can then
simply recurse through the whole structure.)


-- 
Paul Richards

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 15:31 Enumerating all objects in the Git object store Paul Richards
@ 2010-03-26 15:53 ` Johannes Sixt
  2010-03-26 16:13   ` Jakub Narebski
                     ` (2 more replies)
  2010-03-27 13:33 ` Michael J Gruber
  1 sibling, 3 replies; 8+ messages in thread
From: Johannes Sixt @ 2010-03-26 15:53 UTC (permalink / raw)
  To: Paul Richards; +Cc: git

Am 3/26/2010 16:31, schrieb Paul Richards:
> Is there a way to enumerate all the objects in the Git
> object store, and for each one figure out its type (commit, tree, or
> blob) and obtain a list of the objects it references?  If not, is
> there a way to do this for a single object at a time?  (I can then
> simply recurse through the whole structure.)

Use 'git rev-list --objects --all' to find all objects connected to all
refs (use something else than --all if you want to). Do *not* look at the
path that the tree and blob objects have attached - it is not authorative
information.

Use 'git cat-file -t' to find the type.

Use 'git cat-file -p' to pretty-print the content of an object. Parse it
depending on the type that you find.

-- Hannes

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 15:53 ` Johannes Sixt
@ 2010-03-26 16:13   ` Jakub Narebski
  2010-03-26 17:25   ` Nicolas Pitre
  2010-03-26 21:11   ` Paul Richards
  2 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2010-03-26 16:13 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Paul Richards, git

Johannes Sixt <j.sixt@viscovery.net> writes:

> Am 3/26/2010 16:31, schrieb Paul Richards:
> > Is there a way to enumerate all the objects in the Git
> > object store, and for each one figure out its type (commit, tree, or
> > blob) and obtain a list of the objects it references?  If not, is
> > there a way to do this for a single object at a time?  (I can then
> > simply recurse through the whole structure.)
> 
> Use 'git rev-list --objects --all' to find all objects connected to all
> refs (use something else than --all if you want to). Do *not* look at the
> path that the tree and blob objects have attached - it is not authorative
> information.
> 
> Use 'git cat-file -t' to find the type.

For performance it would be better to feed `git rev-list --objects --all`
output to `git cat-file --batch-check` instead.
 
> Use 'git cat-file -p' to pretty-print the content of an object. Parse it
> depending on the type that you find.

For performance it would be better to use `git cat-file --batch`...
but on the other hand side you would have to parse "binary" tree objects
representation.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 15:53 ` Johannes Sixt
  2010-03-26 16:13   ` Jakub Narebski
@ 2010-03-26 17:25   ` Nicolas Pitre
  2010-03-26 20:11     ` Johannes Sixt
  2010-03-26 21:11   ` Paul Richards
  2 siblings, 1 reply; 8+ messages in thread
From: Nicolas Pitre @ 2010-03-26 17:25 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Paul Richards, git

On Fri, 26 Mar 2010, Johannes Sixt wrote:

> Use 'git rev-list --objects --all' to find all objects connected to all
> refs (use something else than --all if you want to). Do *not* look at the
> path that the tree and blob objects have attached - it is not authorative
> information.

Really??


Nicolas

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 17:25   ` Nicolas Pitre
@ 2010-03-26 20:11     ` Johannes Sixt
  2010-03-26 20:24       ` Nicolas Pitre
  0 siblings, 1 reply; 8+ messages in thread
From: Johannes Sixt @ 2010-03-26 20:11 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Paul Richards, git

On Freitag, 26. März 2010, Nicolas Pitre wrote:
> On Fri, 26 Mar 2010, Johannes Sixt wrote:
> > Use 'git rev-list --objects --all' to find all objects connected to all
> > refs (use something else than --all if you want to). Do *not* look at the
> > path that the tree and blob objects have attached - it is not authorative
> > information.
>
> Really??

Yes, really. Consider the same content at two differen paths. Now what? 
rev-list will only ever list the object once.

-- Hannes

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 20:11     ` Johannes Sixt
@ 2010-03-26 20:24       ` Nicolas Pitre
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Pitre @ 2010-03-26 20:24 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Paul Richards, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 589 bytes --]

On Fri, 26 Mar 2010, Johannes Sixt wrote:

> On Freitag, 26. März 2010, Nicolas Pitre wrote:
> > On Fri, 26 Mar 2010, Johannes Sixt wrote:
> > > Use 'git rev-list --objects --all' to find all objects connected to all
> > > refs (use something else than --all if you want to). Do *not* look at the
> > > path that the tree and blob objects have attached - it is not authorative
> > > information.
> >
> > Really??
> 
> Yes, really. Consider the same content at two differen paths. Now what? 
> rev-list will only ever list the object once.

Sure. It is still a valid path though.


Nicolas

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 15:53 ` Johannes Sixt
  2010-03-26 16:13   ` Jakub Narebski
  2010-03-26 17:25   ` Nicolas Pitre
@ 2010-03-26 21:11   ` Paul Richards
  2 siblings, 0 replies; 8+ messages in thread
From: Paul Richards @ 2010-03-26 21:11 UTC (permalink / raw)
  To: git

On 26 March 2010 15:53, Johannes Sixt <j.sixt@viscovery.net> wrote:
> Am 3/26/2010 16:31, schrieb Paul Richards:
>> Is there a way to enumerate all the objects in the Git
>> object store, and for each one figure out its type (commit, tree, or
>> blob) and obtain a list of the objects it references?  If not, is
>> there a way to do this for a single object at a time?  (I can then
>> simply recurse through the whole structure.)
>
> Use 'git rev-list --objects --all' to find all objects connected to all
> refs (use something else than --all if you want to). Do *not* look at the
> path that the tree and blob objects have attached - it is not authorative
> information.
>
> Use 'git cat-file -t' to find the type.
>
> Use 'git cat-file -p' to pretty-print the content of an object. Parse it
> depending on the type that you find.
>

Thank you, this looks perfect!

I'll check this out (and perhaps the optimizations suggested by Jakub
if necessary).


-- 
Paul Richards

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

* Re: Enumerating all objects in the Git object store
  2010-03-26 15:31 Enumerating all objects in the Git object store Paul Richards
  2010-03-26 15:53 ` Johannes Sixt
@ 2010-03-27 13:33 ` Michael J Gruber
  1 sibling, 0 replies; 8+ messages in thread
From: Michael J Gruber @ 2010-03-27 13:33 UTC (permalink / raw)
  To: Paul Richards; +Cc: git

Paul Richards venit, vidit, dixit 26.03.2010 16:31:
> Hi,
> I'd like to visualize the objects in a Git repository using Graphviz
> and "dot".  I'd like to see commits as circles, trees as triangles,
> blobs as rectangles, and have arrows linking these objects showing how
> they reference each other in the Git DAG.  For small repositories this
> may be a useful way to visualize how Git objects work.
> 
> I could not find a pre-existing script to do this so I am considering
> writing one.  Is there a way to enumerate all the objects in the Git
> object store, and for each one figure out its type (commit, tree, or
> blob) and obtain a list of the objects it references?  If not, is
> there a way to do this for a single object at a time?  (I can then
> simply recurse through the whole structure.)
> 

If you don't care about loose (unreferenced) objects then it's enough to
walk through all refs (branches, tags) and, for each ref, look at parent
and tree references (using git cat-file) and recurse.

If you don't care about the sha1 of commits you might even want to
(ab)use git-fast-export for that!

Michael

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

end of thread, other threads:[~2010-03-27 13:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26 15:31 Enumerating all objects in the Git object store Paul Richards
2010-03-26 15:53 ` Johannes Sixt
2010-03-26 16:13   ` Jakub Narebski
2010-03-26 17:25   ` Nicolas Pitre
2010-03-26 20:11     ` Johannes Sixt
2010-03-26 20:24       ` Nicolas Pitre
2010-03-26 21:11   ` Paul Richards
2010-03-27 13:33 ` Michael J Gruber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).