How does GitLab calculate total file size?

In GitLab, each project’s landing page shows some statistics on the project’s files, commits, branches, and tags. For files, a size is displayed, as follows:

How is this total file size calculated? When I clone the repository that I used to create the above screenshot, both du -s -h and git count-objects -vH report total file sizes that are far, far lower. The latter command shows 174.74K, and the former shows shows 356K for the .git folder alone, or 940K for the largest of four branches. It occurred to me that someone may have checked in (and then maybe later deleted) some very large sparse files, but du --apparent-size reports similarly small total sizes for the directory, even when run after checking out each of the six individual commits. Using this script to find big deleted files in the commit history also turns up nothing.

So how is it that GitLab thinks there are 4GB worth of files in the repository? Is there any way I can get it to show me big files or big commits?

The GitLab Git Wrapper is responsible for calculating the size shown here.

The Gitlab::Git::Repository#size method calculates the repo size using the command du -sk.

You can also query the database to determine the size that is stored, associated to the GitLab project.

Start a Rails console:

sudo gitlab-rails console

Find the project and check the repo size stored:

p = Project.find_by_name('project_name')
p.repository_size

This value is also cached in Redis, it’s possible that clearing the cache or forcing this value to be updated could cause this to change.

1 Like

I have just finished a big migration, 6.9 to 8.12, manually (there is no direct upgrade path).
I noticed the gui does not have the “Files (0)” populated yet. The command to update the number of commits is gitlab-rake gitlab:update_commit_count .
Is there a similar command for updating sizes Files ? I see it’s updated every commit/push, but we would like to update all migrated projects.
Or maybe there are some other gitlab commands which one needs to do when the repo is manually copied (not imported from backup) ?