Skip to content

feat: add Repository::refdb_compress() for packing loose refs#1221

Merged
ehuss merged 3 commits intorust-lang:masterfrom
bordumb:bordumb/packed-refs
Mar 9, 2026
Merged

feat: add Repository::refdb_compress() for packing loose refs#1221
ehuss merged 3 commits intorust-lang:masterfrom
bordumb:bordumb/packed-refs

Conversation

@bordumb
Copy link
Contributor

@bordumb bordumb commented Mar 8, 2026

Wraps libgit2's git_refdb_compress() as a safe Rust method on Repository.

Link: https://libgit2.org/docs/reference/main/refdb/git_refdb_compress.html

Motivation:

Repositories with many loose refs (e.g. thousands of tags or identity refs) suffer degraded fetch and clone performance.
This exposes libgit2's ref packing capability so callers can compact loose refs into packed-refs without shelling out to git.

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Mar 8, 2026
@bordumb bordumb force-pushed the bordumb/packed-refs branch from 90fdb8a to e8dd7d5 Compare March 8, 2026 23:59
assert!(repo.references_glob("refs/tags/test-*").unwrap().count() == 20);

// Compress should pack them without error.
repo.refdb_compress().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to check the file packed-refs does not exist before calling this, and then check that it is created afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that - good shout.

I've added a check for that.

@bordumb bordumb requested a review from ehuss March 9, 2026 21:20
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

As a longer-term alternative, another consideration would be to have a separate Rust type for a refdb and have compress be a method on it. However, since compress is currently the only thing you can do with it, it seems fine to have a convenience method for it on Repository.

View changes since this review

@ehuss ehuss added this pull request to the merge queue Mar 9, 2026
Merged via the queue into rust-lang:master with commit 0d7ef58 Mar 9, 2026
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Mar 9, 2026
@bordumb
Copy link
Contributor Author

bordumb commented Mar 11, 2026

@ehuss thanks for taking a look at this and providing a review

Was a very positive and easy experience

Happy to noodle on that idea you had

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.

3 participants