Skip to content

Commit

Permalink
Merge branch 'jk/for-each-ref-skip-parsing'
Browse files Browse the repository at this point in the history
* jk/for-each-ref-skip-parsing:
  for-each-ref: avoid loading objects to print %(objectname)
  • Loading branch information
Junio C Hamano committed Nov 1, 2013
2 parents 583736c + b74cf64 commit c167b76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 20 additions & 9 deletions builtin/for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned lo
return buf;
}

static int grab_objectname(const char *name, const unsigned char *sha1,
struct atom_value *v)
{
if (!strcmp(name, "objectname")) {
char *s = xmalloc(41);
strcpy(s, sha1_to_hex(sha1));
v->s = s;
return 1;
}
if (!strcmp(name, "objectname:short")) {
v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
return 1;
}
return 0;
}

/* See grab_values */
static void grab_common_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
{
Expand All @@ -225,15 +241,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
v->ul = sz;
v->s = s;
}
else if (!strcmp(name, "objectname")) {
char *s = xmalloc(41);
strcpy(s, sha1_to_hex(obj->sha1));
v->s = s;
}
else if (!strcmp(name, "objectname:short")) {
v->s = xstrdup(find_unique_abbrev(obj->sha1,
DEFAULT_ABBREV));
}
else if (deref)
grab_objectname(name, obj->sha1, v);
}
}

Expand Down Expand Up @@ -676,6 +685,8 @@ static void populate_value(struct refinfo *ref)
}
continue;
}
else if (!deref && grab_objectname(name, ref->objectname, v))
continue;
else
continue;

Expand Down
4 changes: 4 additions & 0 deletions t/t6300-for-each-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ test_atom head parent ''
test_atom head numparent 0
test_atom head object ''
test_atom head type ''
test_atom head '*objectname' ''
test_atom head '*objecttype' ''
test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
test_atom head authorname 'A U Thor'
test_atom head authoremail '<author@example.com>'
Expand Down Expand Up @@ -91,6 +93,8 @@ test_atom tag parent ''
test_atom tag numparent ''
test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
test_atom tag type 'commit'
test_atom tag '*objectname' '67a36f10722846e891fbada1ba48ed035de75581'
test_atom tag '*objecttype' 'commit'
test_atom tag author ''
test_atom tag authorname ''
test_atom tag authoremail ''
Expand Down

0 comments on commit c167b76

Please sign in to comment.