mirror of
https://github.com/git/git.git
synced 2026-01-09 17:46:37 +00:00
diffcore: add a pickaxe option to find a specific blob
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>
This commit is contained in:
committed by
Junio C Hamano
parent
cf63051ada
commit
15af58c1ad
@@ -124,13 +124,20 @@ 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) {
|
||||
return (DIFF_FILE_VALID(p->one) &&
|
||||
oidset_contains(o->objfind, &p->one->oid)) ||
|
||||
(DIFF_FILE_VALID(p->two) &&
|
||||
oidset_contains(o->objfind, &p->two->oid));
|
||||
}
|
||||
|
||||
if (!o->pickaxe[0])
|
||||
return 0;
|
||||
|
||||
if (o->flags.allow_textconv) {
|
||||
textconv_one = get_textconv(p->one);
|
||||
textconv_two = get_textconv(p->two);
|
||||
@@ -226,20 +233,22 @@ void diffcore_pickaxe(struct diff_options *o)
|
||||
cflags |= REG_ICASE;
|
||||
regcomp_or_die(®ex, needle, cflags);
|
||||
regexp = ®ex;
|
||||
} else if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE &&
|
||||
has_non_ascii(needle)) {
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
int cflags = REG_NEWLINE | REG_ICASE;
|
||||
} else if (opts & DIFF_PICKAXE_KIND_S) {
|
||||
if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE &&
|
||||
has_non_ascii(needle)) {
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
int cflags = REG_NEWLINE | REG_ICASE;
|
||||
|
||||
basic_regex_quote_buf(&sb, needle);
|
||||
regcomp_or_die(®ex, sb.buf, cflags);
|
||||
strbuf_release(&sb);
|
||||
regexp = ®ex;
|
||||
} else {
|
||||
kws = kwsalloc(o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE
|
||||
? tolower_trans_tbl : NULL);
|
||||
kwsincr(kws, needle, strlen(needle));
|
||||
kwsprep(kws);
|
||||
basic_regex_quote_buf(&sb, needle);
|
||||
regcomp_or_die(®ex, sb.buf, cflags);
|
||||
strbuf_release(&sb);
|
||||
regexp = ®ex;
|
||||
} else {
|
||||
kws = kwsalloc(o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE
|
||||
? tolower_trans_tbl : NULL);
|
||||
kwsincr(kws, needle, strlen(needle));
|
||||
kwsprep(kws);
|
||||
}
|
||||
}
|
||||
|
||||
/* Might want to warn when both S and G are on; I don't care... */
|
||||
@@ -248,7 +257,7 @@ void diffcore_pickaxe(struct diff_options *o)
|
||||
|
||||
if (regexp)
|
||||
regfree(regexp);
|
||||
else
|
||||
if (kws)
|
||||
kwsfree(kws);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user