@@ -441,27 +441,28 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
441441 return NULL ;
442442}
443443
444- static int report_last_gc_error (void )
444+ static void report_last_gc_error (void )
445445{
446446 struct strbuf sb = STRBUF_INIT ;
447- int ret = 0 ;
447+ ssize_t len ;
448448 struct stat st ;
449449 char * gc_log_path = git_pathdup ("gc.log" );
450450
451451 if (stat (gc_log_path , & st )) {
452452 if (errno == ENOENT )
453453 goto done ;
454454
455- ret = error_errno (_ ("Can't stat %s" ), gc_log_path );
456- goto done ;
455+ die_errno (_ ("cannot stat '%s'" ), gc_log_path );
457456 }
458457
459458 if (st .st_mtime < gc_log_expire_time )
460459 goto done ;
461460
462- ret = strbuf_read_file (& sb , gc_log_path , 0 );
463- if (ret > 0 )
464- ret = error (_ ("The last gc run reported the following. "
461+ len = strbuf_read_file (& sb , gc_log_path , 0 );
462+ if (len < 0 )
463+ die_errno (_ ("cannot read '%s'" ), gc_log_path );
464+ else if (len > 0 )
465+ die (_ ("The last gc run reported the following. "
465466 "Please correct the root cause\n"
466467 "and remove %s.\n"
467468 "Automatic cleanup will not be performed "
@@ -471,20 +472,18 @@ static int report_last_gc_error(void)
471472 strbuf_release (& sb );
472473done :
473474 free (gc_log_path );
474- return ret ;
475475}
476476
477- static int gc_before_repack (void )
477+ static void gc_before_repack (void )
478478{
479479 if (pack_refs && run_command_v_opt (pack_refs_cmd .argv , RUN_GIT_CMD ))
480- return error (FAILED_RUN , pack_refs_cmd .argv [0 ]);
480+ die (FAILED_RUN , pack_refs_cmd .argv [0 ]);
481481
482482 if (prune_reflogs && run_command_v_opt (reflog .argv , RUN_GIT_CMD ))
483- return error (FAILED_RUN , reflog .argv [0 ]);
483+ die (FAILED_RUN , reflog .argv [0 ]);
484484
485485 pack_refs = 0 ;
486486 prune_reflogs = 0 ;
487- return 0 ;
488487}
489488
490489int cmd_gc (int argc , const char * * argv , const char * prefix )
@@ -565,13 +564,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
565564 fprintf (stderr , _ ("See \"git help gc\" for manual housekeeping.\n" ));
566565 }
567566 if (detach_auto ) {
568- if (report_last_gc_error ())
569- return -1 ;
567+ report_last_gc_error (); /* dies on error */
570568
571569 if (lock_repo_for_gc (force , & pid ))
572570 return 0 ;
573- if (gc_before_repack ())
574- return -1 ;
571+ gc_before_repack (); /* dies on failure */
575572 delete_tempfile (& pidfile );
576573
577574 /*
@@ -611,13 +608,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
611608 atexit (process_log_file_at_exit );
612609 }
613610
614- if (gc_before_repack ())
615- return -1 ;
611+ gc_before_repack ();
616612
617613 if (!repository_format_precious_objects ) {
618614 close_all_packs (the_repository -> objects );
619615 if (run_command_v_opt (repack .argv , RUN_GIT_CMD ))
620- return error (FAILED_RUN , repack .argv [0 ]);
616+ die (FAILED_RUN , repack .argv [0 ]);
621617
622618 if (prune_expire ) {
623619 argv_array_push (& prune , prune_expire );
@@ -627,18 +623,18 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
627623 argv_array_push (& prune ,
628624 "--exclude-promisor-objects" );
629625 if (run_command_v_opt (prune .argv , RUN_GIT_CMD ))
630- return error (FAILED_RUN , prune .argv [0 ]);
626+ die (FAILED_RUN , prune .argv [0 ]);
631627 }
632628 }
633629
634630 if (prune_worktrees_expire ) {
635631 argv_array_push (& prune_worktrees , prune_worktrees_expire );
636632 if (run_command_v_opt (prune_worktrees .argv , RUN_GIT_CMD ))
637- return error (FAILED_RUN , prune_worktrees .argv [0 ]);
633+ die (FAILED_RUN , prune_worktrees .argv [0 ]);
638634 }
639635
640636 if (run_command_v_opt (rerere .argv , RUN_GIT_CMD ))
641- return error (FAILED_RUN , rerere .argv [0 ]);
637+ die (FAILED_RUN , rerere .argv [0 ]);
642638
643639 report_garbage = report_pack_garbage ;
644640 reprepare_packed_git (the_repository );
0 commit comments