ได้สร้างไลบรารี Rust ที่สามารถติดตามได้ว่าแต่ละบรรทัดของไฟล์ข้อความถูกเขียนขึ้นในรีวิชันใด

ฟีเจอร์หลัก:

  • API เมตาดาตาแบบ generic: สามารถแนบประเภทเมตาดาตาที่ต้องการได้ เช่น commit hash, ผู้เขียน, timestamp
  • อัลกอริทึม diff หลากหลาย: รองรับอัลกอริทึม Myers (ค่าเริ่มต้น) และ Patience
  • ออกแบบมาเพื่อประสิทธิภาพสูง: การติดตามบรรทัดแบบ zero-copy, การแชร์เมตาดาตาผ่าน Rc
  • การติดตามแบบ forward: ติดตามที่มาของบรรทัดได้อย่างมีประสิทธิภาพตั้งแต่รีวิชันที่เก่าที่สุดไปจนถึงรีวิชันล่าสุด
  • การทดสอบที่ครอบคลุม: ตรวจสอบสถานการณ์จริงด้วยการทดสอบแบบ fixture

ลิงก์:

การใช้งาน:

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"  

ยังไม่มีความคิดเห็น

ยังไม่มีความคิดเห็น