@matheusbsbs / matheus-bagliano / commits / ef06b91804
Fork 0

do_for_each_ref: perform the same sanity check for leftovers.

An earlier commit b37a562a added a check to see if the ref points at a valid object (as a part of 'negative ref' support which we currently do not use), but did so only while iterating over both packed and loose refs, and forgot to apply the same check while iterating over the remaining ones. We might want to replace the "if null then omit it" check with "eh --- what business does a 0{40} value have here?" complaint later since we currently do not use negative refs, but that is a separate issue. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 18, 2006 at 22:13 UTC ef06b91804ff5a626e265c6d9080bbc0e7924e88
1 file changed +19 -19
refs.c
+19 -19
@@ -322,6 +322,20 @@ int read_ref(const char *ref, unsigned char *sha1)
322 return -1;
323 }
324
325 +static int do_one_ref(const char *base, each_ref_fn fn, int trim,
326 + void *cb_data, struct ref_list *entry)
327 +{
328 + if (strncmp(base, entry->name, trim))
329 + return 0;
330 + if (is_null_sha1(entry->sha1))
331 + return 0;
332 + if (!has_sha1_file(entry->sha1)) {
333 + error("%s does not point to a valid object!", entry->name);
334 + return 0;
335 + }
336 + return fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
337 +}
338 +
339 static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
340 void *cb_data)
341 {
@@ -343,29 +357,15 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
357 entry = packed;
358 packed = packed->next;
359 }
346 - if (strncmp(base, entry->name, trim))
347 - continue;
348 - if (is_null_sha1(entry->sha1))
349 - continue;
350 - if (!has_sha1_file(entry->sha1)) {
351 - error("%s does not point to a valid object!", entry->name);
352 - continue;
353 - }
354 - retval = fn(entry->name + trim, entry->sha1,
355 - entry->flag, cb_data);
360 + retval = do_one_ref(base, fn, trim, cb_data, entry);
361 if (retval)
362 return retval;
363 }
364
360 - packed = packed ? packed : loose;
361 - while (packed) {
362 - if (!strncmp(base, packed->name, trim)) {
363 - retval = fn(packed->name + trim, packed->sha1,
364 - packed->flag, cb_data);
365 - if (retval)
366 - return retval;
367 - }
368 - packed = packed->next;
365 + for (packed = packed ? packed : loose; packed; packed = packed->next) {
366 + retval = do_one_ref(base, fn, trim, cb_data, packed);
367 + if (retval)
368 + return retval;
369 }
370 return 0;
371 }