summaryrefslogtreecommitdiff
path: root/builtin-for-each-ref.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r--builtin-for-each-ref.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 91e8f95..a5a83f1 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -339,8 +339,11 @@ static const char *copy_name(const char *buf)
static const char *copy_email(const char *buf)
{
const char *email = strchr(buf, '<');
- const char *eoemail = strchr(email, '>');
- if (!email || !eoemail)
+ const char *eoemail;
+ if (!email)
+ return "";
+ eoemail = strchr(email, '>');
+ if (!eoemail)
return "";
return xmemdupz(email, eoemail + 1 - email);
}
@@ -558,14 +561,6 @@ static void populate_value(struct refinfo *ref)
ref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);
- buf = get_obj(ref->objectname, &obj, &size, &eaten);
- if (!buf)
- die("missing object %s for %s",
- sha1_to_hex(ref->objectname), ref->refname);
- if (!obj)
- die("parse_object_buffer failed on %s for %s",
- sha1_to_hex(ref->objectname), ref->refname);
-
/* Fill in specials first */
for (i = 0; i < used_atom_cnt; i++) {
const char *name = used_atom[i];
@@ -581,7 +576,7 @@ static void populate_value(struct refinfo *ref)
if (!prefixcmp(name, "refname"))
refname = ref->refname;
- else if(!prefixcmp(name, "upstream")) {
+ else if (!prefixcmp(name, "upstream")) {
struct branch *branch;
/* only local branches may have an upstream */
if (prefixcmp(ref->refname, "refs/heads/"))
@@ -618,6 +613,22 @@ static void populate_value(struct refinfo *ref)
}
}
+ for (i = 0; i < used_atom_cnt; i++) {
+ struct atom_value *v = &ref->value[i];
+ if (v->s == NULL)
+ goto need_obj;
+ }
+ return;
+
+ need_obj:
+ buf = get_obj(ref->objectname, &obj, &size, &eaten);
+ if (!buf)
+ die("missing object %s for %s",
+ sha1_to_hex(ref->objectname), ref->refname);
+ if (!obj)
+ die("parse_object_buffer failed on %s for %s",
+ sha1_to_hex(ref->objectname), ref->refname);
+
grab_values(ref->value, 0, obj, buf, size);
if (!eaten)
free(buf);
@@ -902,7 +913,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_END(),
};
- parse_options(argc, argv, opts, for_each_ref_usage, 0);
+ parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
if (maxcount < 0) {
error("invalid --count argument: `%d'", maxcount);
usage_with_options(for_each_ref_usage, opts);
@@ -923,7 +934,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
memset(&cbdata, 0, sizeof(cbdata));
cbdata.grab_pattern = argv;
- for_each_ref(grab_single_ref, &cbdata);
+ for_each_rawref(grab_single_ref, &cbdata);
refs = cbdata.grab_array;
num_refs = cbdata.grab_cnt;