Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure / count objects in Git to see whether I am close to auto-packing

Tags:

git

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 ?

like image 681
user2288349 Avatar asked Oct 18 '25 10:10

user2288349


1 Answers

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.

  • Is the option gc.auto is set to 0 or negative?
  • Are there too_many_packs: is the option gc.autopacklimit (default 50) positive and less than the number of packs (*.idx files in .git/objects/pack)?
  • Are there 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.

like image 50
ShreevatsaR Avatar answered Oct 20 '25 00:10

ShreevatsaR