#include "list-objects.h"
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
+#include "promisor-remote.h"
+ #include "trace.h"
+ #include "url.h"
+
+ static int parse_combine_filter(
+ struct list_objects_filter_options *filter_options,
+ const char *arg,
+ struct strbuf *errbuf);
/*
* Parse value of the argument to the "filter" keyword.
{
const char *v0;
- if (filter_options->choice) {
- if (errbuf) {
- strbuf_addstr(
- errbuf,
- _("multiple filter-specs cannot be combined"));
- }
- return 1;
- }
-
- filter_options->filter_spec = strdup(arg);
+ if (!arg)
+ return 0;
+
+ if (filter_options->choice)
+ BUG("filter_options already populated");
if (!strcmp(arg, "blob:none")) {
filter_options->choice = LOFC_BLOB_NONE;
void partial_clone_register(
const char *remote,
- const struct list_objects_filter_options *filter_options)
+ struct list_objects_filter_options *filter_options)
{
- /*
- * Record the name of the partial clone remote in the
- * config and in the global variable -- the latter is
- * used throughout to indicate that partial clone is
- * enabled and to expect missing objects.
- */
- if (repository_format_partial_clone &&
- *repository_format_partial_clone &&
- strcmp(remote, repository_format_partial_clone))
- die(_("cannot change partial clone promisor remote"));
+ char *cfg_name;
+ char *filter_name;
- git_config_set("core.repositoryformatversion", "1");
- git_config_set("extensions.partialclone", remote);
+ /* Check if it is already registered */
+ if (!promisor_remote_find(remote)) {
+ git_config_set("core.repositoryformatversion", "1");
- repository_format_partial_clone = xstrdup(remote);
+ /* Add promisor config for the remote */
+ cfg_name = xstrfmt("remote.%s.promisor", remote);
+ git_config_set(cfg_name, "true");
+ free(cfg_name);
+ }
/*
* Record the initial filter-spec in the config as
* the default for subsequent fetches from this remote.
*/
- core_partial_clone_filter_default =
- xstrdup(expand_list_objects_filter_spec(filter_options));
- git_config_set("core.partialclonefilter",
- core_partial_clone_filter_default);
+ filter_name = xstrfmt("remote.%s.partialclonefilter", remote);
- git_config_set(filter_name, filter_options->filter_spec);
++ /* NEEDSWORK: 'expand' result leaking??? */
++ git_config_set(filter_name,
++ expand_list_objects_filter_spec(filter_options));
+ free(filter_name);
+
+ /* Make sure the config info are reset */
+ promisor_remote_reinit();
}
void partial_clone_get_default_filter_spec(
- struct list_objects_filter_options *filter_options)
+ struct list_objects_filter_options *filter_options,
+ const char *remote)
{
+ struct promisor_remote *promisor = promisor_remote_find(remote);
+ struct strbuf errbuf = STRBUF_INIT;
/*
* Parse default value, but silently ignore it if it is invalid.
*/
- if (promisor)
- gently_parse_list_objects_filter(filter_options,
- promisor->partial_clone_filter,
- NULL);
- if (!core_partial_clone_filter_default)
++ if (!promisor)
+ return;
+
+ string_list_append(&filter_options->filter_spec,
- core_partial_clone_filter_default);
++ promisor->partial_clone_filter);
+ gently_parse_list_objects_filter(filter_options,
- core_partial_clone_filter_default,
++ promisor->partial_clone_filter,
+ &errbuf);
+ strbuf_release(&errbuf);
}
}
void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
- int reserved)
+ char_predicate allow_unencoded_fn)
{
- strbuf_add_urlencode(sb, s, strlen(s), reserved);
+ strbuf_add_urlencode(sb, s, strlen(s), allow_unencoded_fn);
}
-void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
+static void strbuf_humanise(struct strbuf *buf, off_t bytes,
+ int humanise_rate)
{
if (bytes > 1 << 30) {
- strbuf_addf(buf, "%u.%2.2u GiB",
+ strbuf_addf(buf,
+ humanise_rate == 0 ?
+ /* TRANSLATORS: IEC 80000-13:2008 gibibyte */
+ _("%u.%2.2u GiB") :
+ /* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */
+ _("%u.%2.2u GiB/s"),
(unsigned)(bytes >> 30),
(unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
} else if (bytes > 1 << 20) {