Skip to main content

open_repository/
open_repository.rs

1//! Read a blob through a trusted handle with explicit repository configuration.
2//! Run `cargo run --example open_repository -- /path/to/repo <blob-revision>`.
3use std::path::PathBuf;
4
5use clap::Parser;
6use girt::{Repo, Repository};
7
8#[derive(Parser)]
9#[command(about, long_about = None)]
10struct Args {
11    /// Repository to open without inherited configuration.
12    path: PathBuf,
13    /// Revision naming a blob (a full blob ID or HEAD:README.md).
14    revision: String,
15}
16
17fn main() -> girt::Result<()> {
18    let args = Args::parse();
19    let git = Repo::new(Repository::open(args.path)?);
20    let id = git.rev_parse(&args.revision)?;
21    let bytes = git.repository().objects()?.read_blob(id)?;
22    println!(
23        "Read {} bytes from {}",
24        bytes.len(),
25        git.repository().object_dir().display()
26    );
27    Ok(())
28}