diff --git a/builtin-fsck.c b/builtin-fsck.c
index b8e71b640b66ebd95a436a5c1c7f3fce0647be0c..cbbcaf011a09d1dd9b3f2a01d18e1ab93e26fd3b 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
static int show_root;
static int show_tags;
static int show_unreachable;
static int show_root;
static int show_tags;
static int show_unreachable;
+static int include_reflogs = 1;
static int check_full;
static int check_strict;
static int keep_cache_objects;
static int check_full;
static int check_strict;
static int keep_cache_objects;
{
int retval;
int has_full_path = 0;
{
int retval;
int has_full_path = 0;
+ int has_empty_name = 0;
int has_zero_pad = 0;
int has_bad_modes = 0;
int has_dup_entries = 0;
int has_zero_pad = 0;
int has_bad_modes = 0;
int has_dup_entries = 0;
const char *o_name;
const unsigned char *o_sha1;
const char *o_name;
const unsigned char *o_sha1;
- desc.buf = item->buffer;
- desc.size = item->size;
+ init_tree_desc(&desc, item->buffer, item->size);
o_mode = 0;
o_name = NULL;
o_mode = 0;
o_name = NULL;
if (strchr(name, '/'))
has_full_path = 1;
if (strchr(name, '/'))
has_full_path = 1;
- has_zero_pad |= *(char *)desc.buf == '0';
+ if (!*name)
+ has_empty_name = 1;
+ has_zero_pad |= *(char *)desc.buffer == '0';
update_tree_entry(&desc);
switch (mode) {
update_tree_entry(&desc);
switch (mode) {
case S_IFREG | 0644:
case S_IFLNK:
case S_IFDIR:
case S_IFREG | 0644:
case S_IFLNK:
case S_IFDIR:
+ case S_IFGITLINK:
break;
/*
* This is nonstandard, but we had a few of these
break;
/*
* This is nonstandard, but we had a few of these
if (has_full_path) {
objwarning(&item->object, "contains full pathnames");
}
if (has_full_path) {
objwarning(&item->object, "contains full pathnames");
}
+ if (has_empty_name) {
+ objwarning(&item->object, "contains empty pathname");
+ }
if (has_zero_pad) {
objwarning(&item->object, "contains zero-padded file modes");
}
if (has_zero_pad) {
objwarning(&item->object, "contains zero-padded file modes");
}
return 0;
}
return 0;
}
-static int fsck_sha1(unsigned char *sha1)
+static int fsck_sha1(const unsigned char *sha1)
{
struct object *obj = parse_object(sha1);
if (!obj) {
{
struct object *obj = parse_object(sha1);
if (!obj) {
@@ -518,7 +525,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
static void get_default_heads(void)
{
for_each_ref(fsck_handle_ref, NULL);
static void get_default_heads(void)
{
for_each_ref(fsck_handle_ref, NULL);
- for_each_reflog(fsck_handle_reflog, NULL);
+ if (include_reflogs)
+ for_each_reflog(fsck_handle_reflog, NULL);
/*
* Not having any default heads isn't really fatal, but
/*
* Not having any default heads isn't really fatal, but
* "show_unreachable" flag.
*/
if (!default_refs) {
* "show_unreachable" flag.
*/
if (!default_refs) {
- error("No default references");
+ fprintf(stderr, "notice: No default references\n");
show_unreachable = 0;
}
}
show_unreachable = 0;
}
}
{
unsigned char sha1[20];
int flag;
{
unsigned char sha1[20];
int flag;
- const char *head_points_at = resolve_ref("HEAD", sha1, 1, &flag);
-
- if (!head_points_at || !(flag & REF_ISSYMREF))
- return error("HEAD is not a symbolic ref");
- if (prefixcmp(head_points_at, "refs/heads/"))
+ int null_is_error = 0;
+ const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
+
+ if (!head_points_at)
+ return error("Invalid HEAD");
+ if (!strcmp(head_points_at, "HEAD"))
+ /* detached HEAD */
+ null_is_error = 1;
+ else if (prefixcmp(head_points_at, "refs/heads/"))
return error("HEAD points to something strange (%s)",
head_points_at);
return error("HEAD points to something strange (%s)",
head_points_at);
- if (is_null_sha1(sha1))
- return error("HEAD: not a valid git pointer");
+ if (is_null_sha1(sha1)) {
+ if (null_is_error)
+ return error("HEAD: detached HEAD points at nothing");
+ fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
+ head_points_at + 11);
+ }
return 0;
}
return 0;
}
keep_cache_objects = 1;
continue;
}
keep_cache_objects = 1;
continue;
}
+ if (!strcmp(arg, "--no-reflogs")) {
+ include_reflogs = 0;
+ continue;
+ }
if (!strcmp(arg, "--full")) {
check_full = 1;
continue;
if (!strcmp(arg, "--full")) {
check_full = 1;
continue;
verify_pack(p, 0);
for (p = packed_git; p; p = p->next) {
verify_pack(p, 0);
for (p = packed_git; p; p = p->next) {
- uint32_t i, num = num_packed_objects(p);
- for (i = 0; i < num; i++) {
- unsigned char sha1[20];
- nth_packed_object_sha1(p, i, sha1);
- fsck_sha1(sha1);
- }
+ uint32_t i, num = p->num_objects;
+ for (i = 0; i < num; i++)
+ fsck_sha1(nth_packed_object_sha1(p, i));
}
}
}
}
int i;
read_cache();
for (i = 0; i < active_nr; i++) {
int i;
read_cache();
for (i = 0; i < active_nr; i++) {
- struct blob *blob = lookup_blob(active_cache[i]->sha1);
+ unsigned int mode;
+ struct blob *blob;
struct object *obj;
struct object *obj;
+
+ mode = ntohl(active_cache[i]->ce_mode);
+ if (S_ISGITLINK(mode))
+ continue;
+ blob = lookup_blob(active_cache[i]->sha1);
if (!blob)
continue;
obj = &blob->object;
if (!blob)
continue;
obj = &blob->object;