@@ -303,25 +303,48 @@ export const useGitService = createSingletonComposable(() => {
303303 }
304304 }
305305
306- async function getCommitByHash ( commitHash : string ) : Promise < Commit | null > {
306+ async function getCommitByHash ( commitHashes : string [ ] ) : Promise < Commit [ ] > {
307307 try {
308- // 直接查询指定的 commit
309- const logResult = await git . log ( [ '--stat' , commitHash , '-1' ] ) as ExtendedLogResult
308+ if ( commitHashes . length === 0 ) {
309+ return [ ]
310+ }
311+
312+ // 构建查询参数,查询多个 commit
313+ const logArgs = [ '--stat' ]
314+ commitHashes . forEach ( ( hash ) => {
315+ logArgs . push ( hash )
316+ } )
317+ logArgs . push ( `-${ commitHashes . length } ` )
318+
319+ const logResult = await git . log ( logArgs ) as ExtendedLogResult
310320
311321 if ( logResult . all . length === 0 ) {
312- return null
322+ return [ ]
313323 }
314324
315- const commit = logResult . all [ 0 ]
316- const { author_email, author_name } = commit
317- commit . authorEmail = author_email
318- commit . authorName = author_name
325+ // 处理查询结果
326+ const commits = logResult . all . map ( ( commit ) => {
327+ const { author_email, author_name } = commit
328+ commit . authorEmail = author_email
329+ commit . authorName = author_name
330+ return commit
331+ } )
332+
333+ // 按照输入的 hash 顺序排序结果
334+ const hashToCommit = new Map < string , Commit > ( )
335+ commits . forEach ( ( commit ) => {
336+ hashToCommit . set ( commit . hash , commit )
337+ } )
338+
339+ const orderedCommits = commitHashes
340+ . map ( hash => hashToCommit . get ( hash ) )
341+ . filter ( ( commit ) : commit is Commit => commit !== undefined )
319342
320- return commit
343+ return orderedCommits
321344 }
322345 catch ( error ) {
323346 logger . error ( 'Error getting commit by hash:' , error )
324- return null
347+ return [ ]
325348 }
326349 }
327350
0 commit comments