@@ -20,13 +20,6 @@ static const char reflog_delete_usage[] =
20
20
static unsigned long default_reflog_expire ;
21
21
static unsigned long default_reflog_expire_unreachable ;
22
22
23
- enum expire_reflog_flags {
24
- EXPIRE_REFLOGS_DRY_RUN = 1 << 0 ,
25
- EXPIRE_REFLOGS_UPDATE_REF = 1 << 1 ,
26
- EXPIRE_REFLOGS_VERBOSE = 1 << 2 ,
27
- EXPIRE_REFLOGS_REWRITE = 1 << 3
28
- };
29
-
30
23
struct cmd_reflog_expire_cb {
31
24
struct rev_info revs ;
32
25
int stalefix ;
@@ -48,13 +41,6 @@ struct expire_reflog_policy_cb {
48
41
struct commit_list * tips ;
49
42
};
50
43
51
- struct expire_reflog_cb {
52
- unsigned int flags ;
53
- void * policy_cb ;
54
- FILE * newlog ;
55
- unsigned char last_kept_sha1 [20 ];
56
- };
57
-
58
44
struct collected_reflog {
59
45
unsigned char sha1 [20 ];
60
46
char reflog [FLEX_ARRAY ];
@@ -330,38 +316,6 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
330
316
return 0 ;
331
317
}
332
318
333
- static int expire_reflog_ent (unsigned char * osha1 , unsigned char * nsha1 ,
334
- const char * email , unsigned long timestamp , int tz ,
335
- const char * message , void * cb_data )
336
- {
337
- struct expire_reflog_cb * cb = cb_data ;
338
- struct expire_reflog_policy_cb * policy_cb = cb -> policy_cb ;
339
-
340
- if (cb -> flags & EXPIRE_REFLOGS_REWRITE )
341
- osha1 = cb -> last_kept_sha1 ;
342
-
343
- if (should_expire_reflog_ent (osha1 , nsha1 , email , timestamp , tz ,
344
- message , policy_cb )) {
345
- if (!cb -> newlog )
346
- printf ("would prune %s" , message );
347
- else if (cb -> flags & EXPIRE_REFLOGS_VERBOSE )
348
- printf ("prune %s" , message );
349
- } else {
350
- if (cb -> newlog ) {
351
- char sign = (tz < 0 ) ? '-' : '+' ;
352
- int zone = (tz < 0 ) ? (- tz ) : tz ;
353
- fprintf (cb -> newlog , "%s %s %s %lu %c%04d\t%s" ,
354
- sha1_to_hex (osha1 ), sha1_to_hex (nsha1 ),
355
- email , timestamp , sign , zone ,
356
- message );
357
- hashcpy (cb -> last_kept_sha1 , nsha1 );
358
- }
359
- if (cb -> flags & EXPIRE_REFLOGS_VERBOSE )
360
- printf ("keep %s" , message );
361
- }
362
- return 0 ;
363
- }
364
-
365
319
static int push_tip_to_list (const char * refname , const unsigned char * sha1 ,
366
320
int flags , void * cb_data )
367
321
{
@@ -428,90 +382,6 @@ static void reflog_expiry_cleanup(void *cb_data)
428
382
}
429
383
}
430
384
431
- static int expire_reflog (const char * refname , const unsigned char * sha1 ,
432
- unsigned int flags , void * policy_cb_data )
433
- {
434
- static struct lock_file reflog_lock ;
435
- struct expire_reflog_cb cb ;
436
- struct ref_lock * lock ;
437
- char * log_file ;
438
- int status = 0 ;
439
-
440
- memset (& cb , 0 , sizeof (cb ));
441
- cb .flags = flags ;
442
- cb .policy_cb = policy_cb_data ;
443
-
444
- /*
445
- * The reflog file is locked by holding the lock on the
446
- * reference itself, plus we might need to update the
447
- * reference if --updateref was specified:
448
- */
449
- lock = lock_any_ref_for_update (refname , sha1 , 0 , NULL );
450
- if (!lock )
451
- return error ("cannot lock ref '%s'" , refname );
452
- if (!reflog_exists (refname )) {
453
- unlock_ref (lock );
454
- return 0 ;
455
- }
456
-
457
- log_file = git_pathdup ("logs/%s" , refname );
458
- if (!(flags & EXPIRE_REFLOGS_DRY_RUN )) {
459
- /*
460
- * Even though holding $GIT_DIR/logs/$reflog.lock has
461
- * no locking implications, we use the lock_file
462
- * machinery here anyway because it does a lot of the
463
- * work we need, including cleaning up if the program
464
- * exits unexpectedly.
465
- */
466
- if (hold_lock_file_for_update (& reflog_lock , log_file , 0 ) < 0 ) {
467
- struct strbuf err = STRBUF_INIT ;
468
- unable_to_lock_message (log_file , errno , & err );
469
- error ("%s" , err .buf );
470
- strbuf_release (& err );
471
- goto failure ;
472
- }
473
- cb .newlog = fdopen_lock_file (& reflog_lock , "w" );
474
- if (!cb .newlog ) {
475
- error ("cannot fdopen %s (%s)" ,
476
- reflog_lock .filename .buf , strerror (errno ));
477
- goto failure ;
478
- }
479
- }
480
-
481
- reflog_expiry_prepare (refname , sha1 , cb .policy_cb );
482
- for_each_reflog_ent (refname , expire_reflog_ent , & cb );
483
- reflog_expiry_cleanup (cb .policy_cb );
484
-
485
- if (!(flags & EXPIRE_REFLOGS_DRY_RUN )) {
486
- if (close_lock_file (& reflog_lock )) {
487
- status |= error ("couldn't write %s: %s" , log_file ,
488
- strerror (errno ));
489
- } else if ((flags & EXPIRE_REFLOGS_UPDATE_REF ) &&
490
- (write_in_full (lock -> lock_fd ,
491
- sha1_to_hex (cb .last_kept_sha1 ), 40 ) != 40 ||
492
- write_str_in_full (lock -> lock_fd , "\n" ) != 1 ||
493
- close_ref (lock ) < 0 )) {
494
- status |= error ("couldn't write %s" ,
495
- lock -> lk -> filename .buf );
496
- rollback_lock_file (& reflog_lock );
497
- } else if (commit_lock_file (& reflog_lock )) {
498
- status |= error ("unable to commit reflog '%s' (%s)" ,
499
- log_file , strerror (errno ));
500
- } else if ((flags & EXPIRE_REFLOGS_UPDATE_REF ) && commit_ref (lock )) {
501
- status |= error ("couldn't set %s" , lock -> ref_name );
502
- }
503
- }
504
- free (log_file );
505
- unlock_ref (lock );
506
- return status ;
507
-
508
- failure :
509
- rollback_lock_file (& reflog_lock );
510
- free (log_file );
511
- unlock_ref (lock );
512
- return -1 ;
513
- }
514
-
515
385
static int collect_reflog (const char * ref , const unsigned char * sha1 , int unused , void * cb_data )
516
386
{
517
387
struct collected_reflog * e ;
@@ -727,7 +597,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
727
597
for (i = 0 ; i < collected .nr ; i ++ ) {
728
598
struct collected_reflog * e = collected .e [i ];
729
599
set_reflog_expiry_param (& cb .cmd , explicit_expiry , e -> reflog );
730
- status |= expire_reflog (e -> reflog , e -> sha1 , flags , & cb );
600
+ status |= reflog_expire (e -> reflog , e -> sha1 , flags ,
601
+ reflog_expiry_prepare ,
602
+ should_expire_reflog_ent ,
603
+ reflog_expiry_cleanup ,
604
+ & cb );
731
605
free (e );
732
606
}
733
607
free (collected .e );
@@ -741,7 +615,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
741
615
continue ;
742
616
}
743
617
set_reflog_expiry_param (& cb .cmd , explicit_expiry , ref );
744
- status |= expire_reflog (ref , sha1 , flags , & cb );
618
+ status |= reflog_expire (ref , sha1 , flags ,
619
+ reflog_expiry_prepare ,
620
+ should_expire_reflog_ent ,
621
+ reflog_expiry_cleanup ,
622
+ & cb );
745
623
}
746
624
return status ;
747
625
}
@@ -813,7 +691,11 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
813
691
cb .cmd .expire_total = 0 ;
814
692
}
815
693
816
- status |= expire_reflog (ref , sha1 , flags , & cb );
694
+ status |= reflog_expire (ref , sha1 , flags ,
695
+ reflog_expiry_prepare ,
696
+ should_expire_reflog_ent ,
697
+ reflog_expiry_cleanup ,
698
+ & cb );
817
699
free (ref );
818
700
}
819
701
return status ;
0 commit comments