typedef int each_ref_entry_fn(struct ref_entry *entry, void *cb_data);
struct ref_entry_cb {
- const char *base;
+ const char *prefix;
int trim;
int flags;
each_ref_fn *fn;
struct ref_entry *old_current_ref;
int retval;
- if (!starts_with(entry->name, data->base))
+ if (!starts_with(entry->name, data->prefix))
return 0;
if (!(data->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
/*
* Call fn for each reference in the specified ref_cache, omitting
- * references not in the containing_dir of base. fn is called for all
- * references, including broken ones. If fn ever returns a non-zero
+ * references not in the containing_dir of prefix. Call fn for all
+ * references, including broken ones. If fn ever returns a non-zero
* value, stop the iteration and return that value; otherwise, return
* 0.
*/
-static int do_for_each_entry(struct ref_cache *refs, const char *base,
+static int do_for_each_entry(struct ref_cache *refs, const char *prefix,
each_ref_entry_fn fn, void *cb_data)
{
struct packed_ref_cache *packed_ref_cache;
* disk.
*/
loose_dir = get_loose_refs(refs);
- if (base && *base) {
- loose_dir = find_containing_dir(loose_dir, base, 0);
+ if (prefix && *prefix) {
+ loose_dir = find_containing_dir(loose_dir, prefix, 0);
}
if (loose_dir)
prime_ref_dir(loose_dir);
packed_ref_cache = get_packed_ref_cache(refs);
acquire_packed_ref_cache(packed_ref_cache);
packed_dir = get_packed_ref_dir(packed_ref_cache);
- if (base && *base) {
- packed_dir = find_containing_dir(packed_dir, base, 0);
+ if (prefix && *prefix) {
+ packed_dir = find_containing_dir(packed_dir, prefix, 0);
}
if (packed_dir && loose_dir) {
return retval;
}
-/*
- * Call fn for each reference in the specified ref_cache for which the
- * refname begins with base. If trim is non-zero, then trim that many
- * characters off the beginning of each refname before passing the
- * refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to include
- * broken references in the iteration. If fn ever returns a non-zero
- * value, stop the iteration and return that value; otherwise, return
- * 0.
- */
-int do_for_each_ref(const char *submodule, const char *base,
+int do_for_each_ref(const char *submodule, const char *prefix,
each_ref_fn fn, int trim, int flags, void *cb_data)
{
struct ref_entry_cb data;
struct ref_cache *refs;
refs = get_ref_cache(submodule);
- data.base = base;
+ data.prefix = prefix;
data.trim = trim;
data.flags = flags;
data.fn = fn;
if (ref_paranoia)
data.flags |= DO_FOR_EACH_INCLUDE_BROKEN;
- return do_for_each_entry(refs, base, do_one_ref, &data);
+ return do_for_each_entry(refs, prefix, do_one_ref, &data);
}
/*
return 0;
}
-int delete_refs(struct string_list *refnames)
+int delete_refs(struct string_list *refnames, unsigned int flags)
{
struct strbuf err = STRBUF_INIT;
int i, result = 0;
for (i = 0; i < refnames->nr; i++) {
const char *refname = refnames->items[i].string;
- if (delete_ref(refname, NULL, 0))
+ if (delete_ref(refname, NULL, flags))
result |= error(_("could not remove reference %s"), refname);
}