Skip to content

Commit ef06b91

Browse files
author
Junio C Hamano
committed
do_for_each_ref: perform the same sanity check for leftovers.
An earlier commit b37a562 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 <[email protected]>
1 parent 6c96c0f commit ef06b91

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

refs.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,20 @@ int read_ref(const char *ref, unsigned char *sha1)
322322
return -1;
323323
}
324324

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+
325339
static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
326340
void *cb_data)
327341
{
@@ -343,29 +357,15 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
343357
entry = packed;
344358
packed = packed->next;
345359
}
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);
356361
if (retval)
357362
return retval;
358363
}
359364

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;
369369
}
370370
return 0;
371371
}

0 commit comments

Comments
 (0)