Reputation: 267
I would like to measure / count objects in git to see whether I am close to auto-packing, I think it can be done trivially by counting files in .git/objects/..., but I am not sure.
Here is the story:
For a couple of days now, my git repo is auto-packing itself whenever I push to it. (The git repo lives on a USB memory stick, therefore the auto-packing is awfully slow and I have cancel it after 30 minutes or so)
it is the same problem as:
What does "Auto packing the repository for optimum performance" mean?
I'm having a problem with my git repo. For the last couple of days whenever I do a push to the server I get this message: "Auto packing the repository for optimum performance"
In that same thread I found the solution:
To disable for one project:
cd your_project_dir
git config gc.auto 0
To disable globally:
git config --global gc.auto 0
That solved my problem for that particular repo...
...but I have got many more git repo's on my memory stick and I would like to know a way to measure if any of my other git repos is close to auto-packing
I found:
Why does git run auto-packing on every push to our repo?
Git decides whether to auto gc based on two criteria:
Are there too many packs? (Literally, are there more than 50 files with .idx in .git/objects/pack?)
Are there too many loose objects? (Literally, are there more than 27 files in .git/objects/17?)
My question is almost answered, but I would simply like to have confirmation that I understand correctly: How can I measure / count loose objects to see if I am close to auto-packing ? -- is it (as suggested in the above answer) literally counting files in .git/objects/17 and compare to the hard limit of 27,
-- or maybe it is counting all files in .git/objects/01, .../02, .../03, etc... and comparing the average to a soft limit defined in git config global ?
-- even if it is trivial, is there a git command that counts objects in .git/objects/17 ? -- is there a git command that returns the hard limit of 27 ?
Upvotes: 4
Views: 3603
Reputation: 1325966
I would like to measure / count objects in git to see whether I am close to auto-packing
Note that, as an indicator, Git 2.22 (Q2 2019) will help, since the "git pack-objects" command learned to report the number of objects it packed via the trace2
mechanism.
See commit 9ed8790 (11 Apr 2019) by Jonathan Tan (jhowtan
).
(Merged by Junio C Hamano -- gitster
-- in commit 3d67555, 08 May 2019)
pack-objects
: write objects packed totrace2
This is useful when investigating performance of pushes, and other times when no progress information is written (because the pack is written to stdout).
See Documentation/technical/api-trace2.txt
for more on trace2
, introduced in commit ee4512e in Feb.2019 for Git 2.22.
Upvotes: 0
Reputation: 39083
The answer at Why does git run auto-packing on every push to our repo? is still valid. As you can see in the source code of the latest release of git (2.10.2), this is the function need_to_gc
that decides whether gc is run.
gc.auto
is set to 0 or negative?too_many_packs
: is the option gc.autopacklimit
(default 50) positive and less than the number of packs (*.idx
files in .git/objects/pack
)?too_many_loose_objects
: is the option gc.auto
(default 6700) positive, and is the number of loose objects in .git/objects/17
(it looks only in this directory; doesn't count all and take average or max or anything like that) greater than ({gc.auto} + 255)/256)
?So that's where the number 27 comes from: it's the floor of (6700 + 255)/256. You can increase it by increasing gc.auto
. You can get the equivalent of this number 27 with the git command git config --get gc.auto
but that only works if the option has been explicitly set.
Upvotes: 2