let mut entries = vec![];
for pr in reverse_log {
let (_, (h, _mrk)) = pr.unwrap();
let cid = pijul::GraphTxnT::get_internal(&txn, h).unwrap().unwrap();
let mut is_in_filters = inodes.is_empty();
for (_, position) in inodes.iter() {
if let Some(position) = position {
is_in_filters = pijul::DepsTxnT::get_touched_files(
&txn,
position,
Some(cid),
)
.unwrap()
== Some(cid);
if is_in_filters {
break;
}
}
}
if is_in_filters {
if offset == 0 && limit > 0 {
// If there were no path filters applied, OR is this was one of the hashes
// marked by the file filters that were applied
let entry = mk_log_entry(repo, pijul::Hash::from(h));
entries.push(entry);
limit -= 1
} else if limit > 0 {
offset -= 1
} else {
break;
}
}
}
entries
}
fn mk_log_entry(repo: &pijul::Repository, h: pijul::Hash) -> LogEntry {
let header = repo.changes.get_header(&h.into()).unwrap();
LogEntry {
hash: h,
message: header.message.clone(),
}
}
// A lot of error-handling noise here, but since we're dealing with
// a user-command and a bunch of file-IO/path manipulation it's
// probably necessary for the feedback to be good.
//
// Borrowed and adjusted from Pijul `pijul/src/commands/log.rs`
// - removed Error handling for now
fn get_inodes(
txn: &pijul::pristine::sanakirja::Txn,
repo_path: &Path,
pats: &[String],
) -> Vec<(
pijul::Inode,
Option<pijul::pristine::Position<pijul::ChangeId>>,
)> {
let mut inodes = Vec::new();
for pat in pats {
let canon_path = match Path::new(pat).canonicalize() {
Err(e) if matches!(e.kind(), std::io::ErrorKind::NotFound) => {
// return Err(Error::NotFound(pat.to_string()))
todo!()
}
Err(e) =>
// return Err(e.into()),
{
todo!()
}
Ok(p) => p,
};
match canon_path.strip_prefix(repo_path).map(|p| p.to_str()) {
// strip_prefix error is if repo_path is not a prefix of canon_path,
// which would only happen if they pased in a filter path that's not
// in the repository.
Err(_) => {
// return Err(Error::FilterPath {
// pat: pat.to_string(),
// canon_path,
// repo_path: repo_path.to_path_buf(),
// })
todo!()
}
// PathBuf.to_str() returns none iff the path contains invalid UTF-8.
Ok(None) =>
// return Err(Error::InvalidUtf8(pat.to_string())),
{
todo!()
}
Ok(Some(s)) => {
let inode = pijul::fs::find_inode(txn, s).expect("TODO");
let inode_position =
pijul::TreeTxnT::get_inodes(txn, &inode, None)
.expect("TODO");
inodes.push((inode, inode_position.cloned()))
}
};
}
inodes
}