git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
80bc65e07d44958c78e54d767f4b91f66391091f blob 5472 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
238
239
240
241
242
 
/*
Copyright 2020 Google LLC

Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/

#include "iter.h"

#include "system.h"

#include "block.h"
#include "constants.h"
#include "reader.h"
#include "reftable.h"

int iterator_is_null(struct reftable_iterator *it)
{
	return it->ops == NULL;
}

static int empty_iterator_next(void *arg, struct reftable_record *rec)
{
	return 1;
}

static void empty_iterator_close(void *arg)
{
}

static struct reftable_iterator_vtable empty_vtable = {
	.next = &empty_iterator_next,
	.close = &empty_iterator_close,
};

void iterator_set_empty(struct reftable_iterator *it)
{
	assert(it->ops == NULL);
	it->iter_arg = NULL;
	it->ops = &empty_vtable;
}

int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
{
	return it->ops->next(it->iter_arg, rec);
}

void reftable_iterator_destroy(struct reftable_iterator *it)
{
	if (it->ops == NULL) {
		return;
	}
	it->ops->close(it->iter_arg);
	it->ops = NULL;
	FREE_AND_NULL(it->iter_arg);
}

int reftable_iterator_next_ref(struct reftable_iterator *it,
			       struct reftable_ref_record *ref)
{
	struct reftable_record rec = { NULL };
	reftable_record_from_ref(&rec, ref);
	return iterator_next(it, &rec);
}

int reftable_iterator_next_log(struct reftable_iterator *it,
			       struct reftable_log_record *log)
{
	struct reftable_record rec = { NULL };
	reftable_record_from_log(&rec, log);
	return iterator_next(it, &rec);
}

static void filtering_ref_iterator_close(void *iter_arg)
{
	struct filtering_ref_iterator *fri =
		(struct filtering_ref_iterator *)iter_arg;
	strbuf_release(&fri->oid);
	reftable_iterator_destroy(&fri->it);
}

static int filtering_ref_iterator_next(void *iter_arg,
				       struct reftable_record *rec)
{
	struct filtering_ref_iterator *fri =
		(struct filtering_ref_iterator *)iter_arg;
	struct reftable_ref_record *ref =
		(struct reftable_ref_record *)rec->data;
	int err = 0;
	while (1) {
		err = reftable_iterator_next_ref(&fri->it, ref);
		if (err != 0) {
			break;
		}

		if (fri->double_check) {
			struct reftable_iterator it = { NULL };

			err = reftable_table_seek_ref(&fri->tab, &it,
						      ref->refname);
			if (err == 0) {
				err = reftable_iterator_next_ref(&it, ref);
			}

			reftable_iterator_destroy(&it);

			if (err < 0) {
				break;
			}

			if (err > 0) {
				continue;
			}
		}

		if ((ref->target_value != NULL &&
		     !memcmp(fri->oid.buf, ref->target_value, fri->oid.len)) ||
		    (ref->value != NULL &&
		     !memcmp(fri->oid.buf, ref->value, fri->oid.len))) {
			return 0;
		}
	}

	reftable_ref_record_clear(ref);
	return err;
}

static struct reftable_iterator_vtable filtering_ref_iterator_vtable = {
	.next = &filtering_ref_iterator_next,
	.close = &filtering_ref_iterator_close,
};

void iterator_from_filtering_ref_iterator(struct reftable_iterator *it,
					  struct filtering_ref_iterator *fri)
{
	assert(it->ops == NULL);
	it->iter_arg = fri;
	it->ops = &filtering_ref_iterator_vtable;
}

static void indexed_table_ref_iter_close(void *p)
{
	struct indexed_table_ref_iter *it = (struct indexed_table_ref_iter *)p;
	block_iter_close(&it->cur);
	reftable_block_done(&it->block_reader.block);
	strbuf_release(&it->oid);
}

static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
{
	uint64_t off;
	int err = 0;
	if (it->offset_idx == it->offset_len) {
		it->is_finished = 1;
		return 1;
	}

	reftable_block_done(&it->block_reader.block);

	off = it->offsets[it->offset_idx++];
	err = reader_init_block_reader(it->r, &it->block_reader, off,
				       BLOCK_TYPE_REF);
	if (err < 0) {
		return err;
	}
	if (err > 0) {
		/* indexed block does not exist. */
		return REFTABLE_FORMAT_ERROR;
	}
	block_reader_start(&it->block_reader, &it->cur);
	return 0;
}

