Skip to content

Commit

Permalink
feat: support workspace filters when fetching them from the object da…
Browse files Browse the repository at this point in the history
…tabase
  • Loading branch information
Byron committed Nov 13, 2023
1 parent 324266a commit fadacb7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gix-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ autotests = false
[features]
default = ["blob"]
## Enable diffing of blobs using imara-diff, which also allows for a generic rewrite tracking implementation.
blob = ["dep:imara-diff"]
blob = ["dep:imara-diff", "dep:gix-filter"]
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde = ["dep:serde", "gix-hash/serde", "gix-object/serde"]
## Make it possible to compile to the `wasm32-unknown-unknown` target.
Expand All @@ -25,6 +25,7 @@ doctest = false
[dependencies]
gix-hash = { version = "^0.13.1", path = "../gix-hash" }
gix-object = { version = "^0.38.0", path = "../gix-object" }
gix-filter = { version = "^0.6.0", path = "../gix-filter", optional = true }

thiserror = "1.0.32"
imara-diff = { version = "0.1.3", optional = true }
Expand Down
24 changes: 22 additions & 2 deletions gix-diff/src/rewrites/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ pub enum ChangeKind {
Addition,
}

/// A trait to help access the worktree version of a file, if present.
pub trait WorktreeBlob {
/// Write the contents of the file, executable or link (i.e. the link target itself) at
/// `rela_path` to the initially empty `buf`.
/// `is_source` is `true` if this is the blob for the source of a rewrite (copy or rename). Otherwise it is the
/// destination.
///
/// Return `std::io::ErrorKind::NotFound` if the file is not available in the working tree, which will make the
/// implementation to extract it from the object database instead and convert it to its working-tree counterpart.
fn worktree_blob(&mut self, rela_path: &BStr, buf: &mut Vec<u8>, is_source: bool) -> std::io::Result<()>;
}

/// A trait providing all functionality to abstract over the concept of a change, as seen by the [`Tracker`].
pub trait Change: Clone {
/// Return the hash of this change for identification.
///
/// Note that this is the id of the object as stored in `git`, i.e. it must have gone through workspace
/// conversions.
fn id(&self) -> &gix_hash::oid;
/// Return the kind of this change.
fn kind(&self) -> ChangeKind;
Expand Down Expand Up @@ -162,10 +177,14 @@ impl<T: Change> Tracker<T> {
///
/// `cb(destination, source)` is called for each item, either with `Some(source)` if it's
/// the destination of a copy or rename, or with `None` for source if no relation to other
/// items in the tracked set exist.
/// items in the tracked set exist, which is like saying 'no rename or rewrite or copy' happened.
///
/// `objects` is used to access blob data for similarity checks if required and is taken directly from the object database.
/// Worktree filters and diff conversions will be applied afterwards automatically.
/// Worktree filters and text conversions will be applied afterwards automatically.
///
/// Use `worktree_filter` to obtain working-tree versions of files present on disk before diffing to see if rewrites happened,
/// with text-conversions being applied afterwards.
/// If it indicates no such file exists, it's read from objects instead.
///
/// `push_source_tree(push_fn: push(change, location))` is a function that is called when the entire tree of the source
/// should be added as modifications by calling `push` repeatedly to use for perfect copy tracking. Note that `push`
Expand All @@ -174,6 +193,7 @@ impl<T: Change> Tracker<T> {
&mut self,
mut cb: impl FnMut(visit::Destination<'_, T>, Option<visit::Source<'_>>) -> crate::tree::visit::Action,
objects: &dyn gix_object::Find,
worktree_filter: &mut gix_filter::Pipeline,
mut push_source_tree: PushSourceTreeFn,
) -> Result<Outcome, emit::Error>
where
Expand Down

0 comments on commit fadacb7

Please sign in to comment.