@@ -441,27 +441,28 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
441
441
return NULL ;
442
442
}
443
443
444
- static int report_last_gc_error (void )
444
+ static void report_last_gc_error (void )
445
445
{
446
446
struct strbuf sb = STRBUF_INIT ;
447
- int ret = 0 ;
447
+ ssize_t len ;
448
448
struct stat st ;
449
449
char * gc_log_path = git_pathdup ("gc.log" );
450
450
451
451
if (stat (gc_log_path , & st )) {
452
452
if (errno == ENOENT )
453
453
goto done ;
454
454
455
- ret = error_errno (_ ("Can't stat %s" ), gc_log_path );
456
- goto done ;
455
+ die_errno (_ ("cannot stat '%s'" ), gc_log_path );
457
456
}
458
457
459
458
if (st .st_mtime < gc_log_expire_time )
460
459
goto done ;
461
460
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. "
465
466
"Please correct the root cause\n"
466
467
"and remove %s.\n"
467
468
"Automatic cleanup will not be performed "
@@ -471,20 +472,18 @@ static int report_last_gc_error(void)
471
472
strbuf_release (& sb );
472
473
done :
473
474
free (gc_log_path );
474
- return ret ;
475
475
}
476
476
477
- static int gc_before_repack (void )
477
+ static void gc_before_repack (void )
478
478
{
479
479
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 ]);
481
481
482
482
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 ]);
484
484
485
485
pack_refs = 0 ;
486
486
prune_reflogs = 0 ;
487
- return 0 ;
488
487
}
489
488
490
489
int 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)
565
564
fprintf (stderr , _ ("See \"git help gc\" for manual housekeeping.\n" ));
566
565
}
567
566
if (detach_auto ) {
568
- if (report_last_gc_error ())
569
- return -1 ;
567
+ report_last_gc_error (); /* dies on error */
570
568
571
569
if (lock_repo_for_gc (force , & pid ))
572
570
return 0 ;
573
- if (gc_before_repack ())
574
- return -1 ;
571
+ gc_before_repack (); /* dies on failure */
575
572
delete_tempfile (& pidfile );
576
573
577
574
/*
@@ -611,13 +608,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
611
608
atexit (process_log_file_at_exit );
612
609
}
613
610
614
- if (gc_before_repack ())
615
- return -1 ;
611
+ gc_before_repack ();
616
612
617
613
if (!repository_format_precious_objects ) {
618
614
close_all_packs (the_repository -> objects );
619
615
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 ]);
621
617
622
618
if (prune_expire ) {
623
619
argv_array_push (& prune , prune_expire );
@@ -627,18 +623,18 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
627
623
argv_array_push (& prune ,
628
624
"--exclude-promisor-objects" );
629
625
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 ]);
631
627
}
632
628
}
633
629
634
630
if (prune_worktrees_expire ) {
635
631
argv_array_push (& prune_worktrees , prune_worktrees_expire );
636
632
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 ]);
638
634
}
639
635
640
636
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 ]);
642
638
643
639
report_garbage = report_pack_garbage ;
644
640
reprepare_packed_git (the_repository );
0 commit comments