Skip to content

Commit

Permalink
Merge branch 'md/list-objects-filter-combo'
Browse files Browse the repository at this point in the history
The list-objects-filter API (used to create a sparse/lazy clone)
learned to take a combined filter specification.

* md/list-objects-filter-combo:
  list-objects-filter-options: make parser void
  list-objects-filter-options: clean up use of ALLOC_GROW
  list-objects-filter-options: allow mult. --filter
  strbuf: give URL-encoding API a char predicate fn
  list-objects-filter-options: make filter_spec a string_list
  list-objects-filter-options: move error check up
  list-objects-filter: implement composite filters
  list-objects-filter-options: always supply *errbuf
  list-objects-filter: put omits set in filter struct
  list-objects-filter: encapsulate filter components
  • Loading branch information
gitster committed Sep 18, 2019
2 parents b9ac6c5 + 90d21f9 commit 627b826
Show file tree
Hide file tree
Showing 22 changed files with 889 additions and 242 deletions.
16 changes: 16 additions & 0 deletions Documentation/rev-list-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,22 @@ explicitly-given commit or tree.
Note that the form '--filter=sparse:path=<path>' that wants to read
from an arbitrary path on the filesystem has been dropped for security
reasons.
+
Multiple '--filter=' flags can be specified to combine filters. Only
objects which are accepted by every filter are included.
+
The form '--filter=combine:<filter1>+<filter2>+...<filterN>' can also be
used to combined several filters, but this is harder than just repeating
the '--filter' flag and is usually not necessary. Filters are joined by
'{plus}' and individual filters are %-encoded (i.e. URL-encoded).
Besides the '{plus}' and '%' characters, the following characters are
reserved and also must be encoded: `~!@#$^&*()[]{}\;",<>?`+&#39;&#96;+
as well as all characters with ASCII code &lt;= `0x20`, which includes
space and newline.
+
Other arbitrary characters can also be encoded. For instance,
'combine:tree:3+blob:none' and 'combine:tree%3A3+blob%3Anone' are
equivalent.

--no-filter::
Turn off any previous `--filter=` argument.
Expand Down
8 changes: 3 additions & 5 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport->server_options = &server_options;

if (filter_options.choice) {
struct strbuf expanded_filter_spec = STRBUF_INIT;
expand_list_objects_filter_spec(&filter_options,
&expanded_filter_spec);
const char *spec =
expand_list_objects_filter_spec(&filter_options);
transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
expanded_filter_spec.buf);
spec);
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
strbuf_release(&expanded_filter_spec);
}

if (transport->smart_options && !deepen && !filter_options.choice)
Expand Down
9 changes: 3 additions & 6 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,13 +1243,10 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
if (update_shallow)
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
if (filter_options.choice) {
struct strbuf expanded_filter_spec = STRBUF_INIT;
expand_list_objects_filter_spec(&filter_options,
&expanded_filter_spec);
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
expanded_filter_spec.buf);
const char *spec =
expand_list_objects_filter_spec(&filter_options);
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, spec);
set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
strbuf_release(&expanded_filter_spec);
}
if (negotiation_tip.nr) {
if (transport->smart_options)
Expand Down
6 changes: 4 additions & 2 deletions builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
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);
die(
_("invalid sparse value '%s'"),
list_objects_filter_spec(
&filter_options));
continue;
}
if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
Expand Down
22 changes: 22 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ int daemonize(void);
* at least 'nr' entries; the number of entries currently allocated
* is 'alloc', using the standard growing factor alloc_nr() macro.
*
* Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
* added niceties.
*
* DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
*/
#define ALLOC_GROW(x, nr, alloc) \
Expand All @@ -649,6 +652,25 @@ int daemonize(void);
} \
} while (0)

/*
* Similar to ALLOC_GROW but handles updating of the nr value and
* zeroing the bytes of the newly-grown array elements.
*
* DO NOT USE any expression with side-effect for any of the
* arguments.
*/
#define ALLOC_GROW_BY(x, nr, increase, alloc) \
do { \
if (increase) { \
size_t new_nr = nr + (increase); \
if (new_nr < nr) \
BUG("negative growth in ALLOC_GROW_BY"); \
ALLOC_GROW(x, new_nr, alloc); \
memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
nr = new_nr; \
} \
} while (0)

