struct expire_reflog_cb: a new callback data type
Add a new data type, "struct expire_reflog_cb", for holding the data that expire_reflog() passes to expire_reflog_ent() via for_each_reflog_ent(). For now it only holds a pointer to a "struct expire_reflog_policy_cb", which still contains all of the actual data. In future commits we will move some fields from the latter to the former. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Dec 12, 2014 at 09:56 UTC
ddd64c566d0b9d110ec51e269b8ce8630fa36348
1 file changed
+26
-17
builtin/reflog.c
+26
-17
@@ -50,10 +50,15 @@ struct expire_reflog_policy_cb {
50
struct commit_list *tips;
51
};
52
53
+struct expire_reflog_cb {
54
+ void *policy_cb;
55
+};
56
+
57
struct collected_reflog {
58
unsigned char sha1[20];
59
char reflog[FLEX_ARRAY];
60
};
61
+
62
struct collect_reflog_cb {
63
struct collected_reflog **e;
64
int alloc;
@@ -328,28 +333,29 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
333
const char *email, unsigned long timestamp, int tz,
334
const char *message, void *cb_data)
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;
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;
341
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)
345
printf("would prune %s", message);
340
- else if (cb->cmd->verbose)
346
+ else if (policy_cb->cmd->verbose)
347
printf("prune %s", message);
348
} else {
343
- if (cb->newlog) {
349
+ if (policy_cb->newlog) {
350
char sign = (tz < 0) ? '-' : '+';
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",
353
sha1_to_hex(osha1), sha1_to_hex(nsha1),
354
email, timestamp, sign, zone,
355
message);
350
- hashcpy(cb->last_kept_sha1, nsha1);
356
+ hashcpy(policy_cb->last_kept_sha1, nsha1);
357
}
352
- if (cb->cmd->verbose)
358
+ if (policy_cb->cmd->verbose)
359
printf("keep %s", message);
360
}
361
return 0;
@@ -421,12 +427,15 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
427
unsigned int flags, struct cmd_reflog_expire_cb *cmd)
428
{
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;
432
struct ref_lock *lock;
433
char *log_file;
434
int status = 0;
435
436
memset(&cb, 0, sizeof(cb));
437
+ memset(&policy_cb, 0, sizeof(policy_cb));
438
+ cb.policy_cb = &policy_cb;
439
440
/*
441
* The reflog file is locked by holding the lock on the
@@ -457,19 +466,19 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
466
strbuf_release(&err);
467
goto failure;
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) {
471
error("cannot fdopen %s (%s)",
472
reflog_lock.filename.buf, strerror(errno));
473
goto failure;
474
}
475
}
476
468
- cb.cmd = cmd;
477
+ policy_cb.cmd = cmd;
478
470
- reflog_expiry_prepare(refname, sha1, &cb);
479
+ reflog_expiry_prepare(refname, sha1, &policy_cb);
480
for_each_reflog_ent(refname, expire_reflog_ent, &cb);
472
- reflog_expiry_cleanup(&cb);
481
+ reflog_expiry_cleanup(&policy_cb);
482
483
if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
484
if (close_lock_file(&reflog_lock)) {
@@ -477,7 +486,7 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
486
strerror(errno));
487
} else if ((flags & EXPIRE_REFLOGS_UPDATE_REF) &&
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 ||
490
write_str_in_full(lock->lock_fd, "\n") != 1 ||
491
close_ref(lock) < 0)) {
492
status |= error("couldn't write %s",