git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
86b1005802bf3462b61dd9a51980877b179b7ab7 blob 5784 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
#include "git-compat-util.h"
#include "bloom.h"
#include "commit.h"
#include "commit-slab.h"
#include "commit-graph.h"
#include "object-store.h"
#include "diff.h"
#include "diffcore.h"
#include "revision.h"
#include "hashmap.h"

#define BITS_PER_BLOCK 64

define_commit_slab(bloom_filter_slab, struct bloom_filter);

struct bloom_filter_slab bloom_filters;

struct pathmap_hash_entry {
    struct hashmap_entry entry;
    const char path[FLEX_ARRAY];
};

static uint32_t rotate_right(uint32_t value, int32_t count)
{
	uint32_t mask = 8 * sizeof(uint32_t) - 1;
	count &= mask;
	return ((value >> count) | (value << ((-count) & mask)));
}

static uint32_t seed_murmur3(uint32_t seed, const char *data, int len)
{
	const uint32_t c1 = 0xcc9e2d51;
	const uint32_t c2 = 0x1b873593;
	const int32_t r1 = 15;
	const int32_t r2 = 13;
	const uint32_t m = 5;
	const uint32_t n = 0xe6546b64;
	int i;
	uint32_t k1 = 0;
	const char *tail;

	int len4 = len / sizeof(uint32_t);

	const uint32_t *blocks = (const uint32_t*)data;

	uint32_t k;
	for (i = 0; i < len4; i++)
	{
		k = blocks[i];
		k *= c1;
		k = rotate_right(k, r1);
		k *= c2;

		seed ^= k;
		seed = rotate_right(seed, r2) * m + n;
	}

	tail = (data + len4 * sizeof(uint32_t));

	switch (len & (sizeof(uint32_t) - 1))
	{
	case 3:
		k1 ^= ((uint32_t)tail[2]) << 16;
		/*-fallthrough*/
	case 2:
		k1 ^= ((uint32_t)tail[1]) << 8;
		/*-fallthrough*/
	case 1:
		k1 ^= ((uint32_t)tail[0]) << 0;
		k1 *= c1;
		k1 = rotate_right(k1, r1);
		k1 *= c2;
		seed ^= k1;
		break;
	}

	seed ^= (uint32_t)len;
	seed ^= (seed >> 16);
	seed *= 0x85ebca6b;
	seed ^= (seed >> 13);
	seed *= 0xc2b2ae35;
	seed ^= (seed >> 16);

	return seed;
}

static inline uint64_t get_bitmask(uint32_t pos)
{
	return ((uint64_t)1) << (pos & (BITS_PER_BLOCK - 1));
}

void fill_bloom_key(const char *data,
		    int len,
		    struct bloom_key *key,
		    struct bloom_filter_settings *settings)
{
	int i;
	uint32_t seed0 = 0x293ae76f;
	uint32_t seed1 = 0x7e646e2c;

	uint32_t hash0 = seed_murmur3(seed0, data, len);
	uint32_t hash1 = seed_murmur3(seed1, data, len);

	key->hashes = (uint32_t *)xcalloc(settings->num_hashes, sizeof(uint32_t));
	for (i = 0; i < settings->num_hashes; i++)
		key->hashes[i] = hash0 + i * hash1;
}

static void add_key_to_filter(struct bloom_key *key,
			      struct bloom_filter *filter,
			      struct bloom_filter_settings *settings)
{
	int i;
	uint64_t mod = filter->len * BITS_PER_BLOCK;

	for (i = 0; i < settings->num_hashes; i++) {
		uint64_t hash_mod = key->hashes[i] % mod;
		uint64_t block_pos = hash_mod / BITS_PER_BLOCK;

		filter->data[block_pos] |= get_bitmask(hash_mod);
	}
}

static void fill_filter_from_graph(struct commit_graph *g,
				   struct bloom_filter *filter,
				   struct commit *c)
{
	uint32_t lex_pos, prev_index, next_index;

	while (c->graph_pos < g->num_commits_in_base)
		g = g->base_graph;

	lex_pos = c->graph_pos - g->num_commits_in_base;

	next_index = get_be32(g->chunk_bloom_indexes + 4 * lex_pos);
	if (lex_pos)
		prev_index = get_be32(g->chunk_bloom_indexes + 4 * (lex_pos - 1));
	else
		prev_index = 0;

