for-each-reflog: fix case for empty log directory
When we remove the last reflog in a directory, opendir() would succeed and we would iterate over its dirents, expecting retval to be initialized to zero and setting it to non-zero only upon seeing an error. If the directory is empty, oops!, we do not have anybody that touches retval. The problem is because we initialize retval to errno even on success from opendir(), which would leave the errno unmolested. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 7, 2007 at 09:18 UTC
fcee5a145d5a9e27afa8086c54e8f718a4a8f1cc
1 file changed
+3
-1
refs.c
+3
-1
@@ -1206,7 +1206,7 @@ int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1206
static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
1207
{
1208
DIR *dir = opendir(git_path("logs/%s", base));
1209
- int retval = errno;
1209
+ int retval = 0;
1210
1211
if (dir) {
1212
struct dirent *de;
@@ -1246,6 +1246,8 @@ static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
1246
free(log);
1247
closedir(dir);
1248
}
1249
+ else
1250
+ return errno;
1251
return retval;
1252
}
1253