Skip to content

Commit

Permalink
do_for_each_ref: perform the same sanity check for leftovers.
Browse files Browse the repository at this point in the history
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 <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Nov 20, 2006
1 parent 6c96c0f commit ef06b91
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ int read_ref(const char *ref, unsigned char *sha1)
return -1;
}

static int do_one_ref(const char *base, each_ref_fn fn, int trim,
void *cb_data, struct ref_list *entry)
{
if (strncmp(base, entry->name, trim))
return 0;
if (is_null_sha1(entry->sha1))
return 0;
if (!has_sha1_file(entry->sha1)) {
error("%s does not point to a valid object!", entry->name);
return 0;
}
return fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
}

static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
void *cb_data)
{
Expand All @@ -343,29 +357,15 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
entry = packed;
packed = packed->next;
}
if (strncmp(base, entry->name, trim))
continue;
if (is_null_sha1(entry->sha1))
continue;
if (!has_sha1_file(entry->sha1)) {
error("%s does not point to a valid object!", entry->name);
continue;
}
retval = fn(entry->name + trim, entry->sha1,
entry->flag, cb_data);
retval = do_one_ref(base, fn, trim, cb_data, entry);
if (retval)
return retval;
}

packed = packed ? packed : loose;
while (packed) {
if (!strncmp(base, packed->name, trim)) {
retval = fn(packed->name + trim, packed->sha1,
packed->flag, cb_data);
if (retval)
return retval;
}
packed = packed->next;
for (packed = packed ? packed : loose; packed; packed = packed->next) {
retval = do_one_ref(base, fn, trim, cb_data, packed);
if (retval)
return retval;
}
return 0;
}
Expand Down

0 comments on commit ef06b91

Please sign in to comment.