From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Matthieu.Moy@grenoble-inp.fr,
Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v6 06/11] for-each-ref: rename some functions and make them public
Date: Sat, 6 Jun 2015 19:18:11 +0530 [thread overview]
Message-ID: <1433598496-31287-6-git-send-email-karthik.188@gmail.com> (raw)
In-Reply-To: <1433598496-31287-1-git-send-email-karthik.188@gmail.com>
Rename some of the functions and make them publicly available.
This is a preparatory step for moving code from 'for-each-ref'
to 'ref-filter' to make meaningful, targeted services available to
other commands via public APIs.
Functions renamed are:
parse_atom() -> parse_ref_filter_atom()
verify_format() -> verify_ref_format()
get_value() -> get_ref_atom_value()
grab_single_ref() -> ref_filter_handler()
sort_refs() -> ref_array_sort()
show_ref() -> show_ref_array_item()
default_sort() -> ref_default_sorting()
opt_parse_sort() -> parse_opt_ref_sorting()
cmp_ref_sort() -> cmp_ref_sorting()
Rename 'struct ref_sort' to 'struct ref_sorting' in this context.
Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
builtin/for-each-ref.c | 68 +++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index a65a4db..11552ad 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -25,8 +25,8 @@ struct atom_value {
unsigned long ul; /* used for sorting when not FIELD_STR */
};
-struct ref_sort {
- struct ref_sort *next;
+struct ref_sorting {
+ struct ref_sorting *next;
int atom; /* index into 'struct atom_value *' array */
unsigned reverse : 1;
};
@@ -113,7 +113,7 @@ static int need_color_reset_at_eol;
/*
* Used to parse format string and sort specifiers
*/
-static int parse_atom(const char *atom, const char *ep)
+int parse_ref_filter_atom(const char *atom, const char *ep)
{
const char *sp;
int i, at;
@@ -190,7 +190,7 @@ static const char *find_next(const char *cp)
* Make sure the format string is well formed, and parse out
* the used atoms.
*/
-static int verify_format(const char *format)
+int verify_ref_format(const char *format)
{
const char *cp, *sp;
@@ -202,7 +202,7 @@ static int verify_format(const char *format)
if (!ep)
return error("malformed format string %s", sp);
/* sp points at "%(" and ep points at the closing ")" */
- at = parse_atom(sp + 2, ep);
+ at = parse_ref_filter_atom(sp + 2, ep);
cp = ep + 1;
if (skip_prefix(used_atom[at], "color:", &color))
@@ -409,7 +409,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
/*
* We got here because atomname ends in "date" or "date<something>";
* it's not possible that <something> is not ":<format>" because
- * parse_atom() wouldn't have allowed it, so we can assume that no
+ * parse_ref_filter_atom() wouldn't have allowed it, so we can assume that no
* ":" means no format is specified, and use the default.
*/
formatp = strchr(atomname, ':');
@@ -849,7 +849,7 @@ static void populate_value(struct ref_array_item *ref)
* Given a ref, return the value for the atom. This lazily gets value
* out of the object by calling populate value.
*/
-static void get_value(struct ref_array_item *ref, int atom, struct atom_value **v)
+static void get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)
{
if (!ref->value) {
populate_value(ref);
@@ -899,8 +899,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
* A call-back given to for_each_ref(). Filter refs and keep them for
* later object processing.
*/
-static int grab_single_ref(const char *refname, const struct object_id *oid,
- int flag, void *cb_data)
+int ref_filter_handler(const char *refname, const struct object_id *oid, int flag, void *cb_data)
{
struct ref_filter_cbdata *ref_cbdata = cb_data;
struct ref_filter *filter = &ref_cbdata->filter;
@@ -946,14 +945,14 @@ void ref_array_clear(struct ref_array *array)
array->nr = array->alloc = 0;
}
-static int cmp_ref_sort(struct ref_sort *s, struct ref_array_item *a, struct ref_array_item *b)
+static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struct ref_array_item *b)
{
struct atom_value *va, *vb;
int cmp;
cmp_type cmp_type = used_atom_type[s->atom];
- get_value(a, s->atom, &va);
- get_value(b, s->atom, &vb);
+ get_ref_atom_value(a, s->atom, &va);
+ get_ref_atom_value(b, s->atom, &vb);
switch (cmp_type) {
case FIELD_STR:
cmp = strcmp(va->s, vb->s);
@@ -970,24 +969,24 @@ static int cmp_ref_sort(struct ref_sort *s, struct ref_array_item *a, struct ref
return (s->reverse) ? -cmp : cmp;
}
-static struct ref_sort *ref_sort;
+static struct ref_sorting *ref_sorting;
static int compare_refs(const void *a_, const void *b_)
{
struct ref_array_item *a = *((struct ref_array_item **)a_);
struct ref_array_item *b = *((struct ref_array_item **)b_);
- struct ref_sort *s;
+ struct ref_sorting *s;
- for (s = ref_sort; s; s = s->next) {
- int cmp = cmp_ref_sort(s, a, b);
+ for (s = ref_sorting; s; s = s->next) {
+ int cmp = cmp_ref_sorting(s, a, b);
if (cmp)
return cmp;
}
return 0;
}
-static void sort_refs(struct ref_sort *sort, struct ref_array *array)
+void ref_array_sort(struct ref_sorting *sort, struct ref_array *array)
{
- ref_sort = sort;
+ ref_sorting = sort;
qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs);
}
@@ -1055,7 +1054,7 @@ static void emit(const char *cp, const char *ep)
}
}
-static void show_ref(struct ref_array_item *info, const char *format, int quote_style)
+void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
{
const char *cp, *sp, *ep;
@@ -1065,7 +1064,7 @@ static void show_ref(struct ref_array_item *info, const char *format, int quote_
ep = strchr(sp, ')');
if (cp < sp)
emit(cp, sp);
- get_value(info, parse_atom(sp + 2, ep), &atomv);
+ get_ref_atom_value(info, parse_ref_filter_atom(sp + 2, ep), &atomv);
print_value(atomv, quote_style);
}
if (*cp) {
@@ -1084,21 +1083,22 @@ static void show_ref(struct ref_array_item *info, const char *format, int quote_
putchar('\n');
}
-static struct ref_sort *default_sort(void)
+/* If no sorting option is given, use refname to sort as default */
+struct ref_sorting *ref_default_sorting(void)
{
static const char cstr_name[] = "refname";
- struct ref_sort *sort = xcalloc(1, sizeof(*sort));
+ struct ref_sorting *sort = xcalloc(1, sizeof(*sort));
sort->next = NULL;
- sort->atom = parse_atom(cstr_name, cstr_name + strlen(cstr_name));
+ sort->atom = parse_ref_filter_atom(cstr_name, cstr_name + strlen(cstr_name));
return sort;
}
-static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
+int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
{
- struct ref_sort **sort_tail = opt->value;
- struct ref_sort *s;
+ struct ref_sorting **sort_tail = opt->value;
+ struct ref_sorting *s;
int len;
if (!arg) /* should --no-sort void the list ? */
@@ -1113,7 +1113,7 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
arg++;
}
len = strlen(arg);
- s->atom = parse_atom(arg, arg+len);
+ s->atom = parse_ref_filter_atom(arg, arg+len);
return 0;
}
@@ -1126,7 +1126,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
{
int i;
const char *format = "%(objectname) %(objecttype)\t%(refname)";
- struct ref_sort *sort = NULL, **sort_tail = &sort;
+ struct ref_sorting *sort = NULL, **sort_tail = &sort;
int maxcount = 0, quote_style = 0;
struct ref_filter_cbdata ref_cbdata;
@@ -1144,7 +1144,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")),
OPT_CALLBACK(0 , "sort", sort_tail, N_("key"),
- N_("field name to sort on"), &opt_parse_sort),
+ N_("field name to sort on"), &parse_opt_ref_sorting),
OPT_END(),
};
@@ -1157,25 +1157,25 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
error("more than one quoting style?");
usage_with_options(for_each_ref_usage, opts);
}
- if (verify_format(format))
+ if (verify_ref_format(format))
usage_with_options(for_each_ref_usage, opts);
if (!sort)
- sort = default_sort();
+ sort = ref_default_sorting();
/* for warn_ambiguous_refs */
git_config(git_default_config, NULL);
memset(&ref_cbdata, 0, sizeof(ref_cbdata));
ref_cbdata.filter.name_patterns = argv;
- for_each_rawref(grab_single_ref, &ref_cbdata);
+ for_each_rawref(ref_filter_handler, &ref_cbdata);
- sort_refs(sort, &ref_cbdata.array);
+ ref_array_sort(sort, &ref_cbdata.array);
if (!maxcount || ref_cbdata.array.nr < maxcount)
maxcount = ref_cbdata.array.nr;
for (i = 0; i < maxcount; i++)
- show_ref(ref_cbdata.array.items[i], format, quote_style);
+ show_ref_array_item(ref_cbdata.array.items[i], format, quote_style);
ref_array_clear(&ref_cbdata.array);
return 0;
}
--
2.4.2
next prev parent reply other threads:[~2015-06-06 13:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-06 13:43 [PATCH v6 0/11] create ref-filter from for-each-ref Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 01/11] for-each-ref: extract helper functions out of grab_single_ref() Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 02/11] for-each-ref: clean up code Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 03/11] for-each-ref: rename 'refinfo' to 'ref_array_item' Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 04/11] for-each-ref: introduce new structures for better organisation Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 05/11] for-each-ref: introduce 'ref_array_clear()' Karthik Nayak
2015-06-06 13:48 ` Karthik Nayak [this message]
2015-06-06 13:48 ` [PATCH v6 07/11] for-each-ref: rename variables called sort to sorting Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 08/11] ref-filter: add 'ref-filter.h' Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 09/11] ref-filter: move code from 'for-each-ref' Karthik Nayak
2015-06-07 10:34 ` Karthik Nayak
2015-06-08 17:08 ` Matthieu Moy
2015-06-08 17:13 ` Karthik Nayak
2015-06-08 18:08 ` Junio C Hamano
2015-06-06 13:48 ` [PATCH v6 10/11] for-each-ref: introduce filter_refs() Karthik Nayak
2015-06-07 10:36 ` Karthik Nayak
2015-06-08 18:15 ` Junio C Hamano
2015-06-08 18:37 ` Karthik Nayak
2015-06-06 13:48 ` [PATCH v6 11/11] ref-filter: make 'ref_array_item' use a FLEX_ARRAY for refname Karthik Nayak
2015-06-08 18:02 ` [PATCH v6 01/11] for-each-ref: extract helper functions out of grab_single_ref() Junio C Hamano
2015-06-08 18:33 ` Karthik Nayak
2015-06-07 12:03 ` [PATCH v6 0/11] create ref-filter from for-each-ref Karthik Nayak
2015-06-08 17:15 ` Matthieu Moy
2015-06-08 17:18 ` Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433598496-31287-6-git-send-email-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).