	filter->len = next_index - prev_index;
	filter->data = (uint64_t *)(g->chunk_bloom_data + 8 * prev_index + 12);
}

void load_bloom_filters(void)
{
	init_bloom_filter_slab(&bloom_filters);
}

struct bloom_filter *get_bloom_filter(struct repository *r,
				      struct commit *c,
				      int compute_if_null)
{
	struct bloom_filter *filter;
	struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
	int i;
	struct rev_info revs;
	const char *revs_argv[] = {NULL, "HEAD", NULL};

	filter = bloom_filter_slab_at(&bloom_filters, c);

	if (!filter->data) {
		load_commit_graph_info(r, c);
		if (c->graph_pos != COMMIT_NOT_FROM_GRAPH && r->objects->commit_graph->chunk_bloom_indexes) {
			fill_filter_from_graph(r->objects->commit_graph, filter, c);
			return filter;
		}
	}

	if (filter->data || !compute_if_null)
			return filter;

	init_revisions(&revs, NULL);
	revs.diffopt.flags.recursive = 1;

	setup_revisions(2, revs_argv, &revs, NULL);

	if (c->parents)
		diff_tree_oid(&c->parents->item->object.oid, &c->object.oid, "", &revs.diffopt);
	else
		diff_tree_oid(NULL, &c->object.oid, "", &revs.diffopt);
	diffcore_std(&revs.diffopt);

	if (diff_queued_diff.nr <= 512) {
		struct hashmap pathmap;
		struct pathmap_hash_entry* e;
		struct hashmap_iter iter;
		hashmap_init(&pathmap, NULL, NULL, 0);

		for (i = 0; i < diff_queued_diff.nr; i++) {
		    const char* path = diff_queued_diff.queue[i]->two->path;
		    const char* p = path;

		    /*
		     * Add each leading directory of the changed file, i.e. for
		     * 'dir/subdir/file' add 'dir' and 'dir/subdir' as well, so
		     * the Bloom filter could be used to speed up commands like
		     * 'git log dir/subdir', too.
		     *
		     * Note that directories are added without the trailing '/'.
		     */
		    do {
				char* last_slash = strrchr(p, '/');

				FLEX_ALLOC_STR(e, path, path);
				hashmap_entry_init(&e->entry, strhash(p));
				hashmap_add(&pathmap, &e->entry);

				if (!last_slash)
				    last_slash = (char*)p;
				*last_slash = '\0';

		    } while (*p);

		    diff_free_filepair(diff_queued_diff.queue[i]);
		}

		filter->len = (hashmap_get_size(&pathmap) * settings.bits_per_entry + BITS_PER_BLOCK - 1) / BITS_PER_BLOCK;
		filter->data = xcalloc(filter->len, sizeof(uint64_t));

		hashmap_for_each_entry(&pathmap, &iter, e, entry) {
		    struct bloom_key key;
		    fill_bloom_key(e->path, strlen(e->path), &key, &settings);
		    add_key_to_filter(&key, filter, &settings);
		}

		hashmap_free_entries(&pathmap, struct pathmap_hash_entry, entry);
	} else {
		filter->data = NULL;
		filter->len = 0;
	}

	free(diff_queued_diff.queue);
	DIFF_QUEUE_CLEAR(&diff_queued_diff);

	return filter;
}
debug log:

solving 86b1005802 ...
found 86b1005802 in https://public-inbox.org/git/1e2acb37ad710cb0d1c09ed163fdd4473a27335c.1576879520.git.gitgitgadget@gmail.com/
found 08328cc381 in https://public-inbox.org/git/e52c7ad37a306891487bd79a09b040bfb657d723.1576879520.git.gitgitgadget@gmail.com/

applying [1/2] https://public-inbox.org/git/e52c7ad37a306891487bd79a09b040bfb657d723.1576879520.git.gitgitgadget@gmail.com/
diff --git a/bloom.c b/bloom.c
new file mode 100644
index 0000000000..08328cc381


applying [2/2] https://public-inbox.org/git/1e2acb37ad710cb0d1c09ed163fdd4473a27335c.1576879520.git.gitgitgadget@gmail.com/
diff --git a/bloom.c b/bloom.c
index 08328cc381..86b1005802 100644

Checking patch bloom.c...
Applied patch bloom.c cleanly.
Checking patch bloom.c...
Applied patch bloom.c cleanly.

index at:
100644 86b1005802bf3462b61dd9a51980877b179b7ab7	bloom.c

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git