diff options
author | Stefan Beller <sbeller@google.com> | 2017-12-11 17:24:22 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-12-12 10:31:32 -0800 |
commit | 785d58cf991d5a11a7b249ec28c506cd7adbdcef (patch) | |
tree | 9911eb153c5389a8e8ade7aa69387d8814a39431 /diffcore-objfind.c | |
parent | d8df70f2739af78cab6d7f9b942e890da6fbd01d (diff) | |
download | git-sb/diff-blobfind.tar.gz |
diffcore: add a filter to find a specific blobsb/diff-blobfind
Sometimes users are given a hash of an object and they want to
identify it further (ex.: Use verify-pack to find the largest blobs,
but what are these? or [1])
One might be tempted to extend git-describe to also work with blobs,
such that `git describe <blob-id>` gives a description as
'<commit-ish>:<path>'. This was implemented at [2]; as seen by the sheer
number of responses (>110), it turns out this is tricky to get right.
The hard part to get right is picking the correct 'commit-ish' as that
could be the commit that (re-)introduced the blob or the blob that
removed the blob; the blob could exist in different branches.
Junio hinted at a different approach of solving this problem, which this
patch implements. Teach the diff machinery another flag for restricting
the information to what is shown. For example:
$ ./git log --oneline --find-object=v2.0.0:Makefile
b2feb64309 Revert the whole "ask curl-config" topic for now
47fbfded53 i18n: only extract comments marked with "TRANSLATORS:"
we observe that the Makefile as shipped with 2.0 was appeared in
v1.9.2-471-g47fbfded53 and in v2.0.0-rc1-5-gb2feb6430b. The
reason why these commits both occur prior to v2.0.0 are evil
merges that are not found using this new mechanism.
[1] https://stackoverflow.com/questions/223678/which-commit-has-this-blob
[2] https://public-inbox.org/git/20171028004419.10139-1-sbeller@google.com/
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diffcore-objfind.c')
-rw-r--r-- | diffcore-objfind.c | 42 |
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); +} |