aboutsummaryrefslogtreecommitdiffstats
path: root/list-objects-filter-options.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-11-21 20:58:50 +0000
committerJunio C Hamano <gitster@pobox.com>2017-11-22 14:11:57 +0900
commit25ec7bcac044057900a0f3c9a8d6ccbb41a066bc (patch)
tree115a72c755c0578349d3cf08bef0b0883fd4153e /list-objects-filter-options.c
parentc3a9ad311793e16f6f5c5dcc3559133700c70288 (diff)
downloadgit-25ec7bcac044057900a0f3c9a8d6ccbb41a066bc.tar.gz
list-objects: filter objects in traverse_commit_list
Create traverse_commit_list_filtered() and add filtering interface to allow certain objects to be omitted from the traversal. Update traverse_commit_list() to be a wrapper for the above with a null filter to minimize the number of callers that needed to be changed. Object filtering will be used in a future commit by rev-list and pack-objects for partial clone and fetch to omit unwanted objects from the result. traverse_bitmap_commit_list() does not work with filtering. If a packfile bitmap is present, it will not be used. It should be possible to extend such support in the future (at least to simple filters that do not require object pathnames), but that is beyond the scope of this patch series. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Reviewed-by: Jonathan Tan <jonathantanmy@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.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
new file mode 100644
index 0000000000..9b28322b1f
--- /dev/null
+++ b/list-objects-filter-options.c
@@ -0,0 +1,81 @@
+#include "cache.h"
+#include "commit.h"
+#include "config.h"
+#include "revision.h"
+#include "argv-array.h"
+#include "list-objects.h"
+#include "list-objects-filter.h"
+#include "list-objects-filter-options.h"
+
+/*
+ * Parse value of the argument to the "filter" keword.
+ * On the command line this looks like:
+ * --filter=<arg>
+ * and in the pack protocol as:
+ * "filter" SP <arg>
+ *
+ * The filter keyword will be used by many commands.
+ * 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.
+ */
+int parse_list_objects_filter(struct list_objects_filter_options *filter_options,
+ const char *arg)
+{
+ const char *v0;
+
+ if (filter_options->choice)
+ die(_("multiple object filter types cannot be combined"));
+
+ filter_options->filter_spec = strdup(arg);
+
+ if (!strcmp(arg, "blob:none")) {
+ filter_options->choice = LOFC_BLOB_NONE;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "blob:limit=", &v0)) {
+ if (!git_parse_ulong(v0, &filter_options->blob_limit_value))
+ die(_("invalid filter-spec expression '%s'"), arg);
+ filter_options->choice = LOFC_BLOB_LIMIT;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "sparse:oid=", &v0)) {
+ struct object_context oc;
+ struct object_id sparse_oid;
+
+ /*
+ * Try to parse <oid-expression> into an OID for the current
+ * command, but DO NOT complain if we don't have the blob or
+ * ref locally.
+ */
+ if (!get_oid_with_context(v0, GET_OID_BLOB,
+ &sparse_oid, &oc))
+ filter_options->sparse_oid_value = oiddup(&sparse_oid);
+ filter_options->choice = LOFC_SPARSE_OID;
+ return 0;
+ }
+
+ if (skip_prefix(arg, "sparse:path=", &v0)) {
+ filter_options->choice = LOFC_SPARSE_PATH;
+ filter_options->sparse_path_value = strdup(v0);
+ return 0;
+ }
+
+ die(_("invalid filter-spec expression '%s'"), arg);
+ return 0;
+}
+
+int opt_parse_list_objects_filter(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct list_objects_filter_options *filter_options = opt->value;
+
+ assert(arg);
+ assert(!unset);
+
+ return parse_list_objects_filter(filter_options, arg);
+}