@@ -251,43 +251,7 @@ impl BlameService {
251251 format ! ( "refs/heads/{}" , ref_str)
252252 } ;
253253 tracing:: debug!( "Trying to resolve ref: {}" , full_ref_name) ;
254- match self . mono_storage . get_ref_by_name ( & full_ref_name) . await {
255- Ok ( Some ( commit_id) ) => self
256- . get_commit_by_hash ( & commit_id. ref_commit_hash )
257- . await ?
258- . ok_or_else ( || GitError :: ObjectNotFound ( ref_str. to_string ( ) ) ) ,
259- Ok ( None ) => {
260- // Fallback to default branch
261- tracing:: debug!(
262- "Ref not found by name, falling back to get_ref with root path"
263- ) ;
264- match self . mono_storage . get_ref ( "/" ) . await {
265- Ok ( Some ( commit_id) ) => {
266- tracing:: debug!(
267- "Found commit via fallback: {}" ,
268- commit_id. ref_commit_hash
269- ) ;
270- self . get_commit_by_hash ( & commit_id. ref_commit_hash )
271- . await ?
272- . ok_or_else ( || {
273- GitError :: ObjectNotFound ( ref_str. to_string ( ) )
274- } )
275- }
276- Ok ( None ) => {
277- tracing:: debug!( "No commit found via fallback" ) ;
278- Err ( GitError :: ObjectNotFound ( ref_str. to_string ( ) ) )
279- }
280- Err ( e) => Err ( GitError :: CustomError ( format ! (
281- "Failed to resolve reference: {}" ,
282- e
283- ) ) ) ,
284- }
285- }
286- Err ( e) => Err ( GitError :: CustomError ( format ! (
287- "Failed to resolve reference: {}" ,
288- e
289- ) ) ) ,
290- }
254+ self . commit_by_ref_or_default ( & full_ref_name, ref_str) . await
291255 }
292256 }
293257 None => {
@@ -319,6 +283,64 @@ impl BlameService {
319283 Ok ( resolved_commit)
320284 }
321285
286+ // Extracted helper: resolve commit by ref name with safe fallback
287+ async fn commit_by_ref_or_default (
288+ & self ,
289+ full_ref_name : & str ,
290+ ref_display_name : & str ,
291+ ) -> Result < Commit , GitError > {
292+ match self . mono_storage . get_ref_by_name ( full_ref_name) . await {
293+ Ok ( Some ( ref_row) ) => match self . get_commit_by_hash ( & ref_row. ref_commit_hash ) . await ? {
294+ Some ( commit) => Ok ( commit) ,
295+ None => {
296+ tracing:: warn!(
297+ "Ref {} -> {} missing in mono commits, falling back to root default" ,
298+ full_ref_name,
299+ ref_row. ref_commit_hash
300+ ) ;
301+ match self . mono_storage . get_ref ( "/" ) . await {
302+ Ok ( Some ( default_ref) ) => self
303+ . get_commit_by_hash ( & default_ref. ref_commit_hash )
304+ . await ?
305+ . ok_or_else ( || GitError :: ObjectNotFound ( ref_display_name. to_string ( ) ) ) ,
306+ Ok ( None ) => {
307+ tracing:: debug!( "No default ref found at root path" ) ;
308+ Err ( GitError :: ObjectNotFound ( ref_display_name. to_string ( ) ) )
309+ }
310+ Err ( e) => Err ( GitError :: CustomError ( format ! (
311+ "Failed to resolve default reference: {}" ,
312+ e
313+ ) ) ) ,
314+ }
315+ }
316+ } ,
317+ Ok ( None ) => {
318+ tracing:: debug!(
319+ "Ref not found by name: {}, falling back to root default" ,
320+ full_ref_name
321+ ) ;
322+ match self . mono_storage . get_ref ( "/" ) . await {
323+ Ok ( Some ( default_ref) ) => self
324+ . get_commit_by_hash ( & default_ref. ref_commit_hash )
325+ . await ?
326+ . ok_or_else ( || GitError :: ObjectNotFound ( ref_display_name. to_string ( ) ) ) ,
327+ Ok ( None ) => {
328+ tracing:: debug!( "No default ref found at root path" ) ;
329+ Err ( GitError :: ObjectNotFound ( ref_display_name. to_string ( ) ) )
330+ }
331+ Err ( e) => Err ( GitError :: CustomError ( format ! (
332+ "Failed to resolve reference: {}" ,
333+ e
334+ ) ) ) ,
335+ }
336+ }
337+ Err ( e) => Err ( GitError :: CustomError ( format ! (
338+ "Failed to resolve reference: {}" ,
339+ e
340+ ) ) ) ,
341+ }
342+ }
343+
322344 /// Get file version at specific commit (with caching)
323345 async fn get_file_version (
324346 & self ,
0 commit comments