Pathspec support for magic words
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy mẫu được cung cấp với git2-rs và so sánh DiffOptions::pathspec với repo.diff_tree_to_tree đối với magic-word pathspecs. Theo dõi cách Rust API truyền pathspecs cho libgit2, sau đó xác minh rằng ví dụ exclude được ghi trong tài liệu và ví dụ kết hợp include/exclude tạo ra các danh sách tệp như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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};
pub fn diff(
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();
let mut rename_opts = DiffFindOptions::new();
rename_opts.renames(true);
rename_opts.rename_limit(200);
rename_opts.renames_from_rewrites(true);
let mut opts = DiffOptions::new();
opts.update_index(false);
opts.context_lines(0);
for p in pathspecs {
opts.pathspec(p);
}
let mut 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(())
}
fn main() -> Result<(), Box<dyn Error>> {
let mut args = args();
if args.len() <= 3 {
println!("Usage: <repo> <sha> <sha> [pathspec...]");
return Err("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):
- Run Git on an example repository
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
libgit2-sys/lib.rs
src/repo.rs
Note that also Cargo.toml and git2-curl/Cargo.toml have changed, but they are not part of the diff.
- Run sample app
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:
cargo run -- /tmp/git2-rs/ d1ae3b6c 7b7be439 "*.toml" ":(exclude)*.toml"
# Outputs
Cargo.toml
git2-curl/Cargo.toml
Git correctly prints out nothing.
Thank you! Looking forward to your answers :)
- Ngôn ngữ chính
- Rust
- Star
- 2.1k
- Fork
- 470
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/git2-rs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messageCó thể đã có người làm @shivampwm2020 đã nhận 43 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/git2-rs
Issue tương tự
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
max-sixty/worktrunk#4939 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursĐang mởflaky
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
stacks-network/stacks-core#7918 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày