Skip to content

Add --include-unreachable flag and related processing #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

ScottArbeit
Copy link

@ScottArbeit ScottArbeit commented Apr 16, 2025

This PR adds a new flag to git-sizer, --include-unreachable, to include unreachable objects in the counts displayed in the output.

Changes

It adds the following:

  • A new command-line flag --include-unreachable so that the new functionality only runs when requested
  • Processing of each unreachable object using git cat-file --batch-check
  • Output of the count and uncompressed total size of unreachable objects in a new section in the output

Considerations

Getting the uncompressed size of the unreachable objects means listing them and then running git cat-file --batch-check with each unreachable oid input to stdin. This is, obviously, an O(n) operation, and that's why I've stuck it behind a new flag rather than including it in processing by default.

For repos with a lot of unreachable objects, this will take some time to run.

Sample output

Here's an example of the output including the new section (at the bottom):

(5:53:24 PM) D:\Source\Grace>D:\Source\github\git-sizer\bin\git-sizer.exe -v --include-unreachable
Processing blobs: 2593
Processing trees: 1427
Processing commits: 207
Matching commits to trees: 207
Processing annotated tags: 1
Processing references: 7

| Name                         | Value     | Level of concern               |
| ---------------------------- | --------- | ------------------------------ |
| Repository statistics        |           |                                |
| * Commits                    |           |                                |
|   * Count                    |   207     |                                |
|   * Total size               |  72.4 KiB |                                |
| * Trees                      |           |                                |
|   * Count                    |  1.43 k   |                                |
|   * Total size               |   777 KiB |                                |
|   * Total tree entries       |  18.1 k   |                                |
| * Blobs                      |           |                                |
|   * Count                    |  2.59 k   |                                |
|   * Uncompressed total size  |  57.4 MiB |                                |
| * On-disk size               |           |                                |
|   * Compressed total size    |  2.74 MiB |                                |
| * Annotated tags             |           |                                |
|   * Count                    |     1     |                                |
| * References                 |           |                                |
|   * Count                    |     7     |                                |
|     * Branches               |     3     |                                |
|     * Tags                   |     1     |                                |
|     * Remote-tracking refs   |     3     |                                |
|                              |           |                                |
| Biggest objects              |           |                                |
| * Commits                    |           |                                |
|   * Maximum size         [1] |  1.51 KiB |                                |
|   * Maximum parents      [2] |     2     |                                |
| * Trees                      |           |                                |
|   * Maximum entries      [3] |    41     |                                |
| * Blobs                      |           |                                |
|   * Maximum size         [4] |   946 KiB |                                |
|                              |           |                                |
| History structure            |           |                                |
| * Maximum history depth      |   197     |                                |
| * Maximum tag depth      [5] |     1     |                                |
|                              |           |                                |
| Biggest checkouts            |           |                                |
| * Number of directories  [6] |    55     |                                |
| * Maximum path depth     [6] |     7     |                                |
| * Maximum path length    [6] |    72 B   |                                |
| * Number of files        [6] |   258     |                                |
| * Total size of files    [6] |  4.28 MiB |                                |
| * Number of symlinks         |     0     |                                |
| * Number of submodules       |     0     |                                |
|                              |           |                                |
| Unreachable objects          |           |                                |  <--- new output section
| * Blobs                      |           |                                |
|   * Count                    |    21     |                                |
|   * Uncompressed total size  |   428 KiB |                                |
| * Trees                      |           |                                |
|   * Count                    |    30     |                                |
|   * Total size               |  22.1 KiB |                                |
| * Commits                    |           |                                |
|   * Count                    |    18     |                                |
|   * Total size               |  5.30 KiB |                                |
| * Tags                       |           |                                |
|   * Count                    |     0     |                                |
|   * Total size               |     0 B   |                                |

_detailed refs redacted_

@Copilot Copilot AI review requested due to automatic review settings April 16, 2025 01:15
@ScottArbeit ScottArbeit requested a review from a team as a code owner April 16, 2025 01:15
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new flag, --include-unreachable, to optionally include unreachable objects when reporting repository statistics. Key changes include adding new fields for unreachable objects and .git directory size in the statistics structure, updating output formatting to display these new values, and implementing the processing logic (via git fsck and git cat‐file batch mode) to compute unreachable object stats.

Reviewed Changes

Copilot reviewed 6 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sizes/sizes.go Added new fields to HistorySize for unreachable object stats and the .git directory size.
sizes/output.go Updated repository statistics output with a new section for unreachable objects and on-disk size.
sizes/dirsize.go Introduced a helper function to calculate the size of the .git directory.
git/git.go Added GetUnreachableStats and helper function to compute unreachable objects’ total size.
git-sizer.go Added --include-unreachable flag and integrated unreachable stats processing.
CONTRIBUTING.md Updated dependency installation instructions for Unix and Windows environments.
Files not reviewed (4)
  • Makefile.win: Language not supported
  • script/bootstrap.ps1: Language not supported
  • script/ensure-go-installed.ps1: Language not supported
  • script/go.ps1: Language not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant