refs: convert each_reflog_ent_fn to struct object_id

Make each_reflog_ent_fn take two struct object_id pointers instead of two pointers to unsigned char. Convert the various callbacks to use struct object_id as well. Also, rename fsck_handle_reflog_sha1 to fsck_handle_reflog_oid. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 21, 2017 at 23:47 UTC 9461d27240c158cf781ce706a077663050179b14
10 files changed +50 -50
builtin/fsck.c
+8 -8
@@ -396,13 +396,13 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
396
397 static int default_refs;
398
399 -static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
399 +static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
400 unsigned long timestamp)
401 {
402 struct object *obj;
403
404 - if (!is_null_sha1(sha1)) {
405 - obj = lookup_object(sha1);
404 + if (!is_null_oid(oid)) {
405 + obj = lookup_object(oid->hash);
406 if (obj && (obj->flags & HAS_OBJ)) {
407 if (timestamp && name_objects)
408 add_decoration(fsck_walk_options.object_names,
@@ -411,13 +411,13 @@ static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
411 obj->used = 1;
412 mark_object_reachable(obj);
413 } else {
414 - error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1));
414 + error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
415 errors_found |= ERROR_REACHABLE;
416 }
417 }
418 }
419
420 -static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
420 +static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,
421 const char *email, unsigned long timestamp, int tz,
422 const char *message, void *cb_data)
423 {
@@ -425,10 +425,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
425
426 if (verbose)
427 fprintf(stderr, "Checking reflog %s->%s\n",
428 - sha1_to_hex(osha1), sha1_to_hex(nsha1));
428 + oid_to_hex(ooid), oid_to_hex(noid));
429
430 - fsck_handle_reflog_sha1(refname, osha1, 0);
431 - fsck_handle_reflog_sha1(refname, nsha1, timestamp);
430 + fsck_handle_reflog_oid(refname, ooid, 0);
431 + fsck_handle_reflog_oid(refname, noid, timestamp);
432 return 0;
433 }
434
builtin/merge-base.c
+3 -3
@@ -131,7 +131,7 @@ static void add_one_commit(unsigned char *sha1, struct rev_collect *revs)
131 commit->object.flags |= TMP_MARK;
132 }
133
134 -static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
134 +static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
135 const char *ident, unsigned long timestamp,
136 int tz, const char *message, void *cbdata)
137 {
@@ -139,9 +139,9 @@ static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
139
140 if (revs->initial) {
141 revs->initial = 0;
142 - add_one_commit(osha1, revs);
142 + add_one_commit(ooid->hash, revs);
143 }
144 - add_one_commit(nsha1, revs);
144 + add_one_commit(noid->hash, revs);
145 return 0;
146 }
147
builtin/reflog.c
+1 -1
@@ -615,7 +615,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
615 return status;
616 }
617
618 -static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
618 +static int count_reflog_ent(struct object_id *ooid, struct object_id *noid,
619 const char *email, unsigned long timestamp, int tz,
620 const char *message, void *cb_data)
621 {
reflog-walk.c
+3 -3
@@ -19,7 +19,7 @@ struct complete_reflogs {
19 int nr, alloc;
20 };
21
22 -static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
22 +static int read_one_reflog(struct object_id *ooid, struct object_id *noid,
23 const char *email, unsigned long timestamp, int tz,
24 const char *message, void *cb_data)
25 {
@@ -28,8 +28,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
28
29 ALLOC_GROW(array->items, array->nr + 1, array->alloc);
30 item = array->items + array->nr;
31 - hashcpy(item->ooid.hash, osha1);
32 - hashcpy(item->noid.hash, nsha1);
31 + oidcpy(&item->ooid, ooid);
32 + oidcpy(&item->noid, noid);
33 item->email = xstrdup(email);
34 item->timestamp = timestamp;
35 item->tz = tz;
refs.c
+12 -12
@@ -674,7 +674,7 @@ struct read_ref_at_cb {
674 int *cutoff_cnt;
675 };
676
677 -static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
677 +static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
678 const char *email, unsigned long timestamp, int tz,
679 const char *message, void *cb_data)
680 {
@@ -698,30 +698,30 @@ static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
698 * hold the values for the previous record.
699 */
700 if (!is_null_sha1(cb->osha1)) {
701 - hashcpy(cb->sha1, nsha1);
702 - if (hashcmp(cb->osha1, nsha1))
701 + hashcpy(cb->sha1, noid->hash);
702 + if (hashcmp(cb->osha1, noid->hash))
703 warning("Log for ref %s has gap after %s.",
704 cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
705 }
706 else if (cb->date == cb->at_time)
707 - hashcpy(cb->sha1, nsha1);
708 - else if (hashcmp(nsha1, cb->sha1))
707 + hashcpy(cb->sha1, noid->hash);
708 + else if (hashcmp(noid->hash, cb->sha1))
709 warning("Log for ref %s unexpectedly ended on %s.",
710 cb->refname, show_date(cb->date, cb->tz,
711 DATE_MODE(RFC2822)));
712 - hashcpy(cb->osha1, osha1);
713 - hashcpy(cb->nsha1, nsha1);
712 + hashcpy(cb->osha1, ooid->hash);
713 + hashcpy(cb->nsha1, noid->hash);
714 cb->found_it = 1;
715 return 1;
716 }
717 - hashcpy(cb->osha1, osha1);
718 - hashcpy(cb->nsha1, nsha1);
717 + hashcpy(cb->osha1, ooid->hash);
718 + hashcpy(cb->nsha1, noid->hash);
719 if (cb->cnt > 0)
720 cb->cnt--;
721 return 0;
722 }
723
724 -static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
724 +static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
725 const char *email, unsigned long timestamp,
726 int tz, const char *message, void *cb_data)
727 {
@@ -735,9 +735,9 @@ static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
735 *cb->cutoff_tz = tz;
736 if (cb->cutoff_cnt)
737 *cb->cutoff_cnt = cb->reccnt;
738 - hashcpy(cb->sha1, osha1);
738 + hashcpy(cb->sha1, ooid->hash);
739 if (is_null_sha1(cb->sha1))
740 - hashcpy(cb->sha1, nsha1);
740 + hashcpy(cb->sha1, noid->hash);
741 /* We just want the first entry */
742 return 1;
743 }
refs.h
+1 -1
@@ -292,7 +292,7 @@ int delete_reflog(const char *refname);
292
293 /* iterate over reflog entries */
294 typedef int each_reflog_ent_fn(
295 - unsigned char *old_sha1, unsigned char *new_sha1,
295 + struct object_id *old_oid, struct object_id *new_oid,
296 const char *committer, unsigned long timestamp,
297 int tz, const char *msg, void *cb_data);
298
refs/files-backend.c
+12 -12
@@ -3113,15 +3113,15 @@ static int files_delete_reflog(struct ref_store *ref_store,
3113
3114 static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
3115 {
3116 - unsigned char osha1[20], nsha1[20];
3116 + struct object_id ooid, noid;
3117 char *email_end, *message;
3118 unsigned long timestamp;
3119 int tz;
3120
3121 /* old SP new SP name <email> SP time TAB msg LF */
3122 if (sb->len < 83 || sb->buf[sb->len - 1] != '\n' ||
3123 - get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' ||
3124 - get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' ||
3123 + get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||
3124 + get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||
3125 !(email_end = strchr(sb->buf + 82, '>')) ||
3126 email_end[1] != ' ' ||
3127 !(timestamp = strtoul(email_end + 2, &message, 10)) ||
@@ -3136,7 +3136,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
3136 message += 6;
3137 else
3138 message += 7;
3139 - return fn(osha1, nsha1, sb->buf + 82, timestamp, tz, message, cb_data);
3139 + return fn(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);
3140 }
3141
3142 static char *find_beginning_of_line(char *bob, char *scan)
@@ -3936,10 +3936,10 @@ struct expire_reflog_cb {
3936 reflog_expiry_should_prune_fn *should_prune_fn;
3937 void *policy_cb;
3938 FILE *newlog;
3939 - unsigned char last_kept_sha1[20];
3939 + struct object_id last_kept_oid;
3940 };
3941
3942 -static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
3942 +static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
3943 const char *email, unsigned long timestamp, int tz,
3944 const char *message, void *cb_data)
3945 {
@@ -3947,9 +3947,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
3947 struct expire_reflog_policy_cb *policy_cb = cb->policy_cb;
3948
3949 if (cb->flags & EXPIRE_REFLOGS_REWRITE)
3950 - osha1 = cb->last_kept_sha1;
3950 + ooid = &cb->last_kept_oid;
3951
3952 - if ((*cb->should_prune_fn)(osha1, nsha1, email, timestamp, tz,
3952 + if ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz,
3953 message, policy_cb)) {
3954 if (!cb->newlog)
3955 printf("would prune %s", message);
@@ -3958,9 +3958,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
3958 } else {
3959 if (cb->newlog) {
3960 fprintf(cb->newlog, "%s %s %s %lu %+05d\t%s",
3961 - sha1_to_hex(osha1), sha1_to_hex(nsha1),
3961 + oid_to_hex(ooid), oid_to_hex(noid),
3962 email, timestamp, tz, message);
3963 - hashcpy(cb->last_kept_sha1, nsha1);
3963 + oidcpy(&cb->last_kept_oid, noid);
3964 }
3965 if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
3966 printf("keep %s", message);
@@ -4047,14 +4047,14 @@ static int files_reflog_expire(struct ref_store *ref_store,
4047 */
4048 int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
4049 !(type & REF_ISSYMREF) &&
4050 - !is_null_sha1(cb.last_kept_sha1);
4050 + !is_null_oid(&cb.last_kept_oid);
4051
4052 if (close_lock_file(&reflog_lock)) {
4053 status |= error("couldn't write %s: %s", log_file,
4054 strerror(errno));
4055 } else if (update &&
4056 (write_in_full(get_lock_file_fd(lock->lk),
4057 - sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
4057 + oid_to_hex(&cb.last_kept_oid), GIT_SHA1_HEXSZ) != GIT_SHA1_HEXSZ ||
4058 write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 ||
4059 close_ref(lock) < 0)) {
4060 status |= error("couldn't write %s",
revision.c
+6 -6
@@ -1196,11 +1196,11 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f
1196 for_each(submodule, handle_one_ref, &cb);
1197 }
1198
1199 -static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
1199 +static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
1200 {
1201 struct all_refs_cb *cb = cb_data;
1202 - if (!is_null_sha1(sha1)) {
1203 - struct object *o = parse_object(sha1);
1202 + if (!is_null_oid(oid)) {
1203 + struct object *o = parse_object(oid->hash);
1204 if (o) {
1205 o->flags |= cb->all_flags;
1206 /* ??? CMDLINEFLAGS ??? */
@@ -1214,12 +1214,12 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
1214 }
1215 }
1216
1217 -static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
1217 +static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
1218 const char *email, unsigned long timestamp, int tz,
1219 const char *message, void *cb_data)
1220 {
1221 - handle_one_reflog_commit(osha1, cb_data);
1222 - handle_one_reflog_commit(nsha1, cb_data);
1221 + handle_one_reflog_commit(ooid, cb_data);
1222 + handle_one_reflog_commit(noid, cb_data);
1223 return 0;
1224 }
1225
sha1_name.c
+1 -1
@@ -1051,7 +1051,7 @@ struct grab_nth_branch_switch_cbdata {
1051 struct strbuf buf;
1052 };
1053
1054 -static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
1054 +static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid,
1055 const char *email, unsigned long timestamp, int tz,
1056 const char *message, void *cb_data)
1057 {
wt-status.c
+3 -3
@@ -1373,7 +1373,7 @@ struct grab_1st_switch_cbdata {
1373 unsigned char nsha1[20];
1374 };
1375
1376 -static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1376 +static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
1377 const char *email, unsigned long timestamp, int tz,
1378 const char *message, void *cb_data)
1379 {
@@ -1387,13 +1387,13 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1387 return 0;
1388 target += strlen(" to ");
1389 strbuf_reset(&cb->buf);
1390 - hashcpy(cb->nsha1, nsha1);
1390 + hashcpy(cb->nsha1, noid->hash);
1391 end = strchrnul(target, '\n');
1392 strbuf_add(&cb->buf, target, end - target);
1393 if (!strcmp(cb->buf.buf, "HEAD")) {
1394 /* HEAD is relative. Resolve it to the right reflog entry. */
1395 strbuf_reset(&cb->buf);
1396 - strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);
1396 + strbuf_add_unique_abbrev(&cb->buf, noid->hash, DEFAULT_ABBREV);
1397 }
1398 return 1;
1399 }