This is a resend for sb/diff-blobfind, but now the option --find-object
is a native of the pickaxe family.

Stefan Beller (1):
  diffcore: add a pickaxe option to find a specific blob

 Documentation/diff-options.txt | 10 +++++++
 diff.c                         | 21 ++++++++++++-
 diff.h                         |  3 ++
 diffcore-pickaxe.c             | 14 +++++++--
 revision.c                     |  3 ++
 t/t4064-diff-oidfind.sh        | 68 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 115 insertions(+), 4 deletions(-)
 create mode 100755 t/t4064-diff-oidfind.sh

-- 
2.15.1.620.gb9897f4670-goog

diff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt
index 21d1776996..f9cf85db05 100644
--- c/Documentation/diff-options.txt
+++ w/Documentation/diff-options.txt
@@ -492,6 +492,15 @@ occurrences of that string did not change).
 See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
 information.
 
+--find-object=<object-id>::
+       Look for differences that change the number of occurrences of
+       the specified object. Similar to `-S`, just the argument is different
+       in that it doesn't search for a specific string but for a specific
+       object id.
++
+The object can be a blob or a submodule commit. It implies the `-t` option in
+`git-log` to also find trees.
+
 --pickaxe-all::
        When `-S` or `-G` finds a change, show all the changes in that
        changeset, not just the files that contain the change
@@ -501,11 +510,6 @@ information.
        Treat the <string> given to `-S` as an extended POSIX regular
        expression to match.
 
---find-object=<object-id>::
-       Restrict the output such that one side of the diff
-       matches the given object id. The object can be a blob,
-       gitlink entry or tree (when `-t` is given).
-
 endif::git-format-patch[]
 
 -O<orderfile>::
diff --git c/Makefile w/Makefile
index c26596c30a..ee9d5eb11e 100644
--- c/Makefile
+++ w/Makefile
@@ -775,7 +775,6 @@ LIB_OBJS += date.o
 LIB_OBJS += decorate.o
 LIB_OBJS += diffcore-break.o
 LIB_OBJS += diffcore-delta.o
-LIB_OBJS += diffcore-objfind.o
 LIB_OBJS += diffcore-order.o
 LIB_OBJS += diffcore-pickaxe.o
 LIB_OBJS += diffcore-rename.o
diff --git c/builtin/log.c w/builtin/log.c
index 08ea82d69f..6c1fa896ad 100644
--- c/builtin/log.c
+++ w/builtin/log.c
@@ -181,7 +181,7 @@ static void cmd_log_init_finish(int argc, const char 
**argv, const char *prefix,
                init_display_notes(&rev->notes_opt);
 
        if (rev->diffopt.pickaxe || rev->diffopt.filter ||
-           rev->diffopt.flags.follow_renames || rev->diffopt.objfind)
+           rev->diffopt.flags.follow_renames)
                rev->always_show_header = 0;
 
        if (source)
diff --git c/diff.c w/diff.c
index e13b8229d3..7acddaaee7 100644
--- c/diff.c
+++ w/diff.c
@@ -4497,6 +4497,10 @@ static int parse_objfind_opt(struct diff_options *opt, 
const char *arg)
 
        if (!opt->objfind)
                opt->objfind = xcalloc(1, sizeof(*opt->objfind));
+
+       opt->pickaxe = ""; /* trigger pickaxe */
+       opt->flags.recursive = 1;
+       opt->flags.tree_in_recursive = 1;
        oidset_insert(opt->objfind, &oid);
        return 1;
 }
@@ -5785,9 +5789,6 @@ void diffcore_std(struct diff_options *options)
                diffcore_skip_stat_unmatch(options);
        if (!options->found_follow) {
                /* See try_to_follow_renames() in tree-diff.c */
-
-               if (options->objfind)
-                       diffcore_objfind(options);
                if (options->break_opt != -1)
                        diffcore_break(options->break_opt);
                if (options->detect_rename)
diff --git c/diffcore-objfind.c w/diffcore-objfind.c
deleted file mode 100644
index 676bbfff00..0000000000
--- c/diffcore-objfind.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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);
-}
diff --git c/diffcore-pickaxe.c w/diffcore-pickaxe.c
index 9476bd2108..0d0c697ae7 100644
--- c/diffcore-pickaxe.c
+++ w/diffcore-pickaxe.c
@@ -124,13 +124,21 @@ static int pickaxe_match(struct diff_filepair *p, struct 
diff_options *o,
        mmfile_t mf1, mf2;
        int ret;
 
-       if (!o->pickaxe[0])
-               return 0;
-
        /* ignore unmerged */
        if (!DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two))
                return 0;
 
+       if (o->objfind) {
+               if ((DIFF_FILE_VALID(p->one) &&
+                    oidset_contains(o->objfind, &p->one->oid)) ||
+                   (DIFF_FILE_VALID(p->two) &&
+                    oidset_contains(o->objfind, &p->two->oid)))
+                       return 1;
+       }
+
+       if (!o->pickaxe[0])
+               return 0;
+
        if (o->flags.allow_textconv) {
                textconv_one = get_textconv(p->one);
                textconv_two = get_textconv(p->two);
diff --git c/diffcore.h w/diffcore.h
index cbde777bdd..a30da161da 100644
--- c/diffcore.h
+++ w/diffcore.h
@@ -107,7 +107,6 @@ extern struct diff_filepair *diff_queue(struct 
diff_queue_struct *,
                                        struct diff_filespec *);
 extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
 
-extern void diffcore_objfind(struct diff_options *);
 extern void diffcore_break(int);
 extern void diffcore_rename(struct diff_options *);
 extern void diffcore_merge_broken(void);
diff --git c/revision.c w/revision.c
index 0a797bdfc7..43bb6265cd 100644
--- c/revision.c
+++ w/revision.c
@@ -2409,10 +2409,12 @@ int setup_revisions(int argc, const char **argv, struct 
rev_info *revs, struct s
        /* Pickaxe, diff-filter and rename following need diffs */
        if (revs->diffopt.pickaxe ||
            revs->diffopt.filter ||
-           revs->diffopt.flags.follow_renames ||
-           revs->diffopt.objfind)
+           revs->diffopt.flags.follow_renames)
                revs->diff = 1;
 
+       if (revs->diffopt.objfind)
+               revs->simplify_history = 0;
+
        if (revs->topo_order)
                revs->limited = 1;
 
@@ -2884,8 +2886,6 @@ int prepare_revision_walk(struct rev_info *revs)
                simplify_merges(revs);
        if (revs->children.name)
                set_children(revs);
-       if (revs->diffopt.objfind)
-               revs->simplify_history = 0;
        return 0;
 }
 
diff --git c/t/helper/test-lazy-init-name-hash.c 
w/t/helper/test-lazy-init-name-hash.c
index 6368a89345..297fb01d61 100644
--- c/t/helper/test-lazy-init-name-hash.c
+++ w/t/helper/test-lazy-init-name-hash.c
@@ -112,7 +112,7 @@ static void analyze_run(void)
 {
        uint64_t t1s, t1m, t2s, t2m;
        int cache_nr_limit;
-       int nr_threads_used;
+       int nr_threads_used = 0;
        int i;
        int nr;
 

Reply via email to