2

Having a sparsely checked out working tree, I wish to parse the full git objects, In order to be able to update sparse .git/info/sparse-checkout, based on some business logic (which should not be relevant here).

I tried to find a command to checkout "unsparsed" into a temporary folder. I wonder, if I can probably even read contents out of git objects without a checkout.

Trying to build a module graphe around

def _find_addons(dir):
    """ yield (addon_name, addon_dir, manifest) """
    for root, _, files in os.walk(dir):
        if ".git" in root:
            continue
        if any(s in root for s in SKIP_PATHS):
            continue
        if any(M in files for M in MANIFEST_NAMES):
            yield os.path.dirname(root), os.path.basename(root), _read_manifest(root)

Full code:

https://github.com/xoe-labs/odooup/blob/master/odooup/_modulegraph.py

David Arnold
  • 23
  • 1
  • 4
  • Relevant command in git CLI to get an object from a blob (not sure how/if it would be useful for your needs in a python context, but still) is [cat-file](https://git-scm.com/docs/git-cat-file), especially with `-p` flag. Just to mention it. – Romain Valeri Jul 03 '19 at 12:17

1 Answers1

2

Use git cat-file -p <object name> to print the content of a git object from its id.

Khoyo
  • 1,253
  • 11
  • 20
  • 2
    Thanks great! did the job, together with `git ls-tree`: https://github.com/xoe-labs/odooup/blob/5cf008a08a68c3ae75a8434c7d1f602ef20b7750/odooup/_modulegraph.py#L16-L53 – David Arnold Jul 03 '19 at 16:15
  • @Khoyo and how to get the from a file in the working tree? – dani 'SO learn value newbies' Dec 27 '22 at 01:18
  • 2
    @dani'SOlearnvaluenewbies' `git hash-object ` will give you the id that the current version of the file would have. But since git is content addressed, `git cat-file -p $(git hash-object )` is equivalent to `cat `, except it only works if git actually has the current version of the file in its datastore. – Khoyo Jan 08 '23 at 17:37