1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
mod cli;
mod relevance;

pub mod prompt;
pub mod service;

pub use cli::handle_gen_command;
use git2::FileMode;
pub use service::IrisCommitService;

use crate::git::CommitResult;

pub fn format_commit_result(result: &CommitResult, message: &str) -> String {
    let mut output = format!(
        "[{} {}] {}\n",
        result.branch,
        result.commit_hash,
        message.lines().next().unwrap_or("")
    );
    
    output.push_str(&format!(
        " {} file{} changed, {} insertion{}(+), {} deletion{}(-)\n",
        result.files_changed,
        if result.files_changed != 1 { "s" } else { "" },
        result.insertions,
        if result.insertions != 1 { "s" } else { "" },
        result.deletions,
        if result.deletions != 1 { "s" } else { "" }
    ));
    
    for (file, mode) in &result.new_files {
        output.push_str(&format!(" create mode {} {}\n", format_file_mode(*mode), file));
    }
    
    output
}

fn format_file_mode(mode: FileMode) -> String {
    match mode {
        FileMode::Blob => "100644",
        FileMode::BlobExecutable => "100755",
        FileMode::Link => "120000",
        FileMode::Commit => "160000",
        FileMode::Tree => "040000",
        _ => "000000",
    }.to_string()
}