Skip to content

Commit 627b826

Browse files
committed
Merge branch 'md/list-objects-filter-combo'
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
2 parents b9ac6c5 + 90d21f9 commit 627b826

22 files changed

+889
-242
lines changed

Documentation/rev-list-options.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,22 @@ explicitly-given commit or tree.
756756
Note that the form '--filter=sparse:path=<path>' that wants to read
757757
from an arbitrary path on the filesystem has been dropped for security
758758
reasons.
759+
+
760+
Multiple '--filter=' flags can be specified to combine filters. Only
761+
objects which are accepted by every filter are included.
762+
+
763+
The form '--filter=combine:<filter1>+<filter2>+...<filterN>' can also be
764+
used to combined several filters, but this is harder than just repeating
765+
the '--filter' flag and is usually not necessary. Filters are joined by
766+
'{plus}' and individual filters are %-encoded (i.e. URL-encoded).
767+
Besides the '{plus}' and '%' characters, the following characters are
768+
reserved and also must be encoded: `~!@#$^&*()[]{}\;",<>?`+&#39;&#96;+
769+
as well as all characters with ASCII code &lt;= `0x20`, which includes
770+
space and newline.
771+
+
772+
Other arbitrary characters can also be encoded. For instance,
773+
'combine:tree:3+blob:none' and 'combine:tree%3A3+blob%3Anone' are
774+
equivalent.
759775

760776
--no-filter::
761777
Turn off any previous `--filter=` argument.

builtin/clone.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,13 +1160,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11601160
transport->server_options = &server_options;
11611161

11621162
if (filter_options.choice) {
1163-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1164-
expand_list_objects_filter_spec(&filter_options,
1165-
&expanded_filter_spec);
1163+
const char *spec =
1164+
expand_list_objects_filter_spec(&filter_options);
11661165
transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
1167-
expanded_filter_spec.buf);
1166+
spec);
11681167
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
1169-
strbuf_release(&expanded_filter_spec);
11701168
}
11711169

11721170
if (transport->smart_options && !deepen && !filter_options.choice)

builtin/fetch.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,13 +1243,10 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
12431243
if (update_shallow)
12441244
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
12451245
if (filter_options.choice) {
1246-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1247-
expand_list_objects_filter_spec(&filter_options,
1248-
&expanded_filter_spec);
1249-
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
1250-
expanded_filter_spec.buf);
1246+
const char *spec =
1247+
expand_list_objects_filter_spec(&filter_options);
1248+
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, spec);
12511249
set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
1252-
strbuf_release(&expanded_filter_spec);
12531250
}
12541251
if (negotiation_tip.nr) {
12551252
if (transport->smart_options)

builtin/rev-list.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
473473
die(_("object filtering requires --objects"));
474474
if (filter_options.choice == LOFC_SPARSE_OID &&
475475
!filter_options.sparse_oid_value)
476-
die(_("invalid sparse value '%s'"),
477-
filter_options.filter_spec);
476+
die(
477+
_("invalid sparse value '%s'"),
478+
list_objects_filter_spec(
479+
&filter_options));
478480
continue;
479481
}
480482
if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {

cache.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ int daemonize(void);
636636
* at least 'nr' entries; the number of entries currently allocated
637637
* is 'alloc', using the standard growing factor alloc_nr() macro.
638638
*
639+
* Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
640+
* added niceties.
641+
*
639642
* DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
640643
*/
641644
#define ALLOC_GROW(x, nr, alloc) \
@@ -649,6 +652,25 @@ int daemonize(void);
649652
} \
650653
} while (0)
651654

