summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlga Telezhnaya <olyatelezhnaya@gmail.com>2018-02-12 08:08:54 +0000
committerJunio C Hamano <gitster@pobox.com>2018-02-12 15:03:57 -0800
commit2fa6f42bca016d122f69374d7277dde063d57220 (patch)
tree887f97365cca9f99d8be773da8bd66c863bc8d0c
parentbb35d3ed533613d1a671c01cf788f29932ad2d0b (diff)
downloadgit-2fa6f42bca016d122f69374d7277dde063d57220.tar.gz
ref_filter: add is_atom_used function
Delete all items related to split_on_whitespace from ref-filter and add new function for handling the logic. Now cat-file could invoke that function to implementing its logic. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/cat-file.c8
-rw-r--r--ref-filter.c17
-rw-r--r--ref-filter.h10
3 files changed, 21 insertions, 14 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 6db57e3533..3a49b55a1c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -382,8 +382,7 @@ static int batch_objects(struct batch_options *opt)
{
struct strbuf buf = STRBUF_INIT;
struct expand_data data;
- int save_warning;
- int retval = 0;
+ int save_warning, is_rest, retval = 0;
if (!opt->format.format)
opt->format.format = "%(objectname) %(objecttype) %(objectsize)";
@@ -395,8 +394,6 @@ static int batch_objects(struct batch_options *opt)
memset(&data, 0, sizeof(data));
opt->format.cat_file_data = &data;
verify_ref_format(&opt->format);
- if (opt->cmdmode)
- data.split_on_whitespace = 1;
if (opt->all_objects) {
struct object_info empty = OBJECT_INFO_INIT;
@@ -435,9 +432,10 @@ static int batch_objects(struct batch_options *opt)
*/
save_warning = warn_on_object_refname_ambiguity;
warn_on_object_refname_ambiguity = 0;
+ is_rest = opt->cmdmode || is_atom_used(&opt->format, "rest");
while (strbuf_getline(&buf, stdin) != EOF) {
- if (data.split_on_whitespace) {
+ if (is_rest) {
/*
* Split at first whitespace, tying off the beginning
* of the string and saving the remainder (or NULL) in
diff --git a/ref-filter.c b/ref-filter.c
index 5d808a6010..8dbfdee4c7 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -493,8 +493,6 @@ static int parse_ref_filter_atom(const struct ref_format *format,
need_tagged = 1;
if (!strcmp(valid_atom[i].name, "symref"))
need_symref = 1;
- if (cat_file_info && !strcmp(valid_atom[i].name, "rest"))
- cat_file_info->split_on_whitespace = 1;
return at;
}
@@ -730,6 +728,21 @@ static const char *find_next(const char *cp)
return NULL;
}
+/* Search for atom in given format. */
+int is_atom_used(const struct ref_format *format, const char *atom)
+{
+ const char *cp, *sp;
+ for (cp = format->format; *cp && (sp = find_next(cp)); ) {
+ const char *ep = strchr(sp, ')');
+ int atom_len = ep - sp - 2;
+ sp += 2;
+ if (atom_len == strlen(atom) && !memcmp(sp, atom, atom_len))
+ return 1;
+ cp = ep + 1;
+ }
+ return 0;
+}
+
/*
* Make sure the format string is well formed, and parse out
* the used atoms.
diff --git a/ref-filter.h b/ref-filter.h
index 5c6e019998..fffc443726 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -87,13 +87,6 @@ struct expand_data {
struct object_id delta_base_oid;
/*
- * Whether to split the input on whitespace before feeding it to
- * get_sha1; this is decided during the mark_query phase based on
- * whether we have a %(rest) token in our format.
- */
- int split_on_whitespace;
-
- /*
* After a mark_query run, this object_info is set up to be
* passed to sha1_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
@@ -186,4 +179,7 @@ void pretty_print_ref(const char *name, const unsigned char *sha1,
/* Fill the values of request and prepare all data for final string creation */
int populate_value(struct ref_array_item *ref);
+/* Search for atom in given format. */
+int is_atom_used(const struct ref_format *format, const char *atom);
+
#endif /* REF_FILTER_H */