Skip to content

Commit b180e6f

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: introduce refname_atom_parser_internal()
Since there are multiple atoms which print refs ('%(refname)', '%(symref)', '%(push)', '%(upstream)'), it makes sense to have a common ground for parsing them. This would allow us to share implementations of the atom modifiers between these atoms. Introduce refname_atom_parser_internal() to act as a common parsing function for ref printing atoms. This would eventually be used to introduce refname_atom_parser() and symref_atom_parser() and also be internally used in remote_ref_atom_parser(). Helped-by: Jeff King <peff@peff.net> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 01f9582 commit b180e6f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ref-filter.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct if_then_else {
3232
condition_satisfied : 1;
3333
};
3434

35+
struct refname_atom {
36+
enum { R_NORMAL, R_SHORT, R_STRIP } option;
37+
unsigned int strip;
38+
};
39+
3540
/*
3641
* An atom is a valid field atom listed below, possibly prefixed with
3742
* a "*" to denote deref_tag().
@@ -64,6 +69,7 @@ static struct used_atom {
6469
enum { O_FULL, O_LENGTH, O_SHORT } option;
6570
unsigned int length;
6671
} objectname;
72+
struct refname_atom refname;
6773
} u;
6874
} *used_atom;
6975
static int used_atom_cnt, need_tagged, need_symref;
@@ -77,6 +83,21 @@ static void color_atom_parser(struct used_atom *atom, const char *color_value)
7783
die(_("unrecognized color: %%(color:%s)"), color_value);
7884
}
7985

86+
static void refname_atom_parser_internal(struct refname_atom *atom,
87+
const char *arg, const char *name)
88+
{
89+
if (!arg)
90+
atom->option = R_NORMAL;
91+
else if (!strcmp(arg, "short"))
92+
atom->option = R_SHORT;
93+
else if (skip_prefix(arg, "strip=", &arg)) {
94+
atom->option = R_STRIP;
95+
if (strtoul_ui(arg, 10, &atom->strip) || atom->strip <= 0)
96+
die(_("positive value expected refname:strip=%s"), arg);
97+
} else
98+
die(_("unrecognized %%(%s) argument: %s"), name, arg);
99+
}
100+
80101
static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
81102
{
82103
struct string_list params = STRING_LIST_INIT_DUP;

0 commit comments

Comments
 (0)