From: Matthew DeVore <matvore@google.com>
To: git@vger.kernel.org, jonathantanmy@google.com, jrn@google.com,
dstolee@microsoft.com, jeffhost@microsoft.com,
jrnieder@gmail.com, pclouds@gmail.com, emilyshaffer@google.com
Cc: Matthew DeVore <matvore@google.com>, matvore@comcast.net
Subject: [PATCH v2 6/9] list-objects-filter-options: make filter_spec a strbuf
Date: Fri, 31 May 2019 17:36:00 -0700 [thread overview]
Message-ID: <20190601003603.90794-7-matvore@google.com> (raw)
In-Reply-To: <20190601003603.90794-1-matvore@google.com>
Make the filter_spec string a strbuf rather than a raw C string. A
future patch will need to grow this string dynamically.
Signed-off-by: Matthew DeVore <matvore@google.com>
---
builtin/rev-list.c | 2 +-
list-objects-filter-options.c | 16 ++++++++++------
list-objects-filter-options.h | 2 +-
upload-pack.c | 2 +-
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 9f31837d30..7137f13a74 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -460,21 +460,21 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
continue;
}
if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
parse_list_objects_filter(&filter_options, arg);
if (filter_options.choice && !revs.blob_objects)
die(_("object filtering requires --objects"));
if (filter_options.choice == LOFC_SPARSE_OID &&
!filter_options.sparse_oid_value)
die(_("invalid sparse value '%s'"),
- filter_options.filter_spec);
+ filter_options.filter_spec.buf);
continue;
}
if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
list_objects_filter_set_no_filter(&filter_options);
continue;
}
if (!strcmp(arg, "--filter-print-omitted")) {
arg_print_omitted = 1;
continue;
}
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index e8132b811e..5687425847 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -203,21 +203,22 @@ cleanup:
}
return result;
}
int parse_list_objects_filter(struct list_objects_filter_options *filter_options,
const char *arg)
{
struct strbuf buf = STRBUF_INIT;
if (filter_options->choice)
die(_("multiple filter-specs cannot be combined"));
- filter_options->filter_spec = strdup(arg);
+ strbuf_init(&filter_options->filter_spec, 0);
+ strbuf_addstr(&filter_options->filter_spec, arg);
if (gently_parse_list_objects_filter(filter_options, arg, &buf))
die("%s", buf.buf);
return 0;
}
int opt_parse_list_objects_filter(const struct option *opt,
const char *arg, int unset)
{
struct list_objects_filter_options *filter_options = opt->value;
@@ -226,39 +227,39 @@ int opt_parse_list_objects_filter(const struct option *opt,
return 0;
}
return parse_list_objects_filter(filter_options, arg);
}
void expand_list_objects_filter_spec(
const struct list_objects_filter_options *filter,
struct strbuf *expanded_spec)
{
- strbuf_init(expanded_spec, strlen(filter->filter_spec));
+ strbuf_init(expanded_spec, 0);
if (filter->choice == LOFC_BLOB_LIMIT)
strbuf_addf(expanded_spec, "blob:limit=%lu",
filter->blob_limit_value);
else if (filter->choice == LOFC_TREE_DEPTH)
strbuf_addf(expanded_spec, "tree:%lu",
filter->tree_exclude_depth);
else
- strbuf_addstr(expanded_spec, filter->filter_spec);
+ strbuf_addstr(expanded_spec, filter->filter_spec.buf);
}
void list_objects_filter_release(
struct list_objects_filter_options *filter_options)
{
size_t sub;
if (!filter_options)
return;
- free(filter_options->filter_spec);
+ strbuf_release(&filter_options->filter_spec);
free(filter_options->sparse_oid_value);
free(filter_options->sparse_path_value);
for (sub = 0; sub < filter_options->sub_nr; sub++)
list_objects_filter_release(&filter_options->sub[sub]);
free(filter_options->sub);
memset(filter_options, 0, sizeof(*filter_options));
}
void partial_clone_register(
const char *remote,
@@ -278,32 +279,35 @@ void partial_clone_register(
git_config_set("core.repositoryformatversion", "1");
git_config_set("extensions.partialclone", remote);
repository_format_partial_clone = xstrdup(remote);
/*
* Record the initial filter-spec in the config as
* the default for subsequent fetches from this remote.
*/
core_partial_clone_filter_default =
- xstrdup(filter_options->filter_spec);
+ xstrdup(filter_options->filter_spec.buf);
git_config_set("core.partialclonefilter",
core_partial_clone_filter_default);
}
void partial_clone_get_default_filter_spec(
struct list_objects_filter_options *filter_options)
{
struct strbuf errbuf = STRBUF_INIT;
/*
* Parse default value, but silently ignore it if it is invalid.
*/
if (!core_partial_clone_filter_default)
return;
- filter_options->filter_spec = strdup(core_partial_clone_filter_default);
+ if (!filter_options->filter_spec.buf)
+ strbuf_init(&filter_options->filter_spec, 0);
+ strbuf_addstr(&filter_options->filter_spec,
+ core_partial_clone_filter_default);
gently_parse_list_objects_filter(filter_options,
core_partial_clone_filter_default,
&errbuf);
strbuf_release(&errbuf);
}
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index 8f08ed74a1..e1e23fd191 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -19,21 +19,21 @@ enum list_objects_filter_choice {
};
struct list_objects_filter_options {
/*
* 'filter_spec' is the raw argument value given on the command line
* or protocol request. (The part after the "--keyword=".) For
* commands that launch filtering sub-processes, or for communication
* over the network, don't use this value; use the result of
* expand_list_objects_filter_spec() instead.
*/
- char *filter_spec;
+ struct strbuf filter_spec;
/*
* 'choice' is determined by parsing the filter-spec. This indicates
* the filtering algorithm to use.
*/
enum list_objects_filter_choice choice;
/*
* Choice is LOFC_DISABLED because "--no-filter" was requested.
*/
diff --git a/upload-pack.c b/upload-pack.c
index d2ea5eb20d..2cdd499f28 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -133,21 +133,21 @@ static void create_pack_file(const struct object_array *have_obj,
argv_array_push(&pack_objects.args, "--stdout");
if (shallow_nr)
argv_array_push(&pack_objects.args, "--shallow");
if (!no_progress)
argv_array_push(&pack_objects.args, "--progress");
if (use_ofs_delta)
argv_array_push(&pack_objects.args, "--delta-base-offset");
if (use_include_tag)
argv_array_push(&pack_objects.args, "--include-tag");
- if (filter_options.filter_spec) {
+ if (filter_options.filter_spec.len) {
struct strbuf expanded_filter_spec = STRBUF_INIT;
expand_list_objects_filter_spec(&filter_options,
&expanded_filter_spec);
if (pack_objects.use_shell) {
struct strbuf buf = STRBUF_INIT;
sq_quote_buf(&buf, expanded_filter_spec.buf);
argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf);
strbuf_release(&buf);
} else {
argv_array_pushf(&pack_objects.args, "--filter=%s",
--
2.17.1
next prev parent reply other threads:[~2019-06-01 0:36 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-01 0:35 [PATCH v2 0/9] Filter combination Matthew DeVore
2019-06-01 0:35 ` [PATCH v2 1/9] list-objects-filter: make API easier to use Matthew DeVore
2019-06-01 0:35 ` [PATCH v2 2/9] list-objects-filter: put omits set in filter struct Matthew DeVore
2019-06-01 0:35 ` [PATCH v2 3/9] list-objects-filter-options: always supply *errbuf Matthew DeVore
2019-06-01 0:35 ` [PATCH v2 4/9] list-objects-filter: implement composite filters Matthew DeVore
2019-06-03 21:51 ` Jeff Hostetler
2019-06-06 22:32 ` Matthew DeVore
2019-06-07 17:58 ` Jeff Hostetler
2019-06-01 0:35 ` [PATCH v2 5/9] list-objects-filter-options: move error check up Matthew DeVore
2019-06-01 0:36 ` Matthew DeVore [this message]
2019-06-10 20:13 ` [PATCH v2 6/9] list-objects-filter-options: make filter_spec a strbuf Junio C Hamano
2019-06-11 0:34 ` Matthew DeVore
2019-06-11 17:33 ` Junio C Hamano
2019-06-11 18:44 ` Matthew DeVore
2019-06-11 21:34 ` Matthew DeVore
2019-06-11 21:48 ` Junio C Hamano
2019-06-12 0:37 ` Matthew DeVore
2019-06-12 14:55 ` Matthew DeVore
2019-06-01 0:36 ` [PATCH v2 7/9] list-objects-filter-options: allow mult. --filter Matthew DeVore
2019-06-01 0:36 ` [PATCH v2 8/9] list-objects-filter-options: clean up use of ALLOC_GROW Matthew DeVore
2019-06-03 22:07 ` Jacob Keller
2019-06-03 22:39 ` Matthew DeVore
2019-06-04 3:16 ` Jacob Keller
2019-06-01 0:36 ` [PATCH v2 9/9] list-objects-filter-options: make parser void Matthew DeVore
2019-06-03 21:35 ` [PATCH v2 0/9] Filter combination Jeff Hostetler
2019-06-13 21:51 ` [PATCH v3 00/10] " Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 01/10] list-objects-filter: make API easier to use Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 02/10] list-objects-filter: put omits set in filter struct Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 03/10] list-objects-filter-options: always supply *errbuf Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 04/10] list-objects-filter: implement composite filters Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 05/10] list-objects-filter-options: move error check up Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 06/10] list-objects-filter-options: make filter_spec a string_list Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 07/10] strbuf: give URL-encoding API a char predicate fn Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 08/10] list-objects-filter-options: allow mult. --filter Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 09/10] list-objects-filter-options: clean up use of ALLOC_GROW Matthew DeVore
2019-06-13 21:51 ` [PATCH v3 10/10] list-objects-filter-options: make parser void Matthew DeVore
2019-06-14 19:50 ` [PATCH v3 00/10] Filter combination Junio C Hamano
2019-06-15 0:40 ` [PATCH v4 " Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 01/10] list-objects-filter: make API easier to use Matthew DeVore
2019-06-21 22:58 ` Jonathan Tan
2019-06-27 0:46 ` Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 02/10] list-objects-filter: put omits set in filter struct Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 03/10] list-objects-filter-options: always supply *errbuf Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 04/10] list-objects-filter: implement composite filters Matthew DeVore
2019-06-18 8:42 ` Johannes Schindelin
2019-06-18 20:22 ` Matthew DeVore
2019-06-21 18:17 ` Johannes Schindelin
2019-06-22 0:26 ` Jonathan Tan
2019-06-27 21:12 ` Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 05/10] list-objects-filter-options: move error check up Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 06/10] list-objects-filter-options: make filter_spec a string_list Matthew DeVore
2019-06-22 0:37 ` Jonathan Tan
2019-06-27 21:17 ` Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 07/10] strbuf: give URL-encoding API a char predicate fn Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 08/10] list-objects-filter-options: allow mult. --filter Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 09/10] list-objects-filter-options: clean up use of ALLOC_GROW Matthew DeVore
2019-06-15 0:40 ` [PATCH v4 10/10] list-objects-filter-options: make parser void Matthew DeVore
2019-06-22 0:46 ` Jonathan Tan
2019-06-27 21:24 ` Matthew DeVore
2019-06-27 22:27 ` Matthew DeVore
2019-06-18 1:25 ` [PATCH v4 00/10] Filter combination Junio C Hamano
2019-06-27 22:54 ` [PATCH v5 " Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 01/10] list-objects-filter: encapsulate filter components Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 02/10] list-objects-filter: put omits set in filter struct Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 03/10] list-objects-filter-options: always supply *errbuf Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 04/10] list-objects-filter: implement composite filters Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 05/10] list-objects-filter-options: move error check up Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 06/10] list-objects-filter-options: make filter_spec a string_list Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 07/10] strbuf: give URL-encoding API a char predicate fn Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 08/10] list-objects-filter-options: allow mult. --filter Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 09/10] list-objects-filter-options: clean up use of ALLOC_GROW Matthew DeVore
2019-06-27 22:54 ` [PATCH v5 10/10] list-objects-filter-options: make parser void Matthew DeVore
2019-06-28 16:05 ` [PATCH v5 00/10] Filter combination Junio C Hamano
2019-06-28 17:16 ` Jonathan Tan
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190601003603.90794-7-matvore@google.com \
--to=matvore@google.com \
--cc=dstolee@microsoft.com \
--cc=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=jeffhost@microsoft.com \
--cc=jonathantanmy@google.com \
--cc=jrn@google.com \
--cc=jrnieder@gmail.com \
--cc=matvore@comcast.net \
--cc=pclouds@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).