do_for_each_reflog(): return early on error
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 25, 2012 at 00:45 UTC
93c603fcb7bfbe3d4bfb108463166b850de638f3
1 file changed
+35
-35
refs.c
+35
-35
@@ -2246,47 +2246,47 @@ static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
2246
{
2247
DIR *d = opendir(git_path("logs/%s", base));
2248
int retval = 0;
2249
+ struct dirent *de;
2250
+ int baselen;
2251
+ char *log;
2252
2250
- if (d) {
2251
- struct dirent *de;
2252
- int baselen = strlen(base);
2253
- char *log = xmalloc(baselen + 257);
2253
+ if (!d)
2254
+ return *base ? errno : 0;
2255
2255
- memcpy(log, base, baselen);
2256
- if (baselen && base[baselen-1] != '/')
2257
- log[baselen++] = '/';
2256
+ baselen = strlen(base);
2257
+ log = xmalloc(baselen + 257);
2258
+ memcpy(log, base, baselen);
2259
+ if (baselen && base[baselen-1] != '/')
2260
+ log[baselen++] = '/';
2261
2259
- while ((de = readdir(d)) != NULL) {
2260
- struct stat st;
2261
- int namelen;
2262
+ while ((de = readdir(d)) != NULL) {
2263
+ struct stat st;
2264
+ int namelen;
2265
2263
- if (de->d_name[0] == '.')
2264
- continue;
2265
- namelen = strlen(de->d_name);
2266
- if (namelen > 255)
2267
- continue;
2268
- if (has_extension(de->d_name, ".lock"))
2269
- continue;
2270
- memcpy(log + baselen, de->d_name, namelen+1);
2271
- if (stat(git_path("logs/%s", log), &st) < 0)
2272
- continue;
2273
- if (S_ISDIR(st.st_mode)) {
2274
- retval = do_for_each_reflog(log, fn, cb_data);
2275
- } else {
2276
- unsigned char sha1[20];
2277
- if (read_ref_full(log, sha1, 0, NULL))
2278
- retval = error("bad ref for %s", log);
2279
- else
2280
- retval = fn(log, sha1, 0, cb_data);
2281
- }
2282
- if (retval)
2283
- break;
2266
+ if (de->d_name[0] == '.')
2267
+ continue;
2268
+ namelen = strlen(de->d_name);
2269
+ if (namelen > 255)
2270
+ continue;
2271
+ if (has_extension(de->d_name, ".lock"))
2272
+ continue;
2273
+ memcpy(log + baselen, de->d_name, namelen+1);
2274
+ if (stat(git_path("logs/%s", log), &st) < 0)
2275
+ continue;
2276
+ if (S_ISDIR(st.st_mode)) {
2277
+ retval = do_for_each_reflog(log, fn, cb_data);
2278
+ } else {
2279
+ unsigned char sha1[20];
2280
+ if (read_ref_full(log, sha1, 0, NULL))
2281
+ retval = error("bad ref for %s", log);
2282
+ else
2283
+ retval = fn(log, sha1, 0, cb_data);
2284
}
2285
- free(log);
2286
- closedir(d);
2285
+ if (retval)
2286
+ break;
2287
}
2288
- else if (*base)
2289
- return errno;
2288
+ free(log);
2289
+ closedir(d);
2290
return retval;
2291
}
2292