新增: Git 提交历史显示作者 + 提交详情含作者/时间
- 后端 git log format 加 %an 作者名(状态查询+分页查询) - 提交列表每行显示 hash/作者/主题/时间 - 提交详情头部补充作者显示 - 分支切换按钮占位(后续接入分支列表 IPC)
This commit is contained in:
@@ -266,6 +266,8 @@ struct GitRecentCommit {
|
||||
subject: String,
|
||||
/// Unix 时间戳(秒),供前端格式化显示。
|
||||
timestamp: i64,
|
||||
/// 作者名(git an)
|
||||
author: String,
|
||||
}
|
||||
|
||||
/// Git 状态返回结构(无 .git 时各字段空,前端据此显示"非 Git 仓库")。
|
||||
@@ -367,23 +369,25 @@ fn run_git_status(dir: &str) -> GitStatus {
|
||||
}
|
||||
}
|
||||
|
||||
// 3) 最近提交:`git log -50 --format="%h %ct %s"`(hash + unix 时间戳 + subject)
|
||||
// 3) 最近提交:`git log -50 --format="%h %ct %an %s"`(hash + 时间戳 + 作者 + subject)
|
||||
let mut recent_commits = Vec::new();
|
||||
if let Some(out) = run_git_cmd(path, &["log", "-50", "--format=%h %ct %s"], timeout) {
|
||||
if let Some(out) = run_git_cmd(path, &["log", "-50", "--format=%h %ct %an %s"], timeout) {
|
||||
for line in out.lines() {
|
||||
// format:"<hash> <unix_ts> <subject>"
|
||||
// format:"<hash> <unix_ts> <author> <subject>"(作者不含空格)
|
||||
let line = line.trim();
|
||||
if line.is_empty() { continue; }
|
||||
let mut parts = line.splitn(3, ' ');
|
||||
let mut parts = line.splitn(4, ' ');
|
||||
let hash = parts.next().unwrap_or("").to_string();
|
||||
let ts_str = parts.next().unwrap_or("0");
|
||||
let timestamp: i64 = ts_str.parse().unwrap_or(0);
|
||||
let author = parts.next().unwrap_or("").to_string();
|
||||
let subject = parts.next().unwrap_or("").to_string();
|
||||
if !hash.is_empty() {
|
||||
recent_commits.push(GitRecentCommit {
|
||||
hash,
|
||||
subject,
|
||||
timestamp,
|
||||
author,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -922,7 +926,7 @@ pub async fn get_module_commits(
|
||||
"log",
|
||||
&format!("--skip={}", skip),
|
||||
&format!("-{}", fetch_plus),
|
||||
"--format=%h %ct %s",
|
||||
"--format=%h %ct %an %s",
|
||||
])
|
||||
.current_dir(&dir_for_git)
|
||||
.env("LANG", "en_US.UTF-8")
|
||||
@@ -937,16 +941,18 @@ pub async fn get_module_commits(
|
||||
let line = line.trim();
|
||||
if line.is_empty() { continue; }
|
||||
if commits.len() >= fetch as usize { break; }
|
||||
let mut parts = line.splitn(3, ' ');
|
||||
let mut parts = line.splitn(4, ' ');
|
||||
let hash = parts.next().unwrap_or("").to_string();
|
||||
let ts_str = parts.next().unwrap_or("0");
|
||||
let timestamp: i64 = ts_str.parse().unwrap_or(0);
|
||||
let author = parts.next().unwrap_or("").to_string();
|
||||
let subject = parts.next().unwrap_or("").to_string();
|
||||
if !hash.is_empty() {
|
||||
commits.push(serde_json::json!({
|
||||
"hash": hash,
|
||||
"subject": subject,
|
||||
"timestamp": timestamp,
|
||||
"author": author,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user