{"thread":{"id":"6724","subject":"[PATCH] for-each-reflog: fix case for empty log directory","startedAt":"2007-02-07T17:21:56Z","lastAt":"2007-02-07T17:21:56Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"33828","messageId":"7v4ppx993f.fsf@assigned-by-dhcp.cox.net","threadId":"6724","inReplyTo":null,"subject":"[PATCH] for-each-reflog: fix case for empty log directory","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-07T17:21:56Z","receivedAt":"2007-02-07T17:21:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When we remove the last reflog in a directory, opendir() would\nsucceed and we would iterate over its dirents, expecting retval\nto be initialized to zero and setting it to non-zero only upon\nseeing an error.  If the directory is empty, oops!, we do not\nhave anybody that touches retval.\n\nThe problem is because we initialize retval to errno even on\nsuccess from opendir(), which would leave the errno unmolested.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * This bug made \"git fsck --full\" in fully gc'ed repository to\n   report dangling commits because it did not fully walk the\n   reflogs.\n\n refs.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 03e8dfe..7e07fc4 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1206,7 +1206,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)\n static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)\n {\n \tDIR *dir = opendir(git_path(\"logs/%s\", base));\n-\tint retval = errno;\n+\tint retval = 0;\n \n \tif (dir) {\n \t\tstruct dirent *de;\n@@ -1246,6 +1246,8 @@ static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)\n \t\tfree(log);\n \t\tclosedir(dir);\n \t}\n+\telse\n+\t\treturn errno;\n \treturn retval;\n }\n \n-- \n1.5.0.rc3.185.g302d\n"}]}