summaryrefslogtreecommitdiff
path: root/list-objects-filter-options.c
diff options
context:
space:
mode:
authorJosh Steadmon <steadmon@google.com>2019-01-08 00:17:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-01-15 23:42:31 (GMT)
commit87c2d9d3102e6c388f2d29f1bdb0b3a222d9a707 (patch)
treebfc01fed555a7f00b7ad226bed3ffafd0d70f2c0 /list-objects-filter-options.c
parent8272f26034c9dbaf5cd216a137b8e91241cbc24e (diff)
downloadgit-87c2d9d3102e6c388f2d29f1bdb0b3a222d9a707.zip
git-87c2d9d3102e6c388f2d29f1bdb0b3a222d9a707.tar.gz
git-87c2d9d3102e6c388f2d29f1bdb0b3a222d9a707.tar.bz2
filter-options: expand scaled numbers
When communicating with a remote server or a subprocess, use expanded numbers rather than numbers with scaling suffix in the object filter spec (e.g. "limit:blob=1k" becomes "limit:blob=1024"). Update the protocol docs to note that clients should always perform this expansion, to allow for more compatibility between server implementations. Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'list-objects-filter-options.c')
-rw-r--r--list-objects-filter-options.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index 5285e76..9efb3e9 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -18,8 +18,9 @@
* See Documentation/rev-list-options.txt for allowed values for <arg>.
*
* Capture the given arg as the "filter_spec". This can be forwarded to
- * subordinate commands when necessary. We also "intern" the arg for
- * the convenience of the current command.
+ * subordinate commands when necessary (although it's better to pass it through
+ * expand_list_objects_filter_spec() first). We also "intern" the arg for the
+ * convenience of the current command.
*/
static int gently_parse_list_objects_filter(
struct list_objects_filter_options *filter_options,
@@ -111,6 +112,21 @@ int opt_parse_list_objects_filter(const struct option *opt,
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));
+ 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);
+}
+
void list_objects_filter_release(
struct list_objects_filter_options *filter_options)
{