git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Enumerating all objects in the Git object store

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Mar 27, 2010, 13:33 UTC
Message-ID
<4BAE0945.8040406@drmicha.warpmail.net>
In-Reply-To
<a1138db31003260831q34967f69u9fc8de861f7931b1@mail.gmail.com>
Paul Richards venit, vidit, dixit 26.03.2010 16:31:
Show 14 quoted lines
> 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
Previous: Paul Richards
Message 8 of 8 in “Enumerating all objects in the Git object store”
  1. Paul RichardsMar 26, 2010
  2. Johannes SixtMar 26, 2010
  3. Jakub NarebskiMar 26, 2010
  4. Nicolas PitreMar 26, 2010
  5. Johannes SixtMar 26, 2010
  6. Nicolas PitreMar 26, 2010
  7. Paul RichardsMar 26, 2010
  8. Michael J GruberMar 27, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.