refs: manage current_ref within do_one_ref()
Set and clear current_ref within do_one_ref() instead of setting it here and leaving it to somebody else to clear it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 10, 2012 at 07:30 UTC
429213e47039e6c60dd7ffcf4b32bf5bb3515690
1 file changed
+7
-6
refs.c
+7
-6
@@ -250,6 +250,7 @@ static struct ref_entry *current_ref;
250
static int do_one_ref(const char *base, each_ref_fn fn, int trim,
251
int flags, void *cb_data, struct ref_entry *entry)
252
{
253
+ int retval;
254
if (prefixcmp(entry->name, base))
255
return 0;
256
@@ -262,7 +263,9 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
263
}
264
}
265
current_ref = entry;
265
- return fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
266
+ retval = fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
267
+ current_ref = NULL;
268
+ return retval;
269
}
270
271
/*
@@ -872,7 +875,7 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
875
}
876
retval = do_one_ref(base, fn, trim, flags, cb_data, entry);
877
if (retval)
875
- goto end_each;
878
+ return retval;
879
}
880
881
if (l < loose->nr) {
@@ -883,12 +886,10 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
886
for (; p < packed->nr; p++) {
887
retval = do_one_ref(base, fn, trim, flags, cb_data, packed->refs[p]);
888
if (retval)
886
- goto end_each;
889
+ return retval;
890
}
891
889
-end_each:
890
- current_ref = NULL;
891
- return retval;
892
+ return 0;
893
}
894
895
static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)