summaryrefslogtreecommitdiff
path: root/diffcore-objfind.c
diff options
context:
space:
mode:
Diffstat (limited to 'diffcore-objfind.c')
-rw-r--r--diffcore-objfind.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/diffcore-objfind.c b/diffcore-objfind.c
new file mode 100644
index 0000000000..676bbfff00
--- /dev/null
+++ b/diffcore-objfind.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Google Inc.
+ */
+#include "cache.h"
+#include "diff.h"
+#include "diffcore.h"
+
+static void diffcore_filter_blobs(struct diff_queue_struct *q,
+ struct diff_options *options)
+{
+ int src, dst;
+
+ if (!options->objfind)
+ BUG("objfind oidset not initialized???");
+
+ for (src = dst = 0; src < q->nr; src++) {
+ struct diff_filepair *p = q->queue[src];
+
+ if (!DIFF_PAIR_UNMERGED(p) &&
+ ((DIFF_FILE_VALID(p->one) &&
+ oidset_contains(options->objfind, &p->one->oid)) ||
+ (DIFF_FILE_VALID(p->two) &&
+ oidset_contains(options->objfind, &p->two->oid)))) {
+ q->queue[dst] = p;
+ dst++;
+ } else {
+ diff_free_filepair(p);
+ }
+ }
+
+ if (!dst) {
+ free(q->queue);
+ DIFF_QUEUE_CLEAR(q);
+ } else {
+ q->nr = dst;
+ }
+}
+
+void diffcore_objfind(struct diff_options *options)
+{
+ diffcore_filter_blobs(&diff_queued_diff, options);
+}