From: Jeff Hostetler <git@jeffhostetler.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, jonathantanmy@google.com,
jeffhost@microsoft.com
Subject: [PATCH 04/13] list-objects-filter-all: add filter to omit all blobs
Date: Fri, 22 Sep 2017 20:26:23 +0000 [thread overview]
Message-ID: <20170922202632.53714-5-git@jeffhostetler.com> (raw)
In-Reply-To: <20170922202632.53714-1-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>
Create a simple filter for traverse_commit_list_worker() to omit
all blobs from the result.
This filter will be used in a future commit by rev-list and pack-objects
to create a "commits and trees" result. This is intended for partial
clone and fetch support.
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
Makefile | 1 +
list-objects-filter-all.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++
list-objects-filter-all.h | 18 ++++++++++
3 files changed, 104 insertions(+)
create mode 100644 list-objects-filter-all.c
create mode 100644 list-objects-filter-all.h
diff --git a/Makefile b/Makefile
index 4e0cc39..b98e3dc 100644
--- a/Makefile
+++ b/Makefile
@@ -798,6 +798,7 @@ LIB_OBJS += levenshtein.o
LIB_OBJS += line-log.o
LIB_OBJS += line-range.o
LIB_OBJS += list-objects.o
+LIB_OBJS += list-objects-filter-all.o
LIB_OBJS += ll-merge.o
LIB_OBJS += lockfile.o
LIB_OBJS += log-tree.o
diff --git a/list-objects-filter-all.c b/list-objects-filter-all.c
new file mode 100644
index 0000000..2faccb3
--- /dev/null
+++ b/list-objects-filter-all.c
@@ -0,0 +1,85 @@
+#include "cache.h"
+#include "dir.h"
+#include "tag.h"
+#include "commit.h"
+#include "tree.h"
+#include "blob.h"
+#include "diff.h"
+#include "tree-walk.h"
+#include "revision.h"
+#include "list-objects.h"
+#include "list-objects-filter-all.h"
+
+/*
+ * A filter for list-objects to omit ALL blobs from the traversal.
+ */
+struct filter_omit_all_blobs_data {
+ struct oidset2 omits;
+};
+
+static list_objects_filter_result filter_omit_all_blobs(
+ list_objects_filter_type filter_type,
+ struct object *obj,
+ const char *pathname,
+ const char *filename,
+ void *filter_data_)
+{
+ struct filter_omit_all_blobs_data *filter_data = filter_data_;
+ int64_t object_length = -1;
+ unsigned long s;
+ enum object_type t;
+
+ switch (filter_type) {
+ default:
+ die("unkown filter_type");
+ return LOFR_ZERO;
+
+ case LOFT_BEGIN_TREE:
+ assert(obj->type == OBJ_TREE);
+ /* always include all tree objects */
+ return LOFR_MARK_SEEN | LOFR_SHOW;
+
+ case LOFT_END_TREE:
+ assert(obj->type == OBJ_TREE);
+ return LOFR_ZERO;
+
+ case LOFT_BLOB:
+ assert(obj->type == OBJ_BLOB);
+ assert((obj->flags & SEEN) == 0);
+
+ /*
+ * Since we always omit all blobs (and never provisionally omit),
+ * we should never see a blob twice.
+ */
+ assert(!oidset2_contains(&filter_data->omits, &obj->oid));
+
+ t = sha1_object_info(obj->oid.hash, &s);
+ assert(t == OBJ_BLOB);
+ object_length = (int64_t)((uint64_t)(s));
+
+ /* Insert OID into the omitted list. No need for a pathname. */
+ oidset2_insert(&filter_data->omits, &obj->oid, t, object_length,
+ NULL);
+ return LOFR_MARK_SEEN; /* but not LOFR_SHOW (hard omit) */
+ }
+}
+
+void traverse_commit_list_omit_all_blobs(
+ struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ oidset2_foreach_cb print_omitted_object,
+ void *ctx_data)
+{
+ struct filter_omit_all_blobs_data d;
+
+ memset(&d, 0, sizeof(d));
+
+ traverse_commit_list_worker(revs, show_commit, show_object, ctx_data,
+ filter_omit_all_blobs, &d);
+
+ if (print_omitted_object)
+ oidset2_foreach(&d.omits, print_omitted_object, ctx_data);
+
+ oidset2_clear(&d.omits);
+}
diff --git a/list-objects-filter-all.h b/list-objects-filter-all.h
new file mode 100644
index 0000000..591589f
--- /dev/null
+++ b/list-objects-filter-all.h
@@ -0,0 +1,18 @@
+#ifndef LIST_OBJECTS_FILTER_ALL_H
+#define LIST_OBJECTS_FILTER_ALL_H
+
+#include "oidset2.h"
+
+/*
+ * A filter for list-objects to omit ALL blobs
+ * from the traversal.
+ */
+void traverse_commit_list_omit_all_blobs(
+ struct rev_info *revs,
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ oidset2_foreach_cb print_omitted_object,
+ void *ctx_data);
+
+#endif /* LIST_OBJECTS_FILTER_ALL_H */
+
--
2.9.3
next prev parent reply other threads:[~2017-09-22 20:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 20:26 [PATCH 00/13] RFC object filtering for parital clone Jeff Hostetler
2017-09-22 20:26 ` [PATCH 01/13] dir: refactor add_excludes() Jeff Hostetler
2017-09-22 20:26 ` [PATCH 02/13] oidset2: create oidset subclass with object length and pathname Jeff Hostetler
2017-09-22 20:42 ` Brandon Williams
2017-09-26 22:20 ` Jonathan Tan
2017-09-27 14:47 ` Jeff Hostetler
2017-09-22 20:26 ` [PATCH 03/13] list-objects: filter objects in traverse_commit_list Jeff Hostetler
2017-09-26 22:31 ` Jonathan Tan
2017-09-27 17:04 ` Jeff Hostetler
2017-09-27 18:00 ` Jonathan Tan
2017-09-27 19:09 ` Jeff Hostetler
2017-09-27 20:49 ` Jonathan Tan
2017-09-22 20:26 ` Jeff Hostetler [this message]
2017-09-23 0:39 ` [PATCH 00/13] RFC object filtering for parital clone Jonathan Tan
2017-09-26 14:55 ` Jeff Hostetler
2017-09-26 19:23 ` Jeff Hostetler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170922202632.53714-5-git@jeffhostetler.com \
--to=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.com \
--cc=jonathantanmy@google.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).