655+
/*
656+
* Similar to ALLOC_GROW but handles updating of the nr value and
657+
* zeroing the bytes of the newly-grown array elements.
658+
*
659+
* DO NOT USE any expression with side-effect for any of the
660+
* arguments.
661+
*/
662+
#define ALLOC_GROW_BY(x, nr, increase, alloc) \
663+
do { \
664+
if (increase) { \
665+
size_t new_nr = nr + (increase); \
666+
if (new_nr < nr) \
667+
BUG("negative growth in ALLOC_GROW_BY"); \
668+
ALLOC_GROW(x, new_nr, alloc); \
669+
memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
670+
nr = new_nr; \
671+
} \
672+
} while (0)
673+
652674
/* Initialize and use the cache information */
653675
struct lock_file;
654676
void preload_index(struct index_state *index,

credential-store.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ static void store_credential_file(const char *fn, struct credential *c)
7272
struct strbuf buf = STRBUF_INIT;
7373

7474
strbuf_addf(&buf, "%s://", c->protocol);
75-
strbuf_addstr_urlencode(&buf, c->username, 1);
75+
strbuf_addstr_urlencode(&buf, c->username, is_rfc3986_unreserved);
7676
strbuf_addch(&buf, ':');
77-
strbuf_addstr_urlencode(&buf, c->password, 1);
77+
strbuf_addstr_urlencode(&buf, c->password, is_rfc3986_unreserved);
7878
strbuf_addch(&buf, '@');
7979
if (c->host)
80-
strbuf_addstr_urlencode(&buf, c->host, 1);
80+
strbuf_addstr_urlencode(&buf, c->host, is_rfc3986_unreserved);
8181
if (c->path) {
8282
strbuf_addch(&buf, '/');
83-
strbuf_addstr_urlencode(&buf, c->path, 0);
83+
strbuf_addstr_urlencode(&buf, c->path,
84+
is_rfc3986_reserved_or_unreserved);
8485
}
8586

8687
rewrite_credential_file(fn, c, &buf);

fetch-pack.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,9 @@ static int find_common(struct fetch_negotiator *negotiator,
338338
}
339339
}
340340
if (server_supports_filtering && args->filter_options.choice) {
341-
struct strbuf expanded_filter_spec = STRBUF_INIT;
342-
expand_list_objects_filter_spec(&args->filter_options,
343-
&expanded_filter_spec);
344-
packet_buf_write(&req_buf, "filter %s",
345-
expanded_filter_spec.buf);
346-
strbuf_release(&expanded_filter_spec);
341+
const char *spec =
342+
expand_list_objects_filter_spec(&args->filter_options);
343+
packet_buf_write(&req_buf, "filter %s", spec);
347344
}
348345
packet_buf_flush(&req_buf);
349346
state_len = req_buf.len;
@@ -1112,7 +1109,7 @@ static int add_haves(struct fetch_negotiator *negotiator,
11121109
}
11131110

11141111
static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1115-
const struct fetch_pack_args *args,
1112+
struct fetch_pack_args *args,
11161113
const struct ref *wants, struct oidset *common,
11171114
int *haves_to_send, int *in_vain,
11181115
int sideband_all)
@@ -1153,13 +1150,10 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
11531150
/* Add filter */
11541151
if (server_supports_feature("fetch", "filter", 0) &&
11551152
args->filter_options.choice) {
1156-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1153+
const char *spec =
1154+
expand_list_objects_filter_spec(&args->filter_options);
11571155
print_verbose(args, _("Server supports filter"));
1158-
expand_list_objects_filter_spec(&args->filter_options,
1159-
&expanded_filter_spec);
1160-
packet_buf_write(&req_buf, "filter %s",
1161-
expanded_filter_spec.buf);
1162-
strbuf_release(&expanded_filter_spec);
1156+
packet_buf_write(&req_buf, "filter %s", spec);
11631157
} else if (args->filter_options.choice) {
11641158
warning("filtering not recognized by server, ignoring");
11651159
}

http.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ static void set_proxyauth_name_password(CURL *result)
513513
#else
514514
struct strbuf s = STRBUF_INIT;
515515

516-
strbuf_addstr_urlencode(&s, proxy_auth.username, 1);
516+
strbuf_addstr_urlencode(&s, proxy_auth.username,
517+
is_rfc3986_unreserved);
517518
strbuf_addch(&s, ':');
518-
strbuf_addstr_urlencode(&s, proxy_auth.password, 1);
519+
strbuf_addstr_urlencode(&s, proxy_auth.password,
520+
is_rfc3986_unreserved);
519521
curl_proxyuserpwd = strbuf_detach(&s, NULL);
520522
curl_easy_setopt(result, CURLOPT_PROXYUSERPWD, curl_proxyuserpwd);
521523
#endif

0 commit comments

Comments
 (0)