Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions josh-core/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,12 +1543,14 @@ fn per_rev_filter(
)?;

let parent = transaction.repo().find_commit(parent)?;
let parent = parent.tree()?;

let pin_subtract = pin_subtract.tree();
let pin_overlay = tree::transpose(transaction, pin_subtract, &parent)?;
let pin_overlay = tree::populate(
transaction,
tree::pathstree("", pin_subtract.tree.id(), transaction)?.id(),
parent.tree_id(),
)?;

Some((pin_subtract.id(), pin_overlay.id()))
Some((pin_subtract.tree.id(), pin_overlay))
} else {
None
}
Expand Down
38 changes: 1 addition & 37 deletions josh-core/src/filter/tree.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use std::path::PathBuf;

use crate::cache::TransactionContext;
use crate::cache_stack::CacheStack;
Expand Down Expand Up @@ -890,7 +889,7 @@ pub fn repopulated_tree(
populate(transaction, ipaths.id(), partial_tree.id())
}

fn populate(
pub fn populate(
transaction: &cache::Transaction,
paths: git2::Oid,
content: git2::Oid,
Expand Down Expand Up @@ -1002,41 +1001,6 @@ pub fn get_blob(repo: &git2::Repository, tree: &git2::Tree, path: &Path) -> Stri
content.to_owned()
}

/// Compose a new tree by taking paths out of `paths`,
/// and actual blobs out of `blobs`.
pub fn transpose<'a>(
transaction: &'a cache::Transaction,
paths: &'a git2::Tree,
blobs: &'a git2::Tree,
) -> JoshResult<git2::Tree<'a>> {
use git2::build::TreeUpdateBuilder;
use git2::{TreeWalkMode, TreeWalkResult};

let mut builder = TreeUpdateBuilder::new();

paths.walk(TreeWalkMode::PostOrder, |path, entry| {
let path = PathBuf::from(path).join(entry.name().unwrap_or(""));

let entry = match blobs.get_path(&path) {
Ok(entry) => entry,
Err(e) if e.code() == git2::ErrorCode::NotFound => return TreeWalkResult::Ok,
Err(_) => return TreeWalkResult::Abort,
};

if entry.kind() != Some(git2::ObjectType::Blob) {
return TreeWalkResult::Ok;
}

builder.upsert(path, entry.id(), git2::FileMode::Blob);
TreeWalkResult::Ok
})?;

let repo = transaction.repo();
let tree = builder.create_updated(repo, &empty(repo))?;

Ok(repo.find_tree(tree)?)
}

pub fn empty_id() -> git2::Oid {
git2::Oid::from_str("4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap()
}
Expand Down