Skip to content

Commit 3bbb2be

Browse files
committed
Merge branch 'md/list-objects-filter-combo' into pu
* 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: make API easier to use
2 parents 600bfd9 + 8cae8b7 commit 3bbb2be

22 files changed

+880
-245
lines changed

Documentation/rev-list-options.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,22 @@ explicitly-given commit or tree.
738738
Note that the form '--filter=sparse:path=<path>' that wants to read
739739
from an arbitrary path on the filesystem has been dropped for security
740740
reasons.
741+
+
742+
Multiple '--filter=' flags can be specified to combine filters. Only
743+
objects which are accepted by every filter are included.
744+
+
745+
The form '--filter=combine:<filter1>+<filter2>+...<filterN>' can also be
746+
used to combined several filters, but this is harder than just repeating
747+
the '--filter' flag and is usually not necessary. Filters are joined by
748+
'{plus}' and individual filters are %-encoded (i.e. URL-encoded).
749+
Besides the '{plus}' and '%' characters, the following characters are
750+
reserved and also must be encoded: `~!@#$^&*()[]{}\;",<>?`+&#39;&#96;+
751+
as well as all characters with ASCII code &lt;= `0x20`, which includes
752+
space and newline.
753+
+
754+
Other arbitrary characters can also be encoded. For instance,
755+
'combine:tree:3+blob:none' and 'combine:tree%3A3+blob%3Anone' are
756+
equivalent.
741757

742758
--no-filter::
743759
Turn off any previous `--filter=` argument.

builtin/clone.c

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

11551155
if (filter_options.choice) {
1156-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1157-
expand_list_objects_filter_spec(&filter_options,
1158-
&expanded_filter_spec);
1156+
const char *spec =
1157+
expand_list_objects_filter_spec(&filter_options);
11591158
transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
1160-
expanded_filter_spec.buf);
1159+
spec);
11611160
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
1162-
strbuf_release(&expanded_filter_spec);
11631161
}
11641162

11651163
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
@@ -1198,13 +1198,10 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
11981198
if (update_shallow)
11991199
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
12001200
if (filter_options.choice) {
1201-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1202-
expand_list_objects_filter_spec(&filter_options,
1203-
&expanded_filter_spec);
1204-
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
1205-
expanded_filter_spec.buf);
1201+
const char *spec =
1202+
expand_list_objects_filter_spec(&filter_options);
1203+
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, spec);
12061204
set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
1207-
strbuf_release(&expanded_filter_spec);
12081205
}
12091206
if (negotiation_tip.nr) {
12101207
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
@@ -660,6 +660,9 @@ int daemonize(void);
660660
* at least 'nr' entries; the number of entries currently allocated
661661
* is 'alloc', using the standard growing factor alloc_nr() macro.
662662
*
663+
* Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
664+
* added niceties.
665+
*
663666
* DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
664667
*/
665668
#define ALLOC_GROW(x, nr, alloc) \
@@ -673,6 +676,25 @@ int daemonize(void);
673676
} \
674677
} while (0)
675678

679+
/*
680+
* Similar to ALLOC_GROW but handles updating of the nr value and
681+
* zeroing the bytes of the newly-grown array elements.
682+
*
683+
* DO NOT USE any expression with side-effect for any of the
684+
* arguments.
685+
*/
686+
#define ALLOC_GROW_BY(x, nr, increase, alloc) \
687+
do { \
688+
if (increase) { \
689+
size_t new_nr = nr + (increase); \
690+
if (new_nr < nr) \
691+
BUG("negative growth in ALLOC_GROW_BY"); \
692+
ALLOC_GROW(x, new_nr, alloc); \
693+
memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
694+
nr = new_nr; \
695+
} \
696+
} while (0)
697+
676698
/* Initialize and use the cache information */
677699
struct lock_file;
678700
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
@@ -340,12 +340,9 @@ static int find_common(struct fetch_negotiator *negotiator,
340340
}
341341
}
342342
if (server_supports_filtering && args->filter_options.choice) {
343-
struct strbuf expanded_filter_spec = STRBUF_INIT;
344-
expand_list_objects_filter_spec(&args->filter_options,
345-
&expanded_filter_spec);
346-
packet_buf_write(&req_buf, "filter %s",
347-
expanded_filter_spec.buf);
348-
strbuf_release(&expanded_filter_spec);
343+
const char *spec =
344+
expand_list_objects_filter_spec(&args->filter_options);
345+
packet_buf_write(&req_buf, "filter %s", spec);
349346
}
350347
packet_buf_flush(&req_buf);
351348
state_len = req_buf.len;
@@ -1109,7 +1106,7 @@ static int add_haves(struct fetch_negotiator *negotiator,
11091106
}
11101107

11111108
static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1112-
const struct fetch_pack_args *args,
1109+
struct fetch_pack_args *args,
11131110
const struct ref *wants, struct oidset *common,
11141111
int *haves_to_send, int *in_vain,
11151112
int sideband_all)
@@ -1150,13 +1147,10 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
11501147
/* Add filter */
11511148
if (server_supports_feature("fetch", "filter", 0) &&
11521149
args->filter_options.choice) {
1153-
struct strbuf expanded_filter_spec = STRBUF_INIT;
1150+
const char *spec =
1151+
expand_list_objects_filter_spec(&args->filter_options);
11541152
print_verbose(args, _("Server supports filter"));
1155-
expand_list_objects_filter_spec(&args->filter_options,
1156-
&expanded_filter_spec);
1157-
packet_buf_write(&req_buf, "filter %s",
1158-
expanded_filter_spec.buf);
1159-
strbuf_release(&expanded_filter_spec);
1153+
packet_buf_write(&req_buf, "filter %s", spec);
11601154
} else if (args->filter_options.choice) {
11611155
warning("filtering not recognized by server, ignoring");
11621156
}

http.c

Lines changed: 5 additions & 3 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
@@ -2272,7 +2274,7 @@ struct http_pack_request *new_http_pack_request(
22722274
sha1_pack_name(target->hash));
22732275
} else {
22742276
strbuf_addf(&preq->tmpfile, "%s/pack/pack-", get_object_directory());
2275-
strbuf_addstr_urlencode(&preq->tmpfile, base_url, 1);
2277+
strbuf_addstr_urlencode(&preq->tmpfile, base_url, is_rfc3986_unreserved);
22762278
strbuf_addstr(&preq->tmpfile, ".temp");
22772279
}
22782280

0 commit comments

Comments
 (0)