@@ -3,7 +3,7 @@ import { createSingletonComposable, useWorkspaceFolders } from 'reactive-vscode'
33
44import type { SimpleGit } from 'simple-git'
55import type { Commit , CommitGraph , ExtendedLogResult , GitOperation } from './types'
6- import { logger } from '@/utils'
6+ import { getBranchColor , logger } from '@/utils'
77
88export * from './types'
99
@@ -44,6 +44,7 @@ export const useGitService = createSingletonComposable(() => {
4444 const { author_email, author_name } = commit
4545 commit . authorEmail = author_email
4646 commit . authorName = author_name
47+
4748 commit . children = [ ]
4849 hashToCommit [ commit . hash ] = commit
4950
@@ -195,11 +196,15 @@ export const useGitService = createSingletonComposable(() => {
195196
196197 if ( isMerge ) {
197198 const sourceBranches : string [ ] = [ ]
199+ const sourceBranchColors : Record < string , string > = { }
200+
198201 if ( commit . parents ) {
199202 for ( let i = 1 ; i < commit . parents . length ; i ++ ) {
200- const parentHash = commit . parents [ i ]
203+ const parentHash : string = commit . parents [ i ]
201204 if ( commitToBranch [ parentHash ] ) {
202- sourceBranches . push ( commitToBranch [ parentHash ] )
205+ const sourceBranch = commitToBranch [ parentHash ]
206+ sourceBranches . push ( sourceBranch )
207+ sourceBranchColors [ sourceBranch ] = getBranchColor ( sourceBranch )
203208 }
204209 }
205210 }
@@ -212,15 +217,32 @@ export const useGitService = createSingletonComposable(() => {
212217 sourceBranches,
213218 targetBranch : branch ,
214219 branchChanged : branchChanged [ commit . hash ] ,
220+ branchColor : getBranchColor ( branch ) ,
221+ targetBranchColor : getBranchColor ( branch ) ,
222+ sourceBranchColors,
215223 }
216224 }
217225 else {
226+ let targetBranch : string | undefined
227+ let targetBranchColor : string | undefined
228+
229+ if ( branchChanged [ commit . hash ] && commit . parents && commit . parents . length > 0 ) {
230+ const parentHash = commit . parents [ 0 ]
231+ if ( commitToBranch [ parentHash ] && commitToBranch [ parentHash ] !== branch ) {
232+ targetBranch = commitToBranch [ parentHash ]
233+ targetBranchColor = getBranchColor ( targetBranch )
234+ }
235+ }
236+
218237 return {
219238 type : 'commit' ,
220239 branch,
221240 hash : commit . hash ,
222241 message : commit . message ,
223242 branchChanged : branchChanged [ commit . hash ] ,
243+ branchColor : getBranchColor ( branch ) ,
244+ targetBranch,
245+ targetBranchColor,
224246 }
225247 }
226248 } )
0 commit comments