/* Initialize and use the cache information */
struct lock_file;
void preload_index(struct index_state *index,
Expand Down
9 changes: 5 additions & 4 deletions credential-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ static void store_credential_file(const char *fn, struct credential *c)
struct strbuf buf = STRBUF_INIT;

strbuf_addf(&buf, "%s://", c->protocol);
strbuf_addstr_urlencode(&buf, c->username, 1);
strbuf_addstr_urlencode(&buf, c->username, is_rfc3986_unreserved);
strbuf_addch(&buf, ':');
strbuf_addstr_urlencode(&buf, c->password, 1);
strbuf_addstr_urlencode(&buf, c->password, is_rfc3986_unreserved);
strbuf_addch(&buf, '@');
if (c->host)
strbuf_addstr_urlencode(&buf, c->host, 1);
strbuf_addstr_urlencode(&buf, c->host, is_rfc3986_unreserved);
if (c->path) {
strbuf_addch(&buf, '/');
strbuf_addstr_urlencode(&buf, c->path, 0);
strbuf_addstr_urlencode(&buf, c->path,
is_rfc3986_reserved_or_unreserved);
}

rewrite_credential_file(fn, c, &buf);
Expand Down
20 changes: 7 additions & 13 deletions fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,9 @@ static int find_common(struct fetch_negotiator *negotiator,
}
}
if (server_supports_filtering && args->filter_options.choice) {
struct strbuf expanded_filter_spec = STRBUF_INIT;
expand_list_objects_filter_spec(&args->filter_options,
&expanded_filter_spec);
packet_buf_write(&req_buf, "filter %s",
expanded_filter_spec.buf);
strbuf_release(&expanded_filter_spec);
const char *spec =
expand_list_objects_filter_spec(&args->filter_options);
packet_buf_write(&req_buf, "filter %s", spec);
}
packet_buf_flush(&req_buf);
state_len = req_buf.len;
Expand Down Expand Up @@ -1112,7 +1109,7 @@ static int add_haves(struct fetch_negotiator *negotiator,
}

static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
const struct fetch_pack_args *args,
struct fetch_pack_args *args,
const struct ref *wants, struct oidset *common,
int *haves_to_send, int *in_vain,
int sideband_all)
Expand Down Expand Up @@ -1153,13 +1150,10 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
/* Add filter */
if (server_supports_feature("fetch", "filter", 0) &&
args->filter_options.choice) {
struct strbuf expanded_filter_spec = STRBUF_INIT;
const char *spec =
expand_list_objects_filter_spec(&args->filter_options);
print_verbose(args, _("Server supports filter"));
expand_list_objects_filter_spec(&args->filter_options,
&expanded_filter_spec);
packet_buf_write(&req_buf, "filter %s",
expanded_filter_spec.buf);
strbuf_release(&expanded_filter_spec);
packet_buf_write(&req_buf, "filter %s", spec);
} else if (args->filter_options.choice) {
warning("filtering not recognized by server, ignoring");
}
Expand Down
6 changes: 4 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,11 @@ static void set_proxyauth_name_password(CURL *result)
#else
struct strbuf s = STRBUF_INIT;

strbuf_addstr_urlencode(&s, proxy_auth.username, 1);
strbuf_addstr_urlencode(&s, proxy_auth.username,
is_rfc3986_unreserved);
strbuf_addch(&s, ':');
strbuf_addstr_urlencode(&s, proxy_auth.password, 1);
strbuf_addstr_urlencode(&s, proxy_auth.password,
is_rfc3986_unreserved);
curl_proxyuserpwd = strbuf_detach(&s, NULL);
curl_easy_setopt(result, CURLOPT_PROXYUSERPWD, curl_proxyuserpwd);
#endif
Expand Down

0 comments on commit 627b826

Please sign in to comment.