-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It only prints things without fuzz. Inspired by https://youtu.be/JYH5ILv5g1g?si=bHLBPFJiZyRUTl6u&t=211.
- Loading branch information
Showing
5 changed files
with
80 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::repository::revision::resolve::{BlobFormat, TreeMode}; | ||
use anyhow::{anyhow, Context}; | ||
use gix::diff::blob::ResourceKind; | ||
use gix::filter::plumbing::driver::apply::Delay; | ||
use gix::revision::Spec; | ||
|
||
pub fn display_object( | ||
repo: &gix::Repository, | ||
spec: Spec<'_>, | ||
tree_mode: TreeMode, | ||
cache: Option<(BlobFormat, &mut gix::diff::blob::Platform)>, | ||
mut out: impl std::io::Write, | ||
) -> anyhow::Result<()> { | ||
let id = spec.single().context("rev-spec must resolve to a single object")?; | ||
let header = id.header()?; | ||
match header.kind() { | ||
gix::object::Kind::Tree if matches!(tree_mode, TreeMode::Pretty) => { | ||
for entry in id.object()?.into_tree().iter() { | ||
writeln!(out, "{}", entry?)?; | ||
} | ||
} | ||
gix::object::Kind::Blob if cache.is_some() && spec.path_and_mode().is_some() => { | ||
let (path, mode) = spec.path_and_mode().expect("is present"); | ||
match cache.expect("is some") { | ||
(BlobFormat::Git, _) => unreachable!("no need for a cache when querying object db"), | ||
(BlobFormat::Worktree, cache) => { | ||
let platform = cache.attr_stack.at_entry(path, Some(mode.into()), &repo.objects)?; | ||
let object = id.object()?; | ||
let mut converted = cache.filter.worktree_filter.convert_to_worktree( | ||
&object.data, | ||
path, | ||
&mut |_path, attrs| { | ||
let _ = platform.matching_attributes(attrs); | ||
}, | ||
Delay::Forbid, | ||
)?; | ||
std::io::copy(&mut converted, &mut out)?; | ||
} | ||
(BlobFormat::Diff | BlobFormat::DiffOrGit, cache) => { | ||
cache.set_resource(id.detach(), mode.kind(), path, ResourceKind::OldOrSource, &repo.objects)?; | ||
let resource = cache.resource(ResourceKind::OldOrSource).expect("just set"); | ||
let data = resource | ||
.data | ||
.as_slice() | ||
.ok_or_else(|| anyhow!("Binary data at {} cannot be diffed", path))?; | ||
out.write_all(data)?; | ||
} | ||
} | ||
} | ||
_ => out.write_all(&id.object()?.data)?, | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub(super) mod function { | ||
use crate::repository::revision::resolve::TreeMode; | ||
|
||
pub fn cat(repo: gix::Repository, revspec: &str, out: impl std::io::Write) -> anyhow::Result<()> { | ||
super::display_object(&repo, repo.rev_parse(revspec)?, TreeMode::Pretty, None, out)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters