Show GN: blame-rs - Rust로 작성된 라인별 저자 추적 라이브러리
(github.com/levish0)텍스트 파일의 각 라인이 어떤 리비전에서 작성되었는지 추적할 수 있는 Rust 라이브러리를 만들었습니다.
주요 기능:
- 제네릭 메타데이터 API: 커밋 해시, 작성자, 타임스탬프 등 원하는 메타데이터 타입 첨부 가능
- 다양한 diff 알고리즘: Myers(기본) 및 Patience 알고리즘 지원
- 고성능 설계: zero-copy 라인 추적, Rc를 통한 메타데이터 공유
- 포워드 트래킹: 가장 오래된 리비전부터 최신 리비전까지 효율적으로 라인 출처 추적
- 포괄적인 테스트: fixture 기반 테스트로 실제 시나리오 검증
링크:
- crates.io: https://crates.io/crates/blame-rs
- 소스코드: https://github.com/levish0/blame-rs
- 문서: https://docs.rs/blame-rs
usage:
use blame_rs::DiffAlgorithm::{Myers, Patience};
use blame_rs::{BlameOptions, BlameRevision, blame_with_options};
use std::fs;
use std::rc::Rc;
#[derive(Debug)]
struct CommitInfo {
hash: String,
author: String,
message: String,
}
fn main() {
// Read revision files
let rev0 = fs::read_to_string("examples/rev0.txt").expect("Failed to read rev0.txt");
let rev1 = fs::read_to_string("examples/rev1.txt").expect("Failed to read rev1.txt");
let rev2 = fs::read_to_string("examples/rev2.txt").expect("Failed to read rev2.txt");
// Create revisions with metadata
let revisions = vec![
BlameRevision {
content: &rev0,
metadata: Rc::new(CommitInfo {
hash: "abc123".to_string(),
author: "Alice".to_string(),
message: "Initial commit".to_string(),
}),
},
BlameRevision {
content: &rev1,
metadata: Rc::new(CommitInfo {
hash: "def456".to_string(),
author: "Bob".to_string(),
message: "Add greeting message".to_string(),
}),
},
BlameRevision {
content: &rev2,
metadata: Rc::new(CommitInfo {
hash: "789abc".to_string(),
author: "Charlie".to_string(),
message: "Update greeting and add footer".to_string(),
}),
},
];
// Run blame
let result = blame_with_options(
&revisions,
BlameOptions {
algorithm: Patience,
},
)
.expect("Blame operation failed");
}
Blame Results:
================================================================================
Line Commit Author Content
================================================================================
1 abc123 Alice fn main() {
2 abc123 Alice println!("Hello, world!");
3 def456 Bob println!("Bob did this");
4 def456 Bob }
5 789abc Charlie fn main() {
6 789abc Charlie println!("Hello, world!");
7 789abc Charlie }
================================================================================
Revision Details:
================================================================================
Revision 0: abc123 - Alice - "Initial commit"
Revision 1: def456 - Bob - "Add greeting message"
Revision 2: 789abc - Charlie - "Update greeting and add footer"