fsck: change functions to use object_id
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
May 25, 2015 at 18:38 UTC
635b99a0c715c87fe535b9174a453c2deec4566f
1 file changed
+13
-16
builtin/fsck.c
+13
-16
@@ -25,7 +25,7 @@ static int include_reflogs = 1;
25
static int check_full = 1;
26
static int check_strict;
27
static int keep_cache_objects;
28
-static unsigned char head_sha1[20];
28
+static struct object_id head_oid;
29
static const char *head_points_at;
30
static int errors_found;
31
static int write_lost_and_found;
@@ -476,19 +476,21 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
476
return 0;
477
}
478
479
-static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
479
+static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
480
+ int flag, void *cb_data)
481
{
482
for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
483
return 0;
484
}
485
485
-static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
486
+static int fsck_handle_ref(const char *refname, const struct object_id *oid,
487
+ int flag, void *cb_data)
488
{
489
struct object *obj;
490
489
- obj = parse_object(sha1);
491
+ obj = parse_object(oid->hash);
492
if (!obj) {
491
- error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
493
+ error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
494
errors_found |= ERROR_REACHABLE;
495
/* We'll continue with the rest despite the error.. */
496
return 0;
@@ -504,16 +506,11 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
506
507
static void get_default_heads(void)
508
{
507
- struct each_ref_fn_sha1_adapter wrapped_fsck_handle_ref =
508
- {fsck_handle_ref, NULL};
509
- struct each_ref_fn_sha1_adapter wrapped_fsck_handle_reflog =
510
- {fsck_handle_reflog, NULL};
511
-
512
- if (head_points_at && !is_null_sha1(head_sha1))
513
- fsck_handle_ref("HEAD", head_sha1, 0, NULL);
514
- for_each_rawref(each_ref_fn_adapter, &wrapped_fsck_handle_ref);
509
+ if (head_points_at && !is_null_oid(&head_oid))
510
+ fsck_handle_ref("HEAD", &head_oid, 0, NULL);
511
+ for_each_rawref(fsck_handle_ref, NULL);
512
if (include_reflogs)
516
- for_each_reflog(each_ref_fn_adapter, &wrapped_fsck_handle_reflog);
513
+ for_each_reflog(fsck_handle_reflog, NULL);
514
515
/*
516
* Not having any default heads isn't really fatal, but
@@ -561,7 +558,7 @@ static int fsck_head_link(void)
558
if (verbose)
559
fprintf(stderr, "Checking HEAD link\n");
560
564
- head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag);
561
+ head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, &flag);
562
if (!head_points_at)
563
return error("Invalid HEAD");
564
if (!strcmp(head_points_at, "HEAD"))
@@ -570,7 +567,7 @@ static int fsck_head_link(void)
567
else if (!starts_with(head_points_at, "refs/heads/"))
568
return error("HEAD points to something strange (%s)",
569
head_points_at);
573
- if (is_null_sha1(head_sha1)) {
570
+ if (is_null_oid(&head_oid)) {
571
if (null_is_error)
572
return error("HEAD: detached HEAD points at nothing");
573
fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",