You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, I'm using git2-rs's diff API interface and I'm trying to filter out some paths using pathspec.
From Git's user manual, pathspecs should support "magic words", which would allow me to write something like this :(exclude)*.toml to exclude all toml files when computing the diff. This is important to me because it allows to save a lot of computation time wasted on files I do not care about (and have to filter out manually after the diff).
When using Git, this works as expected, however, I can't replicate the same behaviour using git2-rs from my Rust application.
Any idea on how to workaround on this issue? Am I using the APIs wrongly? Or even pointers on how to implement this in the library (I'm a newbie to Rust, but I might give it a try...).
Here's an example Rust application that showcases the problem.
use std::{env::args, error::Error};use git2::{DiffFindOptions,DiffOptions,ObjectType,Repository};pubfndiff(repo:&Repository,parent:&str,child:&str,pathspecs:&[String],) -> Result<(), git2::Error>{let parent = repo.revparse_single(parent)?;let child = repo.revparse_single(child)?;let p_obj = parent.peel(ObjectType::Tree)?;let c_obj = child.peel(ObjectType::Tree)?;let p_tree = p_obj.as_tree().unwrap();let c_tree = c_obj.as_tree().unwrap();letmut rename_opts = DiffFindOptions::new();
rename_opts.renames(true);
rename_opts.rename_limit(200);
rename_opts.renames_from_rewrites(true);letmut opts = DiffOptions::new();
opts.update_index(false);
opts.context_lines(0);for p in pathspecs {
opts.pathspec(p);}letmut diff = repo.diff_tree_to_tree(Some(p_tree),Some(c_tree),Some(&mut opts))?;
diff.find_similar(Some(&mut rename_opts))?;for delta in diff.deltas(){println!("{}", delta.old_file().path().unwrap().to_str().unwrap());}Ok(())}fnmain() -> Result<(),Box<dynError>>{letmut args = args();if args.len() <= 3{println!("Usage: <repo> <sha> <sha> [pathspec...]");returnErr("Wrong number of arguments".into());}
args.next();let repo = args.next().expect("Repository must be provided");let sha_parent = args.next().expect("Parent sha must be provided");let sha_child = args.next().expect("Child sha must be provided");let pathspecs = args.collect::<Vec<String>>();let repo = Repository::open(repo)?;diff(&repo,&sha_parent,&sha_child, pathspecs.as_slice())?;Ok(())}
To illustrate the problem, you can follow these steps (after setting up the sample cargo app above):
This crate provides bindings for the libgit2 C library. IIRC it only offers fnmatch-based pathspec syntax. You might want to open an issue in that repo instead.
Hi all, I'm using
git2-rs
's diff API interface and I'm trying to filter out some paths using pathspec.From Git's user manual, pathspecs should support "magic words", which would allow me to write something like this
:(exclude)*.toml
to exclude alltoml
files when computing the diff. This is important to me because it allows to save a lot of computation time wasted on files I do not care about (and have to filter out manually after the diff).When using Git, this works as expected, however, I can't replicate the same behaviour using
git2-rs
from my Rust application.Any idea on how to workaround on this issue? Am I using the APIs wrongly? Or even pointers on how to implement this in the library (I'm a newbie to Rust, but I might give it a try...).
Here's an example Rust application that showcases the problem.
To illustrate the problem, you can follow these steps (after setting up the sample cargo app above):
git clone https://github.com/rust-lang/git2-rs /tmp/git2-rs git -C /tmp/git2-rs/ diff --name-only d1ae3b6c 7b7be439 ":(exclude)*.toml"
Which outputs
Note that also
Cargo.toml
andgit2-curl/Cargo.toml
have changed, but they are not part of the diff.cargo run -- /tmp/git2-rs/ d1ae3b6c 7b7be439 ":(exclude)*.toml"
No output is display at all if you provide a pathspec with any magic word. In this case, the expected output is the two
.rs
files seen above.Morover, combinations like these seem to fail too:
Git correctly prints out nothing.
Thank you! Looking forward to your answers :)
The text was updated successfully, but these errors were encountered: