2005-05-21 17:40:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Junio C Hamano
|
2010-08-24 01:17:03 +08:00
|
|
|
* Copyright (C) 2010 Google Inc.
|
2005-05-21 17:40:01 +08:00
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
2010-08-24 01:17:03 +08:00
|
|
|
#include "xdiff-interface.h"
|
Use kwset in pickaxe
Benchmarks in the hot cache case:
before:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
47,092,744 cache-misses # 2.825 M/sec ( +- 1.607% )
123,368,389 cache-references # 7.400 M/sec ( +- 0.812% )
330,040,998 branch-misses # 3.134 % ( +- 0.257% )
10,530,896,750 branches # 631.663 M/sec ( +- 0.121% )
62,037,201,030 instructions # 1.399 IPC ( +- 0.142% )
44,331,294,321 cycles # 2659.073 M/sec ( +- 0.326% )
96,794 page-faults # 0.006 M/sec ( +- 11.952% )
25 CPU-migrations # 0.000 M/sec ( +- 25.266% )
1,424 context-switches # 0.000 M/sec ( +- 0.540% )
16671.708650 task-clock-msecs # 0.997 CPUs ( +- 0.343% )
16.728692052 seconds time elapsed ( +- 0.344% )
after:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
51,385,522 cache-misses # 4.619 M/sec ( +- 0.565% )
129,177,880 cache-references # 11.611 M/sec ( +- 0.219% )
319,222,775 branch-misses # 6.946 % ( +- 0.134% )
4,595,913,233 branches # 413.086 M/sec ( +- 0.112% )
31,395,042,533 instructions # 1.062 IPC ( +- 0.129% )
29,558,348,598 cycles # 2656.740 M/sec ( +- 0.204% )
93,224 page-faults # 0.008 M/sec ( +- 4.487% )
19 CPU-migrations # 0.000 M/sec ( +- 10.425% )
950 context-switches # 0.000 M/sec ( +- 0.360% )
11125.796039 task-clock-msecs # 0.997 CPUs ( +- 0.239% )
11.164216599 seconds time elapsed ( +- 0.240% )
So the kwset code is about 33% faster.
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-21 06:41:57 +08:00
|
|
|
#include "kwset.h"
|
2016-06-25 13:22:37 +08:00
|
|
|
#include "commit.h"
|
|
|
|
#include "quote.h"
|
2010-08-24 01:17:03 +08:00
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
|
|
|
|
struct diff_options *o,
|
|
|
|
regex_t *regexp, kwset_t kws);
|
|
|
|
|
2010-08-24 01:17:03 +08:00
|
|
|
struct diffgrep_cb {
|
|
|
|
regex_t *regexp;
|
|
|
|
int hit;
|
|
|
|
};
|
|
|
|
|
2021-04-13 01:15:24 +08:00
|
|
|
static int diffgrep_consume(void *priv, char *line, unsigned long len)
|
2010-08-24 01:17:03 +08:00
|
|
|
{
|
|
|
|
struct diffgrep_cb *data = priv;
|
|
|
|
regmatch_t regmatch;
|
|
|
|
|
|
|
|
if (line[0] != '+' && line[0] != '-')
|
2021-04-13 01:15:24 +08:00
|
|
|
return 0;
|
2010-08-24 01:17:03 +08:00
|
|
|
if (data->hit)
|
|
|
|
/*
|
|
|
|
* NEEDSWORK: we should have a way to terminate the
|
|
|
|
* caller early.
|
|
|
|
*/
|
2021-04-13 01:15:24 +08:00
|
|
|
return 0;
|
2016-09-22 02:24:14 +08:00
|
|
|
data->hit = !regexec_buf(data->regexp, line + 1, len - 1, 1,
|
|
|
|
®match, 0);
|
2021-04-13 01:15:24 +08:00
|
|
|
return 0;
|
2010-08-24 01:17:03 +08:00
|
|
|
}
|
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
static int diff_grep(mmfile_t *one, mmfile_t *two,
|
|
|
|
struct diff_options *o,
|
2011-10-07 00:50:18 +08:00
|
|
|
regex_t *regexp, kwset_t kws)
|
2010-08-24 01:17:03 +08:00
|
|
|
{
|
|
|
|
regmatch_t regmatch;
|
2013-04-05 13:28:10 +08:00
|
|
|
struct diffgrep_cb ecbdata;
|
|
|
|
xpparam_t xpp;
|
|
|
|
xdemitconf_t xecfg;
|
2013-04-05 04:20:29 +08:00
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
if (!one)
|
2016-09-22 02:24:14 +08:00
|
|
|
return !regexec_buf(regexp, two->ptr, two->size,
|
|
|
|
1, ®match, 0);
|
2013-04-05 13:28:10 +08:00
|
|
|
if (!two)
|
2016-09-22 02:24:14 +08:00
|
|
|
return !regexec_buf(regexp, one->ptr, one->size,
|
|
|
|
1, ®match, 0);
|
2010-08-24 01:17:03 +08:00
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
/*
|
|
|
|
* We have both sides; need to run textual diff and see if
|
|
|
|
* the pattern appears on added/deleted lines.
|
|
|
|
*/
|
|
|
|
memset(&xpp, 0, sizeof(xpp));
|
|
|
|
memset(&xecfg, 0, sizeof(xecfg));
|
|
|
|
ecbdata.regexp = regexp;
|
|
|
|
ecbdata.hit = 0;
|
|
|
|
xecfg.ctxlen = o->context;
|
|
|
|
xecfg.interhunkctxlen = o->interhunkcontext;
|
2018-11-02 14:36:06 +08:00
|
|
|
if (xdi_diff_outf(one, two, discard_hunk_line, diffgrep_consume,
|
|
|
|
&ecbdata, &xpp, &xecfg))
|
react to errors in xdi_diff
When we call into xdiff to perform a diff, we generally lose
the return code completely. Typically by ignoring the return
of our xdi_diff wrapper, but sometimes we even propagate
that return value up and then ignore it later. This can
lead to us silently producing incorrect diffs (e.g., "git
log" might produce no output at all, not even a diff header,
for a content-level diff).
In practice this does not happen very often, because the
typical reason for xdiff to report failure is that it
malloc() failed (it uses straight malloc, and not our
xmalloc wrapper). But it could also happen when xdiff
triggers one our callbacks, which returns an error (e.g.,
outf() in builtin/rerere.c tries to report a write failure
in this way). And the next patch also plans to add more
failure modes.
Let's notice an error return from xdiff and react
appropriately. In most of the diff.c code, we can simply
die(), which matches the surrounding code (e.g., that is
what we do if we fail to load a file for diffing in the
first place). This is not that elegant, but we are probably
better off dying to let the user know there was a problem,
rather than simply generating bogus output.
We could also just die() directly in xdi_diff, but the
callers typically have a bit more context, and can provide a
better message (and if we do later decide to pass errors up,
we're one step closer to doing so).
There is one interesting case, which is in diff_grep(). Here
if we cannot generate the diff, there is nothing to match,
and we silently return "no hits". This is actually what the
existing code does already, but we make it a little more
explicit.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-25 07:12:23 +08:00
|
|
|
return 0;
|
2013-04-05 13:28:10 +08:00
|
|
|
return ecbdata.hit;
|
2010-08-24 01:17:03 +08:00
|
|
|
}
|
|
|
|
|
2021-04-13 01:15:23 +08:00
|
|
|
static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws,
|
|
|
|
unsigned int limit)
|
2005-05-21 17:40:01 +08:00
|
|
|
{
|
2021-04-13 01:15:17 +08:00
|
|
|
unsigned int cnt = 0;
|
|
|
|
unsigned long sz = mf->size;
|
|
|
|
const char *data = mf->ptr;
|
2005-07-24 07:35:25 +08:00
|
|
|
|
2006-03-29 08:16:33 +08:00
|
|
|
if (regexp) {
|
|
|
|
regmatch_t regmatch;
|
|
|
|
int flags = 0;
|
|
|
|
|
2021-04-13 01:15:21 +08:00
|
|
|
while (sz &&
|
2016-09-22 02:24:14 +08:00
|
|
|
!regexec_buf(regexp, data, sz, 1, ®match, flags)) {
|
2006-03-29 08:16:33 +08:00
|
|
|
flags |= REG_NOTBOL;
|
2009-03-17 02:38:42 +08:00
|
|
|
data += regmatch.rm_eo;
|
pickaxe: fix segfault with '-S<...> --pickaxe-regex'
'git {log,diff,...} -S<...> --pickaxe-regex' can segfault as a result
of out-of-bounds memory reads.
diffcore-pickaxe.c:contains() looks for all matches of the given regex
in a buffer in a loop, advancing the buffer pointer to the end of the
last match in each iteration. When we switched to REG_STARTEND in
b7d36ffca (regex: use regexec_buf(), 2016-09-21), we started passing
the size of that buffer to the regexp engine, too. Unfortunately,
this buffer size is never updated on subsequent iterations, and as the
buffer pointer advances on each iteration, this "bufptr+bufsize"
points past the end of the buffer. This results in segmentation
fault, if that memory can't be accessed. In case of 'git log' it can
also result in erroneously listed commits, if the memory past the end
of buffer is accessible and happens to contain data matching the
regex.
Reduce the buffer size on each iteration as the buffer pointer is
advanced, thus maintaining the correct end of buffer location.
Furthermore, make sure that the buffer pointer is not dereferenced in
the control flow statements when we already reached the end of the
buffer.
The new test is flaky, I've never seen it fail on my Linux box even
without the fix, but this is expected according to db5dfa3 (regex:
-G<pattern> feeds a non NUL-terminated string to regexec() and fails,
2016-09-21). However, it did fail on Travis CI with the first (and
incomplete) version of the fix, and based on that commit message I
would expect the new test without the fix to fail most of the time on
Windows.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-19 02:24:08 +08:00
|
|
|
sz -= regmatch.rm_eo;
|
2021-04-13 01:15:21 +08:00
|
|
|
if (sz && regmatch.rm_so == regmatch.rm_eo) {
|
2009-03-17 02:38:42 +08:00
|
|
|
data++;
|
pickaxe: fix segfault with '-S<...> --pickaxe-regex'
'git {log,diff,...} -S<...> --pickaxe-regex' can segfault as a result
of out-of-bounds memory reads.
diffcore-pickaxe.c:contains() looks for all matches of the given regex
in a buffer in a loop, advancing the buffer pointer to the end of the
last match in each iteration. When we switched to REG_STARTEND in
b7d36ffca (regex: use regexec_buf(), 2016-09-21), we started passing
the size of that buffer to the regexp engine, too. Unfortunately,
this buffer size is never updated on subsequent iterations, and as the
buffer pointer advances on each iteration, this "bufptr+bufsize"
points past the end of the buffer. This results in segmentation
fault, if that memory can't be accessed. In case of 'git log' it can
also result in erroneously listed commits, if the memory past the end
of buffer is accessible and happens to contain data matching the
regex.
Reduce the buffer size on each iteration as the buffer pointer is
advanced, thus maintaining the correct end of buffer location.
Furthermore, make sure that the buffer pointer is not dereferenced in
the control flow statements when we already reached the end of the
buffer.
The new test is flaky, I've never seen it fail on my Linux box even
without the fix, but this is expected according to db5dfa3 (regex:
-G<pattern> feeds a non NUL-terminated string to regexec() and fails,
2016-09-21). However, it did fail on Travis CI with the first (and
incomplete) version of the fix, and based on that commit message I
would expect the new test without the fix to fail most of the time on
Windows.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-19 02:24:08 +08:00
|
|
|
sz--;
|
|
|
|
}
|
2005-07-24 07:35:25 +08:00
|
|
|
cnt++;
|
2021-04-13 01:15:23 +08:00
|
|
|
|
|
|
|
if (limit && cnt == limit)
|
|
|
|
return cnt;
|
2005-07-24 07:35:25 +08:00
|
|
|
}
|
2006-03-29 08:16:33 +08:00
|
|
|
|
|
|
|
} else { /* Classic exact string match */
|
2009-03-03 07:00:55 +08:00
|
|
|
while (sz) {
|
2011-10-07 00:50:06 +08:00
|
|
|
struct kwsmatch kwsm;
|
|
|
|
size_t offset = kwsexec(kws, data, sz, &kwsm);
|
Use kwset in pickaxe
Benchmarks in the hot cache case:
before:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
47,092,744 cache-misses # 2.825 M/sec ( +- 1.607% )
123,368,389 cache-references # 7.400 M/sec ( +- 0.812% )
330,040,998 branch-misses # 3.134 % ( +- 0.257% )
10,530,896,750 branches # 631.663 M/sec ( +- 0.121% )
62,037,201,030 instructions # 1.399 IPC ( +- 0.142% )
44,331,294,321 cycles # 2659.073 M/sec ( +- 0.326% )
96,794 page-faults # 0.006 M/sec ( +- 11.952% )
25 CPU-migrations # 0.000 M/sec ( +- 25.266% )
1,424 context-switches # 0.000 M/sec ( +- 0.540% )
16671.708650 task-clock-msecs # 0.997 CPUs ( +- 0.343% )
16.728692052 seconds time elapsed ( +- 0.344% )
after:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
51,385,522 cache-misses # 4.619 M/sec ( +- 0.565% )
129,177,880 cache-references # 11.611 M/sec ( +- 0.219% )
319,222,775 branch-misses # 6.946 % ( +- 0.134% )
4,595,913,233 branches # 413.086 M/sec ( +- 0.112% )
31,395,042,533 instructions # 1.062 IPC ( +- 0.129% )
29,558,348,598 cycles # 2656.740 M/sec ( +- 0.204% )
93,224 page-faults # 0.008 M/sec ( +- 4.487% )
19 CPU-migrations # 0.000 M/sec ( +- 10.425% )
950 context-switches # 0.000 M/sec ( +- 0.360% )
11125.796039 task-clock-msecs # 0.997 CPUs ( +- 0.239% )
11.164216599 seconds time elapsed ( +- 0.240% )
So the kwset code is about 33% faster.
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-21 06:41:57 +08:00
|
|
|
if (offset == -1)
|
2009-03-03 07:00:55 +08:00
|
|
|
break;
|
2014-03-23 01:16:00 +08:00
|
|
|
sz -= offset + kwsm.size[0];
|
|
|
|
data += offset + kwsm.size[0];
|
2009-03-03 07:00:55 +08:00
|
|
|
cnt++;
|
2021-04-13 01:15:23 +08:00
|
|
|
|
|
|
|
if (limit && cnt == limit)
|
|
|
|
return cnt;
|
2006-03-29 08:16:33 +08:00
|
|
|
}
|
2005-07-24 07:35:25 +08:00
|
|
|
}
|
|
|
|
return cnt;
|
2005-05-21 17:40:01 +08:00
|
|
|
}
|
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
static int has_changes(mmfile_t *one, mmfile_t *two,
|
|
|
|
struct diff_options *o,
|
2011-10-07 00:50:06 +08:00
|
|
|
regex_t *regexp, kwset_t kws)
|
2013-04-05 13:28:10 +08:00
|
|
|
{
|
2021-04-13 01:15:23 +08:00
|
|
|
unsigned int c1 = one ? contains(one, regexp, kws, 0) : 0;
|
|
|
|
unsigned int c2 = two ? contains(two, regexp, kws, c1 + 1) : 0;
|
2021-04-13 01:15:22 +08:00
|
|
|
return c1 != c2;
|
2013-04-05 13:28:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
|
|
|
|
regex_t *regexp, kwset_t kws, pickaxe_fn fn)
|
2011-10-07 00:26:24 +08:00
|
|
|
{
|
2013-04-05 04:20:29 +08:00
|
|
|
struct userdiff_driver *textconv_one = NULL;
|
|
|
|
struct userdiff_driver *textconv_two = NULL;
|
2012-10-28 20:27:12 +08:00
|
|
|
mmfile_t mf1, mf2;
|
|
|
|
int ret;
|
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
/* ignore unmerged */
|
|
|
|
if (!DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two))
|
|
|
|
return 0;
|
|
|
|
|
2018-01-05 06:50:42 +08:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-11-01 02:19:11 +08:00
|
|
|
if (o->flags.allow_textconv) {
|
2018-11-10 13:49:06 +08:00
|
|
|
textconv_one = get_textconv(o->repo, p->one);
|
|
|
|
textconv_two = get_textconv(o->repo, p->two);
|
2013-04-05 21:16:30 +08:00
|
|
|
}
|
2013-04-05 04:20:29 +08:00
|
|
|
|
2012-10-28 20:27:12 +08:00
|
|
|
/*
|
|
|
|
* If we have an unmodified pair, we know that the count will be the
|
|
|
|
* same and don't even have to load the blobs. Unless textconv is in
|
|
|
|
* play, _and_ we are using two different textconv filters (e.g.,
|
|
|
|
* because a pair is an exact rename with different textconv attributes
|
|
|
|
* for each side, which might generate different content).
|
|
|
|
*/
|
|
|
|
if (textconv_one == textconv_two && diff_unmodified_pair(p))
|
|
|
|
return 0;
|
|
|
|
|
2018-12-15 02:49:12 +08:00
|
|
|
if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
|
|
|
|
!o->flags.text &&
|
|
|
|
((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
|
|
|
|
(!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
|
|
|
|
return 0;
|
|
|
|
|
2018-09-21 23:57:22 +08:00
|
|
|
mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
|
|
|
|
mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
|
2012-10-28 20:27:12 +08:00
|
|
|
|
2013-04-05 13:28:10 +08:00
|
|
|
ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
|
|
|
|
DIFF_FILE_VALID(p->two) ? &mf2 : NULL,
|
|
|
|
o, regexp, kws);
|
2012-10-28 20:27:12 +08:00
|
|
|
|
|
|
|
if (textconv_one)
|
|
|
|
free(mf1.ptr);
|
|
|
|
if (textconv_two)
|
|
|
|
free(mf2.ptr);
|
|
|
|
diff_free_filespec_data(p->one);
|
|
|
|
diff_free_filespec_data(p->two);
|
|
|
|
|
|
|
|
return ret;
|
2011-10-07 00:26:24 +08:00
|
|
|
}
|
|
|
|
|
2014-03-23 01:15:58 +08:00
|
|
|
static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
|
|
|
|
regex_t *regexp, kwset_t kws, pickaxe_fn fn)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct diff_queue_struct outq;
|
|
|
|
|
|
|
|
DIFF_QUEUE_CLEAR(&outq);
|
|
|
|
|
|
|
|
if (o->pickaxe_opts & DIFF_PICKAXE_ALL) {
|
|
|
|
/* Showing the whole changeset if needle exists */
|
|
|
|
for (i = 0; i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
if (pickaxe_match(p, o, regexp, kws, fn))
|
|
|
|
return; /* do not munge the queue */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise we will clear the whole queue by copying
|
|
|
|
* the empty outq at the end of this function, but
|
|
|
|
* first clear the current entries in the queue.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < q->nr; i++)
|
|
|
|
diff_free_filepair(q->queue[i]);
|
|
|
|
} else {
|
|
|
|
/* Showing only the filepairs that has the needle */
|
|
|
|
for (i = 0; i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
if (pickaxe_match(p, o, regexp, kws, fn))
|
|
|
|
diff_q(&outq, p);
|
|
|
|
else
|
|
|
|
diff_free_filepair(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(q->queue);
|
|
|
|
*q = outq;
|
|
|
|
}
|
|
|
|
|
2016-06-25 13:22:36 +08:00
|
|
|
static void regcomp_or_die(regex_t *regex, const char *needle, int cflags)
|
|
|
|
{
|
|
|
|
int err = regcomp(regex, needle, cflags);
|
|
|
|
if (err) {
|
|
|
|
/* The POSIX.2 people are surely sick */
|
|
|
|
char errbuf[1024];
|
|
|
|
regerror(err, regex, errbuf, 1024);
|
|
|
|
die("invalid regex: %s", errbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-23 01:15:57 +08:00
|
|
|
void diffcore_pickaxe(struct diff_options *o)
|
2005-05-21 17:40:01 +08:00
|
|
|
{
|
2010-09-01 04:44:39 +08:00
|
|
|
const char *needle = o->pickaxe;
|
|
|
|
int opts = o->pickaxe_opts;
|
2006-03-29 08:16:33 +08:00
|
|
|
regex_t regex, *regexp = NULL;
|
Use kwset in pickaxe
Benchmarks in the hot cache case:
before:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
47,092,744 cache-misses # 2.825 M/sec ( +- 1.607% )
123,368,389 cache-references # 7.400 M/sec ( +- 0.812% )
330,040,998 branch-misses # 3.134 % ( +- 0.257% )
10,530,896,750 branches # 631.663 M/sec ( +- 0.121% )
62,037,201,030 instructions # 1.399 IPC ( +- 0.142% )
44,331,294,321 cycles # 2659.073 M/sec ( +- 0.326% )
96,794 page-faults # 0.006 M/sec ( +- 11.952% )
25 CPU-migrations # 0.000 M/sec ( +- 25.266% )
1,424 context-switches # 0.000 M/sec ( +- 0.540% )
16671.708650 task-clock-msecs # 0.997 CPUs ( +- 0.343% )
16.728692052 seconds time elapsed ( +- 0.344% )
after:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
51,385,522 cache-misses # 4.619 M/sec ( +- 0.565% )
129,177,880 cache-references # 11.611 M/sec ( +- 0.219% )
319,222,775 branch-misses # 6.946 % ( +- 0.134% )
4,595,913,233 branches # 413.086 M/sec ( +- 0.112% )
31,395,042,533 instructions # 1.062 IPC ( +- 0.129% )
29,558,348,598 cycles # 2656.740 M/sec ( +- 0.204% )
93,224 page-faults # 0.008 M/sec ( +- 4.487% )
19 CPU-migrations # 0.000 M/sec ( +- 10.425% )
950 context-switches # 0.000 M/sec ( +- 0.360% )
11125.796039 task-clock-msecs # 0.997 CPUs ( +- 0.239% )
11.164216599 seconds time elapsed ( +- 0.240% )
So the kwset code is about 33% faster.
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-21 06:41:57 +08:00
|
|
|
kwset_t kws = NULL;
|
2021-04-13 01:15:19 +08:00
|
|
|
pickaxe_fn fn;
|
2005-05-21 17:40:01 +08:00
|
|
|
|
2021-04-13 01:15:20 +08:00
|
|
|
if (opts & ~DIFF_PICKAXE_KIND_OBJFIND &&
|
|
|
|
(!needle || !*needle))
|
|
|
|
BUG("should have needle under -G or -S");
|
2014-03-23 01:15:57 +08:00
|
|
|
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
|
2014-03-23 01:15:56 +08:00
|
|
|
int cflags = REG_EXTENDED | REG_NEWLINE;
|
2018-01-05 06:50:40 +08:00
|
|
|
if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE)
|
2014-03-23 01:15:56 +08:00
|
|
|
cflags |= REG_ICASE;
|
2016-06-25 13:22:36 +08:00
|
|
|
regcomp_or_die(®ex, needle, cflags);
|
2006-03-29 08:16:33 +08:00
|
|
|
regexp = ®ex;
|
2021-04-13 01:15:19 +08:00
|
|
|
|
|
|
|
if (opts & DIFF_PICKAXE_KIND_G)
|
|
|
|
fn = diff_grep;
|
|
|
|
else if (opts & DIFF_PICKAXE_REGEX)
|
|
|
|
fn = has_changes;
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* We don't need to check the combination of
|
|
|
|
* -G and --pickaxe-regex, by the time we get
|
|
|
|
* here diff.c has already died if they're
|
|
|
|
* combined. See the usage tests in
|
|
|
|
* t4209-log-pickaxe.sh.
|
|
|
|
*/
|
|
|
|
BUG("unreachable");
|
2018-01-05 06:50:42 +08:00
|
|
|
} 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);
|
|
|
|
}
|
2021-04-13 01:15:19 +08:00
|
|
|
fn = has_changes;
|
|
|
|
} else if (opts & DIFF_PICKAXE_KIND_OBJFIND) {
|
|
|
|
fn = NULL;
|
|
|
|
} else {
|
|
|
|
BUG("unknown pickaxe_opts flag");
|
2006-03-29 08:16:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-13 01:15:19 +08:00
|
|
|
pickaxe(&diff_queued_diff, o, regexp, kws, fn);
|
2011-10-07 00:23:11 +08:00
|
|
|
|
2014-03-23 01:15:57 +08:00
|
|
|
if (regexp)
|
|
|
|
regfree(regexp);
|
2018-01-05 06:50:42 +08:00
|
|
|
if (kws)
|
Use kwset in pickaxe
Benchmarks in the hot cache case:
before:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
47,092,744 cache-misses # 2.825 M/sec ( +- 1.607% )
123,368,389 cache-references # 7.400 M/sec ( +- 0.812% )
330,040,998 branch-misses # 3.134 % ( +- 0.257% )
10,530,896,750 branches # 631.663 M/sec ( +- 0.121% )
62,037,201,030 instructions # 1.399 IPC ( +- 0.142% )
44,331,294,321 cycles # 2659.073 M/sec ( +- 0.326% )
96,794 page-faults # 0.006 M/sec ( +- 11.952% )
25 CPU-migrations # 0.000 M/sec ( +- 25.266% )
1,424 context-switches # 0.000 M/sec ( +- 0.540% )
16671.708650 task-clock-msecs # 0.997 CPUs ( +- 0.343% )
16.728692052 seconds time elapsed ( +- 0.344% )
after:
$ perf stat --repeat=5 git log -Sqwerty
Performance counter stats for 'git log -Sqwerty' (5 runs):
51,385,522 cache-misses # 4.619 M/sec ( +- 0.565% )
129,177,880 cache-references # 11.611 M/sec ( +- 0.219% )
319,222,775 branch-misses # 6.946 % ( +- 0.134% )
4,595,913,233 branches # 413.086 M/sec ( +- 0.112% )
31,395,042,533 instructions # 1.062 IPC ( +- 0.129% )
29,558,348,598 cycles # 2656.740 M/sec ( +- 0.204% )
93,224 page-faults # 0.008 M/sec ( +- 4.487% )
19 CPU-migrations # 0.000 M/sec ( +- 10.425% )
950 context-switches # 0.000 M/sec ( +- 0.360% )
11125.796039 task-clock-msecs # 0.997 CPUs ( +- 0.239% )
11.164216599 seconds time elapsed ( +- 0.240% )
So the kwset code is about 33% faster.
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-21 06:41:57 +08:00
|
|
|
kwsfree(kws);
|
2005-05-21 17:40:01 +08:00
|
|
|
return;
|
|
|
|
}
|