reflog_expire: convert to struct object_id

Adjust the callback functions to take struct object_id * instead of unsigned char *, and modify related static functions accordingly. Introduce a temporary object_id instance into files_reflog_expire and copy the SHA-1 value passed in. This is necessary because the sha1 parameter can come indirectly from get_sha1. Without the temporary, it would require much more refactoring to be able to convert this function. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 6, 2017 at 22:10 UTC 4322478a496a5b729a77792584e427d9e7132386
3 files changed +19 -16
builtin/reflog.c
+11 -11
@@ -186,13 +186,13 @@ static int commit_is_complete(struct commit *commit)
186 return !is_incomplete;
187 }
188
189 -static int keep_entry(struct commit **it, unsigned char *sha1)
189 +static int keep_entry(struct commit **it, struct object_id *oid)
190 {
191 struct commit *commit;
192
193 - if (is_null_sha1(sha1))
193 + if (is_null_oid(oid))
194 return 1;
195 - commit = lookup_commit_reference_gently(sha1, 1);
195 + commit = lookup_commit_reference_gently(oid->hash, 1);
196 if (!commit)
197 return 0;
198
@@ -251,17 +251,17 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
251 cb->mark_list = leftover;
252 }
253
254 -static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, unsigned char *sha1)
254 +static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, struct object_id *oid)
255 {
256 /*
257 * We may or may not have the commit yet - if not, look it
258 * up using the supplied sha1.
259 */
260 if (!commit) {
261 - if (is_null_sha1(sha1))
261 + if (is_null_oid(oid))
262 return 0;
263
264 - commit = lookup_commit_reference_gently(sha1, 1);
264 + commit = lookup_commit_reference_gently(oid->hash, 1);
265
266 /* Not a commit -- keep it */
267 if (!commit)
@@ -283,7 +283,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit
283 /*
284 * Return true iff the specified reflog entry should be expired.
285 */
286 -static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
286 +static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
287 const char *email, unsigned long timestamp, int tz,
288 const char *message, void *cb_data)
289 {
@@ -295,13 +295,13 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
295
296 old = new = NULL;
297 if (cb->cmd.stalefix &&
298 - (!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
298 + (!keep_entry(&old, ooid) || !keep_entry(&new, noid)))
299 return 1;
300
301 if (timestamp < cb->cmd.expire_unreachable) {
302 if (cb->unreachable_expire_kind == UE_ALWAYS)
303 return 1;
304 - if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
304 + if (unreachable(cb, old, ooid) || unreachable(cb, new, noid))
305 return 1;
306 }
307
@@ -326,7 +326,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid,
326 }
327
328 static void reflog_expiry_prepare(const char *refname,
329 - const unsigned char *sha1,
329 + const struct object_id *oid,
330 void *cb_data)
331 {
332 struct expire_reflog_policy_cb *cb = cb_data;
@@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname,
335 cb->tip_commit = NULL;
336 cb->unreachable_expire_kind = UE_HEAD;
337 } else {
338 - cb->tip_commit = lookup_commit_reference_gently(sha1, 1);
338 + cb->tip_commit = lookup_commit_reference_gently(oid->hash, 1);
339 if (!cb->tip_commit)
340 cb->unreachable_expire_kind = UE_ALWAYS;
341 else
refs.h
+3 -3
@@ -611,10 +611,10 @@ enum expire_reflog_flags {
611 * unlocked again.
612 */
613 typedef void reflog_expiry_prepare_fn(const char *refname,
614 - const unsigned char *sha1,
614 + const struct object_id *oid,
615 void *cb_data);
616 -typedef int reflog_expiry_should_prune_fn(unsigned char *osha1,
617 - unsigned char *nsha1,
616 +typedef int reflog_expiry_should_prune_fn(struct object_id *ooid,
617 + struct object_id *noid,
618 const char *email,
619 unsigned long timestamp, int tz,
620 const char *message, void *cb_data);
refs/files-backend.c
+5 -2
@@ -3207,7 +3207,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
3207 if (cb->flags & EXPIRE_REFLOGS_REWRITE)
3208 ooid = &cb->last_kept_oid;
3209
3210 - if ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz,
3210 + if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz,
3211 message, policy_cb)) {
3212 if (!cb->newlog)
3213 printf("would prune %s", message);
@@ -3244,6 +3244,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
3244 int status = 0;
3245 int type;
3246 struct strbuf err = STRBUF_INIT;
3247 + struct object_id oid;
3248
3249 memset(&cb, 0, sizeof(cb));
3250 cb.flags = flags;
@@ -3293,7 +3294,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
3294 }
3295 }
3296
3296 - (*prepare_fn)(refname, sha1, cb.policy_cb);
3297 + hashcpy(oid.hash, sha1);
3298 +
3299 + (*prepare_fn)(refname, &oid, cb.policy_cb);
3300 refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
3301 (*cleanup_fn)(cb.policy_cb);
3302