static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec)
{
	struct indexed_table_ref_iter *it = (struct indexed_table_ref_iter *)p;
	struct reftable_ref_record *ref =
		(struct reftable_ref_record *)rec->data;

	while (1) {
		int err = block_iter_next(&it->cur, rec);
		if (err < 0) {
			return err;
		}

		if (err > 0) {
			err = indexed_table_ref_iter_next_block(it);
			if (err < 0) {
				return err;
			}

			if (it->is_finished) {
				return 1;
			}
			continue;
		}

		if (!memcmp(it->oid.buf, ref->target_value, it->oid.len) ||
		    !memcmp(it->oid.buf, ref->value, it->oid.len)) {
			return 0;
		}
	}
}

int new_indexed_table_ref_iter(struct indexed_table_ref_iter **dest,
			       struct reftable_reader *r, uint8_t *oid,
			       int oid_len, uint64_t *offsets, int offset_len)
{
	struct indexed_table_ref_iter empty = INDEXED_TABLE_REF_ITER_INIT;
	struct indexed_table_ref_iter *itr =
		reftable_calloc(sizeof(struct indexed_table_ref_iter));
	int err = 0;

	*itr = empty;
	itr->r = r;
	strbuf_add(&itr->oid, oid, oid_len);

	itr->offsets = offsets;
	itr->offset_len = offset_len;

	err = indexed_table_ref_iter_next_block(itr);
	if (err < 0) {
		reftable_free(itr);
	} else {
		*dest = itr;
	}
	return err;
}

static struct reftable_iterator_vtable indexed_table_ref_iter_vtable = {
	.next = &indexed_table_ref_iter_next,
	.close = &indexed_table_ref_iter_close,
};

void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
					  struct indexed_table_ref_iter *itr)
{
	assert(it->ops == NULL);
	it->iter_arg = itr;
	it->ops = &indexed_table_ref_iter_vtable;
}
debug log:

solving 80bc65e07d ...
found 80bc65e07d in https://public-inbox.org/git/c535f838d62b90b4f24919323fdfaecfdadb2e2b.1601568664.git.gitgitgadget@gmail.com/
found 2cff447323 in https://public-inbox.org/git/eaf4629b-d8c4-0ddc-8c85-6600399a8229@ramsayjones.plus.com/ ||
	https://public-inbox.org/git/c196de7f0639f42133cf520c0e04db8a23c7e8ce.1601568664.git.gitgitgadget@gmail.com/
found 6631408ef8 in https://public-inbox.org/git/25259b683bc35b4f6741c1b2b07b41b99019c088.1600283416.git.gitgitgadget@gmail.com/

applying [1/4] https://public-inbox.org/git/25259b683bc35b4f6741c1b2b07b41b99019c088.1600283416.git.gitgitgadget@gmail.com/
diff --git a/reftable/iter.c b/reftable/iter.c
new file mode 100644
index 0000000000..6631408ef8


applying [2/4] https://public-inbox.org/git/eaf4629b-d8c4-0ddc-8c85-6600399a8229@ramsayjones.plus.com/
diff --git a/reftable/iter.c b/reftable/iter.c
index 6631408ef8..2cff447323 100644

Checking patch reftable/iter.c...
Applied patch reftable/iter.c cleanly.
Checking patch reftable/iter.c...
Applied patch reftable/iter.c cleanly.

skipping https://public-inbox.org/git/c196de7f0639f42133cf520c0e04db8a23c7e8ce.1601568664.git.gitgitgadget@gmail.com/ for 2cff447323
index at:
100644 2cff447323d2698228f4b60d19faa50b807fae34	reftable/iter.c

applying [3/4] https://public-inbox.org/git/c535f838d62b90b4f24919323fdfaecfdadb2e2b.1601568664.git.gitgitgadget@gmail.com/
diff --git a/reftable/iter.c b/reftable/iter.c
index 2cff447323..80bc65e07d 100644

Checking patch reftable/iter.c...
Applied patch reftable/iter.c cleanly.

index at:
100644 80bc65e07d44958c78e54d767f4b91f66391091f	reftable/iter.c

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).