refs: convert read_ref_at to struct object_id

Convert the callers and internals, including struct read_ref_at_cb, of
read_ref_at to use struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
brian m. carlson 2017-10-15 22:07:03 +00:00 committed by Junio C Hamano
parent b420d90980
commit 8eb36d9422
4 changed files with 21 additions and 21 deletions

View File

@ -731,7 +731,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
/* Ah, that is a date spec... */ /* Ah, that is a date spec... */
timestamp_t at; timestamp_t at;
at = approxidate(reflog_base); at = approxidate(reflog_base);
read_ref_at(ref, flags, at, -1, oid.hash, NULL, read_ref_at(ref, flags, at, -1, &oid, NULL,
NULL, NULL, &base); NULL, NULL, &base);
} }
} }
@ -743,7 +743,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
timestamp_t timestamp; timestamp_t timestamp;
int tz; int tz;


if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg, if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
&timestamp, &tz, NULL)) { &timestamp, &tz, NULL)) {
reflog = i; reflog = i;
break; break;

34
refs.c
View File

@ -738,11 +738,11 @@ struct read_ref_at_cb {
timestamp_t at_time; timestamp_t at_time;
int cnt; int cnt;
int reccnt; int reccnt;
unsigned char *sha1; struct object_id *oid;
int found_it; int found_it;


unsigned char osha1[20]; struct object_id ooid;
unsigned char nsha1[20]; struct object_id noid;
int tz; int tz;
timestamp_t date; timestamp_t date;
char **msg; char **msg;
@ -774,25 +774,25 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
* we have not yet updated cb->[n|o]sha1 so they still * we have not yet updated cb->[n|o]sha1 so they still
* hold the values for the previous record. * hold the values for the previous record.
*/ */
if (!is_null_sha1(cb->osha1)) { if (!is_null_oid(&cb->ooid)) {
hashcpy(cb->sha1, noid->hash); oidcpy(cb->oid, noid);
if (hashcmp(cb->osha1, noid->hash)) if (oidcmp(&cb->ooid, noid))
warning("Log for ref %s has gap after %s.", warning("Log for ref %s has gap after %s.",
cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
} }
else if (cb->date == cb->at_time) else if (cb->date == cb->at_time)
hashcpy(cb->sha1, noid->hash); oidcpy(cb->oid, noid);
else if (hashcmp(noid->hash, cb->sha1)) else if (oidcmp(noid, cb->oid))
warning("Log for ref %s unexpectedly ended on %s.", warning("Log for ref %s unexpectedly ended on %s.",
cb->refname, show_date(cb->date, cb->tz, cb->refname, show_date(cb->date, cb->tz,
DATE_MODE(RFC2822))); DATE_MODE(RFC2822)));
hashcpy(cb->osha1, ooid->hash); oidcpy(&cb->ooid, ooid);
hashcpy(cb->nsha1, noid->hash); oidcpy(&cb->noid, noid);
cb->found_it = 1; cb->found_it = 1;
return 1; return 1;
} }
hashcpy(cb->osha1, ooid->hash); oidcpy(&cb->ooid, ooid);
hashcpy(cb->nsha1, noid->hash); oidcpy(&cb->noid, noid);
if (cb->cnt > 0) if (cb->cnt > 0)
cb->cnt--; cb->cnt--;
return 0; return 0;
@ -812,15 +812,15 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
*cb->cutoff_tz = tz; *cb->cutoff_tz = tz;
if (cb->cutoff_cnt) if (cb->cutoff_cnt)
*cb->cutoff_cnt = cb->reccnt; *cb->cutoff_cnt = cb->reccnt;
hashcpy(cb->sha1, ooid->hash); oidcpy(cb->oid, ooid);
if (is_null_sha1(cb->sha1)) if (is_null_oid(cb->oid))
hashcpy(cb->sha1, noid->hash); oidcpy(cb->oid, noid);
/* We just want the first entry */ /* We just want the first entry */
return 1; return 1;
} }


int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt, int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
unsigned char *sha1, char **msg, struct object_id *oid, char **msg,
timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt) timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
{ {
struct read_ref_at_cb cb; struct read_ref_at_cb cb;
@ -833,7 +833,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
cb.cutoff_time = cutoff_time; cb.cutoff_time = cutoff_time;
cb.cutoff_tz = cutoff_tz; cb.cutoff_tz = cutoff_tz;
cb.cutoff_cnt = cutoff_cnt; cb.cutoff_cnt = cutoff_cnt;
cb.sha1 = sha1; cb.oid = oid;


for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb); for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);



2
refs.h
View File

@ -363,7 +363,7 @@ int safe_create_reflog(const char *refname, int force_create, struct strbuf *err
/** Reads log for the value of ref during at_time. **/ /** Reads log for the value of ref during at_time. **/
int read_ref_at(const char *refname, unsigned int flags, int read_ref_at(const char *refname, unsigned int flags,
timestamp_t at_time, int cnt, timestamp_t at_time, int cnt,
unsigned char *sha1, char **msg, struct object_id *oid, char **msg,
timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt); timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);


/** Check if a particular reflog exists */ /** Check if a particular reflog exists */

View File

@ -697,7 +697,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
return -1; return -1;
} }
} }
if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL, if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
&co_time, &co_tz, &co_cnt)) { &co_time, &co_tz, &co_cnt)) {
if (!len) { if (!len) {
if (starts_with(real_ref, "refs/heads/")) { if (starts_with(real_ref, "refs/heads/")) {