Skip to content

Instantly share code, notes, and snippets.

@yuja
Created December 14, 2023 03:43
Show Gist options
  • Save yuja/b922bc0881c0912dad9c1a6a78f0703f to your computer and use it in GitHub Desktop.
Save yuja/b922bc0881c0912dad9c1a6a78f0703f to your computer and use it in GitHub Desktop.
//! https://github.com/martinvonz/jj/issues/2697
use std::path::Path;
use std::process::Command;
use gix::refs::transaction::{Change, PreviousValue, RefEdit};
use gix::ObjectId;
fn main() {
let repo_path = Path::new("test-repo");
{
let repo = gix::init(repo_path).unwrap();
let empty_tree_id =
ObjectId::from_hex(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap();
let commit_id1 = repo
.commit(
"refs/heads/main",
"empty commit",
empty_tree_id,
[] as [ObjectId; 0],
)
.unwrap()
.detach();
// Create many refs to mmap() packed-refs
let edits = (0..1000).map(|n| {
let name = format!("refs/heads/feat-{n:04}");
RefEdit {
change: Change::Update {
log: Default::default(),
expected: PreviousValue::MustNotExist,
new: commit_id1.into(),
},
name: name.try_into().unwrap(),
deref: false,
}
});
repo.edit_references(edits).unwrap();
}
Command::new("git")
.current_dir(repo_path)
.args(["pack-refs", "--all"])
.status()
.unwrap();
dbg!(repo_path.join(".git").join("packed-refs").metadata().unwrap().len());
// Reopen the repo to ensure that the packed-refs file is read.
{
let repo = gix::open(repo_path).unwrap();
let git_ref = repo.find_reference("refs/heads/feat-0000").unwrap();
dbg!(&repo.refs);
git_ref.delete().unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment