Skip to content

Commit fe63c4d

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: introduce objectname_atom_parser()
Introduce objectname_atom_parser() which will parse the '%(objectname)' atom and store information into the 'used_atom' structure based on the modifiers used along with the atom. Helped-by: Ramsay Jones <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 452db39 commit fe63c4d

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

ref-filter.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static struct used_atom {
4343
enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB } option;
4444
unsigned int nlines;
4545
} contents;
46+
enum { O_FULL, O_SHORT } objectname;
4647
} u;
4748
} *used_atom;
4849
static int used_atom_cnt, need_tagged, need_symref;
@@ -102,6 +103,16 @@ static void contents_atom_parser(struct used_atom *atom, const char *arg)
102103
die(_("unrecognized %%(contents) argument: %s"), arg);
103104
}
104105

106+
static void objectname_atom_parser(struct used_atom *atom, const char *arg)
107+
{
108+
if (!arg)
109+
atom->u.objectname = O_FULL;
110+
else if (!strcmp(arg, "short"))
111+
atom->u.objectname = O_SHORT;
112+
else
113+
die(_("unrecognized %%(objectname) argument: %s"), arg);
114+
}
115+
105116
static align_type parse_align_position(const char *s)
106117
{
107118
if (!strcmp(s, "right"))
@@ -160,7 +171,7 @@ static struct {
160171
{ "refname" },
161172
{ "objecttype" },
162173
{ "objectsize", FIELD_ULONG },
163-
{ "objectname" },
174+
{ "objectname", FIELD_STR, objectname_atom_parser },
164175
{ "tree" },
165176
{ "parent" },
166177
{ "numparent", FIELD_ULONG },
@@ -440,15 +451,17 @@ static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned lo
440451
}
441452

442453
static int grab_objectname(const char *name, const unsigned char *sha1,
443-
struct atom_value *v)
454+
struct atom_value *v, struct used_atom *atom)
444455
{
445-
if (!strcmp(name, "objectname")) {
446-
v->s = xstrdup(sha1_to_hex(sha1));
447-
return 1;
448-
}
449-
if (!strcmp(name, "objectname:short")) {
450-
v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
451-
return 1;
456+
if (starts_with(name, "objectname")) {
457+
if (atom->u.objectname == O_SHORT) {
458+
v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
459+
return 1;
460+
} else if (atom->u.objectname == O_FULL) {
461+
v->s = xstrdup(sha1_to_hex(sha1));
462+
return 1;
463+
} else
464+
die("BUG: unknown %%(objectname) option");
452465
}
453466
return 0;
454467
}
@@ -472,7 +485,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
472485
v->s = xstrfmt("%lu", sz);
473486
}
474487
else if (deref)
475-
grab_objectname(name, obj->oid.hash, v);
488+
grab_objectname(name, obj->oid.hash, v, &used_atom[i]);
476489
}
477490
}
478491

@@ -996,7 +1009,7 @@ static void populate_value(struct ref_array_item *ref)
9961009
v->s = xstrdup(buf + 1);
9971010
}
9981011
continue;
999-
} else if (!deref && grab_objectname(name, ref->objectname, v)) {
1012+
} else if (!deref && grab_objectname(name, ref->objectname, v, atom)) {
10001013
continue;
10011014
} else if (!strcmp(name, "HEAD")) {
10021015
const char *head;

0 commit comments

Comments
 (0)