{"thread":{"id":"27712","subject":"[PATCH 1/3] fsck: minor typofix","startedAt":"2011-06-27T17:50:57Z","lastAt":"2011-06-27T17:50:59Z","messageCount":3,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"170578","messageId":"1309197059-7177-1-git-send-email-gitster@pobox.com","threadId":"27712","inReplyTo":null,"subject":"[PATCH 1/3] fsck: minor typofix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-27T17:50:57Z","receivedAt":"2011-06-27T17:50:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There are two places that diagnose the same kind of error in mark_object(),\nthat receives an object, the type the object is expected to be, and the\nobject that refers to it (IOW, the reason why we want to make sure that\nthe first object is in a good order). When the object that is referred to\nis missing, we report \"broken link from X; broken link to Y\".\n\nHowever, one of the two places, that is used much less often, said \"broken\nlink from X; broken link from Y\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n This rarely used codepath is triggered only when fsck_walk() calls this\n function that is set as a callback in traverse_one_object() from one of\n the type specific scanners, e.g. fsck_walk_tree(), and an object that is\n referred to is of a wrong type, e.g. a tree entry with mode 100644 is\n looked up with lookup_blob(), and the type of the named object is already\n known to us to be something different. The look-up code issues an unrelated\n error message in such a case, but then this codepath does not know what the\n object name of the offending object was.\n---\n builtin/fsck.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 5ae0366..64f30d4 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -83,7 +83,7 @@ static int mark_object(struct object *obj, int type, void *data)\n \t\t/* ... these references to parent->fld are safe here */\n \t\tprintf(\"broken link from %7s %s\\n\",\n \t\t\t   typename(parent->type), sha1_to_hex(parent->sha1));\n-\t\tprintf(\"broken link from %7s %s\\n\",\n+\t\tprintf(\"broken link to %7s %s\\n\",\n \t\t\t   (type == OBJ_ANY ? \"unknown\" : typename(type)), \"unknown\");\n \t\terrors_found |= ERROR_REACHABLE;\n \t\treturn 1;\n-- \n1.7.6\n"},{"id":"170579","messageId":"1309197059-7177-2-git-send-email-gitster@pobox.com","threadId":"27712","inReplyTo":"1309197059-7177-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/3] fsck: clarify semantics of mark_object_reachable()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-27T17:50:58Z","receivedAt":"2011-06-27T17:50:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Any object that is directly reachable from refs, in the index or in the\ncache tree, are obviously \"used\", and indeed all the existing callers of\nmark_object_reachable() function sets this bit.  Move the assignment from\nthe callers to this function.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fsck.c |   33 ++++++++-------------------------\n 1 files changed, 8 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 64f30d4..90f5c2c 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -113,7 +113,10 @@ static int mark_object(struct object *obj, int type, void *data)\n \n static void mark_object_reachable(struct object *obj)\n {\n-\tmark_object(obj, OBJ_ANY, NULL);\n+\tif (obj) {\n+\t\tobj->used = 1;\n+\t\tmark_object(obj, OBJ_ANY, NULL);\n+\t}\n }\n \n static int traverse_one_object(struct object *obj)\n@@ -435,24 +438,13 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\n-\tstruct object *obj;\n-\n \tif (verbose)\n \t\tfprintf(stderr, \"Checking reflog %s->%s\\n\",\n \t\t\tsha1_to_hex(osha1), sha1_to_hex(nsha1));\n \n-\tif (!is_null_sha1(osha1)) {\n-\t\tobj = lookup_object(osha1);\n-\t\tif (obj) {\n-\t\t\tobj->used = 1;\n-\t\t\tmark_object_reachable(obj);\n-\t\t}\n-\t}\n-\tobj = lookup_object(nsha1);\n-\tif (obj) {\n-\t\tobj->used = 1;\n-\t\tmark_object_reachable(obj);\n-\t}\n+\tif (!is_null_sha1(osha1))\n+\t\tmark_object_reachable(lookup_object(osha1));\n+\tmark_object_reachable(lookup_object(nsha1));\n \treturn 0;\n }\n \n@@ -480,7 +472,6 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f\n \tif (obj->type != OBJ_COMMIT && is_branch(refname))\n \t\terror(\"%s: not a commit\", refname);\n \tdefault_refs++;\n-\tobj->used = 1;\n \tmark_object_reachable(obj);\n \n \treturn 0;\n@@ -568,7 +559,6 @@ static int fsck_cache_tree(struct cache_tree *it)\n \t\t\t      sha1_to_hex(it->sha1));\n \t\t\treturn 1;\n \t\t}\n-\t\tobj->used = 1;\n \t\tmark_object_reachable(obj);\n \t\tif (obj->type != OBJ_TREE)\n \t\t\terr |= objerror(obj, \"non-tree in cache-tree\");\n@@ -647,12 +637,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tunsigned char sha1[20];\n \t\tif (!get_sha1(arg, sha1)) {\n \t\t\tstruct object *obj = lookup_object(sha1);\n-\n-\t\t\t/* Error is printed by lookup_object(). */\n \t\t\tif (!obj)\n \t\t\t\tcontinue;\n-\n-\t\t\tobj->used = 1;\n \t\t\tmark_object_reachable(obj);\n \t\t\theads++;\n \t\t\tcontinue;\n@@ -675,7 +661,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tunsigned int mode;\n \t\t\tstruct blob *blob;\n-\t\t\tstruct object *obj;\n \n \t\t\tmode = active_cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n@@ -683,9 +668,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tblob = lookup_blob(active_cache[i]->sha1);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n-\t\t\tobj = &blob->object;\n-\t\t\tobj->used = 1;\n-\t\t\tmark_object_reachable(obj);\n+\t\t\tmark_object_reachable(&blob->object);\n \t\t}\n \t\tif (active_cache_tree)\n \t\t\tfsck_cache_tree(active_cache_tree);\n-- \n1.7.6\n"},{"id":"170580","messageId":"1309197059-7177-3-git-send-email-gitster@pobox.com","threadId":"27712","inReplyTo":"1309197059-7177-1-git-send-email-gitster@pobox.com","subject":"[PATCH 3/3] object: reclaim one bit in the flags field","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-27T17:50:59Z","receivedAt":"2011-06-27T17:50:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The object layer has \"used\" bit in the structure that is only used while\nrunning fsck. Remove it, and instead use one bit from the flags to record\nthe fact that an object is referenced from some other object (only during\nfsck).\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fsck.c |    7 ++++---\n object.c       |    1 -\n object.h       |    3 +--\n 3 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 90f5c2c..dde0907 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -14,6 +14,7 @@\n \n #define REACHABLE 0x0001\n #define SEEN      0x0002\n+#define USED\t  0x0004\n \n static int show_root;\n static int show_tags;\n@@ -114,7 +115,7 @@ static int mark_object(struct object *obj, int type, void *data)\n static void mark_object_reachable(struct object *obj)\n {\n \tif (obj) {\n-\t\tobj->used = 1;\n+\t\tobj->flags |= USED;\n \t\tmark_object(obj, OBJ_ANY, NULL);\n \t}\n }\n@@ -156,7 +157,7 @@ static int mark_used(struct object *obj, int type, void *data)\n {\n \tif (!obj)\n \t\treturn 1;\n-\tobj->used = 1;\n+\tobj->flags |= USED;\n \treturn 0;\n }\n \n@@ -214,7 +215,7 @@ static void check_unreachable_object(struct object *obj)\n \t * deleted a branch by mistake, this is a prime candidate to\n \t * start looking at, for example.\n \t */\n-\tif (!obj->used) {\n+\tif (!(obj->flags & USED)) {\n \t\tprintf(\"dangling %s %s\\n\", typename(obj->type),\n \t\t       sha1_to_hex(obj->sha1));\n \t\tif (write_lost_and_found) {\ndiff --git a/object.c b/object.c\nindex 31976b5..4a9d77f 100644\n--- a/object.c\n+++ b/object.c\n@@ -111,7 +111,6 @@ void *create_object(const unsigned char *sha1, int type, void *o)\n \tstruct object *obj = o;\n \n \tobj->parsed = 0;\n-\tobj->used = 0;\n \tobj->type = type;\n \tobj->flags = 0;\n \thashcpy(obj->sha1, sha1);\ndiff --git a/object.h b/object.h\nindex b6618d9..dbfc88f 100644\n--- a/object.h\n+++ b/object.h\n@@ -19,14 +19,13 @@ struct object_array {\n #define OBJECT_ARRAY_INIT { 0, 0, NULL }\n \n #define TYPE_BITS   3\n-#define FLAG_BITS  27\n+#define FLAG_BITS  (31-TYPE_BITS)\n \n /*\n  * The object type is stored in 3 bits.\n  */\n struct object {\n \tunsigned parsed : 1;\n-\tunsigned used : 1;\n \tunsigned type : TYPE_BITS;\n \tunsigned flags : FLAG_BITS;\n \tunsigned char sha1[20];\n-- \n1.7.6\n"}]}