-#include <sys/types.h>
-#include <dirent.h>
-
#include "cache.h"
#include "commit.h"
#include "tree.h"
static int default_refs;
-static int fsck_handle_ref(const char *refname, const unsigned char *sha1)
+static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *datail, void *cb_data)
+{
+ struct object *obj;
+
+ if (!is_null_sha1(osha1)) {
+ obj = lookup_object(osha1);
+ if (obj) {
+ obj->used = 1;
+ mark_reachable(obj, REACHABLE);
+ }
+ }
+ obj = lookup_object(nsha1);
+ if (obj) {
+ obj->used = 1;
+ mark_reachable(obj, REACHABLE);
+ }
+ return 0;
+}
+
+static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
struct object *obj;
default_refs++;
obj->used = 1;
mark_reachable(obj, REACHABLE);
+
+ for_each_reflog_ent(refname, fsck_handle_reflog_ent, NULL);
+
return 0;
}
static void get_default_heads(void)
{
- for_each_ref(fsck_handle_ref);
+ for_each_ref(fsck_handle_ref, NULL);
/*
* Not having any default heads isn't really fatal, but
static int fsck_head_link(void)
{
unsigned char sha1[20];
- const char *head_points_at = resolve_ref("HEAD", sha1, 1);
+ int flag;
+ const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag);
- if (!head_points_at)
+ if (!head_points_at || !(flag & REF_ISSYMREF))
return error("HEAD is not a symbolic ref");
if (strncmp(head_points_at, "refs/heads/", 11))
return error("HEAD points to something strange (%s)",