@@ -50,10 +50,15 @@ struct expire_reflog_policy_cb {
50
50
struct commit_list * tips ;
51
51
};
52
52
53
+ struct expire_reflog_cb {
54
+ void * policy_cb ;
55
+ };
56
+
53
57
struct collected_reflog {
54
58
unsigned char sha1 [20 ];
55
59
char reflog [FLEX_ARRAY ];
56
60
};
61
+
57
62
struct collect_reflog_cb {
58
63
struct collected_reflog * * e ;
59
64
int alloc ;
@@ -328,28 +333,29 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
328
333
const char * email , unsigned long timestamp , int tz ,
329
334
const char * message , void * cb_data )
330
335
{
331
- struct expire_reflog_policy_cb * cb = cb_data ;
336
+ struct expire_reflog_cb * cb = cb_data ;
337
+ struct expire_reflog_policy_cb * policy_cb = cb -> policy_cb ;
332
338
333
- if (cb -> cmd -> rewrite )
334
- osha1 = cb -> last_kept_sha1 ;
339
+ if (policy_cb -> cmd -> rewrite )
340
+ osha1 = policy_cb -> last_kept_sha1 ;
335
341
336
342
if (should_expire_reflog_ent (osha1 , nsha1 , email , timestamp , tz ,
337
- message , cb_data )) {
338
- if (!cb -> newlog )
343
+ message , policy_cb )) {
344
+ if (!policy_cb -> newlog )
339
345
printf ("would prune %s" , message );
340
- else if (cb -> cmd -> verbose )
346
+ else if (policy_cb -> cmd -> verbose )
341
347
printf ("prune %s" , message );
342
348
} else {
343
- if (cb -> newlog ) {
349
+ if (policy_cb -> newlog ) {
344
350
char sign = (tz < 0 ) ? '-' : '+' ;
345
351
int zone = (tz < 0 ) ? (- tz ) : tz ;
346
- fprintf (cb -> newlog , "%s %s %s %lu %c%04d\t%s" ,
352
+ fprintf (policy_cb -> newlog , "%s %s %s %lu %c%04d\t%s" ,
347
353
sha1_to_hex (osha1 ), sha1_to_hex (nsha1 ),
348
354
email , timestamp , sign , zone ,
349
355
message );
350
- hashcpy (cb -> last_kept_sha1 , nsha1 );
356
+ hashcpy (policy_cb -> last_kept_sha1 , nsha1 );
351
357
}
352
- if (cb -> cmd -> verbose )
358
+ if (policy_cb -> cmd -> verbose )
353
359
printf ("keep %s" , message );
354
360
}
355
361
return 0 ;
@@ -421,12 +427,15 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
421
427
unsigned int flags , struct cmd_reflog_expire_cb * cmd )
422
428
{
423
429
static struct lock_file reflog_lock ;
424
- struct expire_reflog_policy_cb cb ;
430
+ struct expire_reflog_cb cb ;
431
+ struct expire_reflog_policy_cb policy_cb ;
425
432
struct ref_lock * lock ;
426
433
char * log_file ;
427
434
int status = 0 ;
428
435
429
436
memset (& cb , 0 , sizeof (cb ));
437
+ memset (& policy_cb , 0 , sizeof (policy_cb ));
438
+ cb .policy_cb = & policy_cb ;
430
439
431
440
/*
432
441
* The reflog file is locked by holding the lock on the
@@ -457,27 +466,27 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
457
466
strbuf_release (& err );
458
467
goto failure ;
459
468
}
460
- cb .newlog = fdopen_lock_file (& reflog_lock , "w" );
461
- if (!cb .newlog ) {
469
+ policy_cb .newlog = fdopen_lock_file (& reflog_lock , "w" );
470
+ if (!policy_cb .newlog ) {
462
471
error ("cannot fdopen %s (%s)" ,
463
472
reflog_lock .filename .buf , strerror (errno ));
464
473
goto failure ;
465
474
}
466
475
}
467
476
468
- cb .cmd = cmd ;
477
+ policy_cb .cmd = cmd ;
469
478
470
- reflog_expiry_prepare (refname , sha1 , & cb );
479
+ reflog_expiry_prepare (refname , sha1 , & policy_cb );
471
480
for_each_reflog_ent (refname , expire_reflog_ent , & cb );
472
- reflog_expiry_cleanup (& cb );
481
+ reflog_expiry_cleanup (& policy_cb );
473
482
474
483
if (!(flags & EXPIRE_REFLOGS_DRY_RUN )) {
475
484
if (close_lock_file (& reflog_lock )) {
476
485
status |= error ("couldn't write %s: %s" , log_file ,
477
486
strerror (errno ));
478
487
} else if ((flags & EXPIRE_REFLOGS_UPDATE_REF ) &&
479
488
(write_in_full (lock -> lock_fd ,
480
- sha1_to_hex (cb .last_kept_sha1 ), 40 ) != 40 ||
489
+ sha1_to_hex (policy_cb .last_kept_sha1 ), 40 ) != 40 ||
481
490
write_str_in_full (lock -> lock_fd , "\n" ) != 1 ||
482
491
close_ref (lock ) < 0 )) {
483
492
status |= error ("couldn't write %s" ,
0 commit comments