scandinavian_
scandinavian_

Reputation: 2576

How does git know the sha1 name of the pack files?

Hypothetical situation: I have a git repository, I have the index, HEAD, refs, packed-refs etc. I don't know the names of the pack files in .git/objects/pack

How does git figure out the name of the pack files? Is there a way to calculate the name of the pack files from the index file?

Update: .git/objects/info/packs is the closest I'm gonna get to what I'm looking for. This file is not always present though.

Upvotes: 2

Views: 727

Answers (1)

torek
torek

Reputation: 487725

As a general rule, git just reads the contents of the objects/pack directory: it does not know a priori what the pack file SHA-1 values will be. However, when it goes to make a new pack file, it does calculate an SHA-1 and use that for the name of the pack file; and the name of the index is necessarily the same as the name of the pack-file, so if

objects/pack/pack-1713881825f0238230418a7f843a8c9af9b70eea.pack

exists, then

objects/pack/pack-1713881825f0238230418a7f843a8c9af9b70eea.idx

should also exist, for instance (these names found by looking in a directory, there's no particular significance to these SHA-1s).

There may also be .keep and .bitmap files corresponding to any given SHA-1 (bitmaps appear to be new in git 2.0.0).

For more amusing enlightenment on pack files, see

Documentation/technical/pack-heuristics.txt

in the git source. :-)

Upvotes: 5

Related Questions