@@ -442,50 +442,64 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
442
442
return NULL ;
443
443
}
444
444
445
+ /*
446
+ * Returns 0 if there was no previous error and gc can proceed, 1 if
447
+ * gc should not proceed due to an error in the last run. Prints a
448
+ * message and returns -1 if an error occured while reading gc.log
449
+ */
445
450
static int report_last_gc_error (void )
446
451
{
447
452
struct strbuf sb = STRBUF_INIT ;
448
453
int ret = 0 ;
454
+ ssize_t len ;
449
455
struct stat st ;
450
456
char * gc_log_path = git_pathdup ("gc.log" );
451
457
452
458
if (stat (gc_log_path , & st )) {
453
459
if (errno == ENOENT )
454
460
goto done ;
455
461
456
- ret = error_errno (_ ("Can't stat %s " ), gc_log_path );
462
+ ret = error_errno (_ ("cannot stat '%s' " ), gc_log_path );
457
463
goto done ;
458
464
}
459
465
460
466
if (st .st_mtime < gc_log_expire_time )
461
467
goto done ;
462
468
463
- ret = strbuf_read_file (& sb , gc_log_path , 0 );
464
- if (ret > 0 )
465
- ret = error (_ ("The last gc run reported the following. "
469
+ len = strbuf_read_file (& sb , gc_log_path , 0 );
470
+ if (len < 0 )
471
+ ret = error_errno (_ ("cannot read '%s'" ), gc_log_path );
472
+ else if (len > 0 ) {
473
+ /*
474
+ * A previous gc failed. Report the error, and don't
475
+ * bother with an automatic gc run since it is likely
476
+ * to fail in the same way.
477
+ */
478
+ warning (_ ("The last gc run reported the following. "
466
479
"Please correct the root cause\n"
467
480
"and remove %s.\n"
468
481
"Automatic cleanup will not be performed "
469
482
"until the file is removed.\n\n"
470
483
"%s" ),
471
484
gc_log_path , sb .buf );
485
+ ret = 1 ;
486
+ }
472
487
strbuf_release (& sb );
473
488
done :
474
489
free (gc_log_path );
475
490
return ret ;
476
491
}
477
492
478
- static int gc_before_repack (void )
493
+ static void gc_before_repack (void )
479
494
{
480
495
if (pack_refs && run_command_v_opt (pack_refs_cmd .argv , RUN_GIT_CMD ))
481
- return error (FAILED_RUN , pack_refs_cmd .argv [0 ]);
496
+ die (FAILED_RUN , pack_refs_cmd .argv [0 ]);
482
497
483
498
if (prune_reflogs && run_command_v_opt (reflog .argv , RUN_GIT_CMD ))
484
- return error (FAILED_RUN , reflog .argv [0 ]);
499
+ die (FAILED_RUN , reflog .argv [0 ]);
485
500
486
501
pack_refs = 0 ;
487
502
prune_reflogs = 0 ;
488
- return 0 ;
489
503
}
490
504
491
505
int cmd_gc (int argc , const char * * argv , const char * prefix )
@@ -566,13 +580,17 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
566
580
fprintf (stderr , _ ("See \"git help gc\" for manual housekeeping.\n" ));
567
581
}
568
582
if (detach_auto ) {
569
- if (report_last_gc_error ())
570
- return -1 ;
583
+ int ret = report_last_gc_error ();
584
+ if (ret < 0 )
585
+ /* an I/O error occured, already reported */
586
+ exit (128 );
587
+ if (ret == 1 )
588
+ /* Last gc --auto failed. Skip this one. */
589
+ return 0 ;
571
590
572
591
if (lock_repo_for_gc (force , & pid ))
573
592
return 0 ;
574
- if (gc_before_repack ())
575
- return -1 ;
593
+ gc_before_repack (); /* dies on failure */
576
594
delete_tempfile (& pidfile );
577
595
578
596
/*
@@ -612,13 +630,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
612
630
atexit (process_log_file_at_exit );
613
631
}
614
632
615
- if (gc_before_repack ())
616
- return -1 ;
633
+ gc_before_repack ();
617
634
618
635
if (!repository_format_precious_objects ) {
619
636
close_all_packs (the_repository -> objects );
620
637
if (run_command_v_opt (repack .argv , RUN_GIT_CMD ))
621
- return error (FAILED_RUN , repack .argv [0 ]);
638
+ die (FAILED_RUN , repack .argv [0 ]);
622
639
623
640
if (prune_expire ) {
624
641
argv_array_push (& prune , prune_expire );
@@ -628,18 +645,18 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
628
645
argv_array_push (& prune ,
629
646
"--exclude-promisor-objects" );
630
647
if (run_command_v_opt (prune .argv , RUN_GIT_CMD ))
631
- return error (FAILED_RUN , prune .argv [0 ]);
648
+ die (FAILED_RUN , prune .argv [0 ]);
632
649
}
633
650
}
634
651
635
652
if (prune_worktrees_expire ) {
636
653
argv_array_push (& prune_worktrees , prune_worktrees_expire );
637
654
if (run_command_v_opt (prune_worktrees .argv , RUN_GIT_CMD ))
638
- return error (FAILED_RUN , prune_worktrees .argv [0 ]);
655
+ die (FAILED_RUN , prune_worktrees .argv [0 ]);
639
656
}
640
657
641
658
if (run_command_v_opt (rerere .argv , RUN_GIT_CMD ))
642
- return error (FAILED_RUN , rerere .argv [0 ]);
659
+ die (FAILED_RUN , rerere .argv [0 ]);
643
660
644
661
report_garbage = report_pack_garbage ;
645
662
reprepare_packed_git (the_repository );
0 commit comments