feat(rawDump): add parent_ids to commit payload

Include parent commit hashes in raw dump commit reporting.
- git log format now includes %P (parent hashes)
- parseCommitLog extracts parent_ids as string array
- CommitPayload type extended with parent_ids field
- merge commits may have multiple parents

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
林凯90331 2026-05-18 20:06:15 +08:00
parent a76c92ea2d
commit ad90f40088
3 changed files with 8 additions and 4 deletions

View File

@ -77,15 +77,17 @@ export function parseCommitLog(output: string): Array<{
commit_time: string commit_time: string
git_user_name: string git_user_name: string
git_user_email: string git_user_email: string
parent_ids: string[]
subject: string subject: string
}> { }> {
if (!output.trim()) return [] if (!output.trim()) return []
return output return output
.split('\n') .split('\n')
.map((line) => { .map((line) => {
const [commit_id, commit_time, git_user_name, git_user_email, ...rest] = line.split('|') const [commit_id, commit_time, git_user_name, git_user_email, parent_ids_str, ...rest] = line.split('|')
if (!commit_id || !git_user_email) return null if (!commit_id || !git_user_email) return null
return { commit_id, commit_time, git_user_name, git_user_email, subject: rest.join('|') } const parent_ids = parent_ids_str ? parent_ids_str.trim().split(' ').filter(Boolean) : []
return { commit_id, commit_time, git_user_name, git_user_email, parent_ids, subject: rest.join('|') }
}) })
.filter((item): item is NonNullable<typeof item> => !!item) .filter((item): item is NonNullable<typeof item> => !!item)
} }
@ -96,12 +98,12 @@ export async function getCommitLog(cwd: string, lastCommit?: string): Promise<st
if (lastCommit) { if (lastCommit) {
return gitExec( return gitExec(
['log', `${lastCommit}..HEAD`, '--reverse', '--max-count=50', ...authorFilter, '--format=%H|%aI|%an|%ae|%s'], ['log', `${lastCommit}..HEAD`, '--reverse', '--max-count=50', ...authorFilter, '--format=%H|%aI|%an|%ae|%P|%s'],
cwd, cwd,
) )
} }
return gitExec( return gitExec(
['log', '--since=1 day ago', '--reverse', '--max-count=50', ...authorFilter, '--format=%H|%aI|%an|%ae|%s'], ['log', '--since=1 day ago', '--reverse', '--max-count=50', ...authorFilter, '--format=%H|%aI|%an|%ae|%P|%s'],
cwd, cwd,
) )
} }

View File

@ -87,4 +87,5 @@ export interface CommitPayload {
files: string[] files: string[]
comment: string comment: string
subject: string subject: string
parent_ids: string[]
} }

View File

@ -599,6 +599,7 @@ export async function uploadCommits(
files: extractFilesFromDiff(diff), files: extractFilesFromDiff(diff),
comment: toCommitComment(commit.subject), comment: toCommitComment(commit.subject),
subject: commit.subject, subject: commit.subject,
parent_ids: commit.parent_ids,
} }
await postJson(authData.baseUrl, authData.headers, '/raw-store/commit', body as unknown as Record<string, unknown>) await postJson(authData.baseUrl, authData.headers, '/raw-store/commit', body as unknown as Record<string, unknown>)
// 每成功一个 commit 立即更新 state避免失败后全部重传 // 每成功一个 commit 立即更新 state避免失败后全部重传