# Enumerating all objects in the Git object store

8 messages from 2010-03-26 to 2010-03-27. Participants: Paul Richards, Johannes Sixt, Jakub Narebski, Nicolas Pitre, Michael J Gruber.
Thread: https://gitlist.dev/t/23190

## Paul Richards, 2010-03-26 15:31

Subject: Enumerating all objects in the Git object store
Message-ID: <a1138db31003260831q34967f69u9fc8de861f7931b1@mail.gmail.com>
URL: https://gitlist.dev/e/a1138db31003260831q34967f69u9fc8de861f7931b1%40mail.gmail.com

```
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

```

## Johannes Sixt, 2010-03-26 15:53

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <4BACD86E.4020803@viscovery.net>
URL: https://gitlist.dev/e/4BACD86E.4020803%40viscovery.net
In-Reply-To: <a1138db31003260831q34967f69u9fc8de861f7931b1@mail.gmail.com>

```
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

```

## Jakub Narebski, 2010-03-26 16:13

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <m3zl1vhxjg.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3zl1vhxjg.fsf%40localhost.localdomain
In-Reply-To: <4BACD86E.4020803@viscovery.net>

```
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

```

## Nicolas Pitre, 2010-03-26 17:25

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <alpine.LFD.2.00.1003261324350.694@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.2.00.1003261324350.694%40xanadu.home
In-Reply-To: <4BACD86E.4020803@viscovery.net>

```
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

```

## Johannes Sixt, 2010-03-26 20:11

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <201003262111.48298.j.sixt@viscovery.net>
URL: https://gitlist.dev/e/201003262111.48298.j.sixt%40viscovery.net
In-Reply-To: <alpine.LFD.2.00.1003261324350.694@xanadu.home>

```
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

```

## Nicolas Pitre, 2010-03-26 20:24

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <alpine.LFD.2.00.1003261621560.694@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.2.00.1003261621560.694%40xanadu.home
In-Reply-To: <201003262111.48298.j.sixt@viscovery.net>

```
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

```

## Paul Richards, 2010-03-26 21:11

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <a1138db31003261411o136145eeu14afe75ee3d170f5@mail.gmail.com>
URL: https://gitlist.dev/e/a1138db31003261411o136145eeu14afe75ee3d170f5%40mail.gmail.com
In-Reply-To: <4BACD86E.4020803@viscovery.net>

```
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

```

## Michael J Gruber, 2010-03-27 13:33

Subject: Re: Enumerating all objects in the Git object store
Message-ID: <4BAE0945.8040406@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4BAE0945.8040406%40drmicha.warpmail.net
In-Reply-To: <a1138db31003260831q34967f69u9fc8de861f7931b1@mail.gmail.com>

```
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

```
