* [PATCH] do_for_each_ref: perform the same sanity check for leftovers.
@ 2006-11-19 6:13 Junio C Hamano
2006-11-19 6:19 ` Shawn Pearce
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2006-11-19 6:13 UTC (permalink / raw)
To: git; +Cc: Linus Torvalds
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>
---
* "pickaxe -L'/^static int do_for_each_ref/,+40' refs.c" turns
out to be a very handy way to find out why a line I am
interested in is in that shape.
But it might be even better if it allowed us to say
'-L/^static int do_for_each_ref/+20,+20'.
diff --git a/refs.c b/refs.c
index f003a0b..6abd12f 100644
--- a/refs.c
+++ b/refs.c
@@ -322,6 +322,20 @@ int read_ref(const char *ref, unsigned c
return -1;
}
+static inline 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)
{
@@ -343,29 +357,15 @@ static int do_for_each_ref(const char *b
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;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] do_for_each_ref: perform the same sanity check for leftovers.
2006-11-19 6:13 [PATCH] do_for_each_ref: perform the same sanity check for leftovers Junio C Hamano
@ 2006-11-19 6:19 ` Shawn Pearce
2006-11-19 6:22 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Shawn Pearce @ 2006-11-19 6:19 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Linus Torvalds
Junio C Hamano <junkio@cox•net> wrote:
> * "pickaxe -L'/^static int do_for_each_ref/,+40' refs.c" turns
What's this pickaxe you speak of? Last I read you deleted it when
you renamed git-pickaxe to git-blame.
Have you reinvented git-pickaxe so soon? Maybe we could try using
git-longblade next time a new comamnd is being developed? :-)
--
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] do_for_each_ref: perform the same sanity check for leftovers.
2006-11-19 6:19 ` Shawn Pearce
@ 2006-11-19 6:22 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2006-11-19 6:22 UTC (permalink / raw)
To: Shawn Pearce; +Cc: git
Shawn Pearce <spearce@spearce•org> writes:
> Junio C Hamano <junkio@cox•net> wrote:
>> * "pickaxe -L'/^static int do_for_each_ref/,+40' refs.c" turns
>
> What's this pickaxe you speak of? Last I read you deleted it when
> you renamed git-pickaxe to git-blame.
>
> Have you reinvented git-pickaxe so soon? Maybe we could try using
> git-longblade next time a new comamnd is being developed? :-)
Oh, no, I meant "blame".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-11-19 6:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-19 6:13 [PATCH] do_for_each_ref: perform the same sanity check for leftovers Junio C Hamano
2006-11-19 6:19 ` Shawn Pearce
2006-11-19 6:22 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox