git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
de2ae70db19c1929dc1540d4d1e099d5336420ed blob 4579 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
 
#include "cache.h"
#include "external-odb.h"
#include "odb-helper.h"
#include "config.h"

static struct odb_helper *helpers;
static struct odb_helper **helpers_tail = &helpers;

static struct odb_helper *find_or_create_helper(const char *name, int len)
{
	struct odb_helper *o;

	for (o = helpers; o; o = o->next)
		if (!strncmp(o->name, name, len) && !o->name[len])
			return o;

	o = odb_helper_new(name, len);
	*helpers_tail = o;
	helpers_tail = &o->next;

	return o;
}

static int external_odb_config(const char *var, const char *value, void *data)
{
	struct odb_helper *o;
	const char *name;
	int namelen;
	const char *subkey;

	if (parse_config_key(var, "odb", &name, &namelen, &subkey) < 0)
		return 0;

	o = find_or_create_helper(name, namelen);

	if (!strcmp(subkey, "promisorremote")) {
		o->type = ODB_HELPER_GIT_REMOTE;
		o->supported_capabilities |= ODB_HELPER_CAP_HAVE;
		o->supported_capabilities |= ODB_HELPER_CAP_GET_DIRECT;
		return git_config_string(&o->dealer, var, value);
	}
	if (!strcmp(subkey, "scriptcommand")) {
		o->type = ODB_HELPER_SCRIPT_CMD;
		return git_config_string(&o->dealer, var, value);
	}
	if (!strcmp(subkey, "subprocesscommand")) {
		o->type = ODB_HELPER_SUBPROCESS_CMD;
		return git_config_string(&o->dealer, var, value);
	}
	if (!strcmp(subkey, "partialclonefilter"))
		return git_config_string(&o->partial_clone_filter, var, value);

	return 0;
}

static void external_odb_do_init(int force)
{
	static int initialized;
	struct odb_helper *o;

	if ((!force && initialized) || !use_external_odb)
		return;
	initialized = 1;

	git_config(external_odb_config, NULL);

	for (o = helpers; o; o = o->next)
		odb_helper_init(o);
}

static inline void external_odb_init(void)
{
	external_odb_do_init(0);
}

inline void external_odb_reinit(void)
{
	external_odb_do_init(1);
}

int has_external_odb(void)
{
	external_odb_init();

	return !!helpers;
}

struct odb_helper *find_odb_helper(const char *dealer, enum odb_helper_type type)
{
	struct odb_helper *o;

	external_odb_init();

	for (o = helpers; o; o = o->next)
		if (!strcmp(o->dealer, dealer) && o->type == type)
			return o;

	return NULL;
}

const char *external_odb_root(void)
{
	static const char *root;
	if (!root)
		root = git_pathdup("objects/external");
	return root;
}

int external_odb_has_object(const unsigned char *sha1)
{
	struct odb_helper *o;

	external_odb_init();

	for (o = helpers; o; o = o->next) {
		if (!(o->supported_capabilities & ODB_HELPER_CAP_HAVE))
			return 1;
		if (odb_helper_has_object(o, sha1))
			return 1;
	}
	return 0;
}

int external_odb_get_object(const unsigned char *sha1)
{
	struct odb_helper *o;
	struct strbuf pathbuf = STRBUF_INIT;

	if (!external_odb_has_object(sha1))
		return -1;

	sha1_file_name_alt(&pathbuf, external_odb_root(), sha1);
	safe_create_leading_directories_const(pathbuf.buf);
	prepare_external_alt_odb();

	for (o = helpers; o; o = o->next) {
		struct strbuf tmpfile = STRBUF_INIT;
		int ret;
		int fd;

		if (!(o->supported_capabilities & ODB_HELPER_CAP_GET_RAW_OBJ) &&
		    !(o->supported_capabilities & ODB_HELPER_CAP_GET_GIT_OBJ))
			continue;

		fd = create_object_tmpfile(&tmpfile, pathbuf.buf);
		if (fd < 0) {
			strbuf_release(&tmpfile);
			strbuf_release(&pathbuf);
			return -1;
		}

		if (odb_helper_get_object(o, sha1, fd) < 0) {
			close(fd);
			unlink(tmpfile.buf);
			strbuf_release(&tmpfile);
			continue;
		}

		close_sha1_file(fd);
		ret = finalize_object_file(tmpfile.buf, pathbuf.buf);
		strbuf_release(&tmpfile);
		strbuf_release(&pathbuf);
		if (!ret)
			return 0;
	}

	strbuf_release(&pathbuf);

	return -1;
}

int external_odb_get_direct(const unsigned char *sha1)
{
	struct odb_helper *o;

	external_odb_init();

	for (o = helpers; o; o = o->next) {
		if (!(o->supported_capabilities & ODB_HELPER_CAP_GET_DIRECT))
			continue;
		if (odb_helper_get_direct(o, sha1) < 0)
			continue;
		return 0;
	}

	return -1;
}

int external_odb_get_many_direct(const struct oid_array *to_get)
{
	struct odb_helper *o;

	external_odb_init();

	for (o = helpers; o; o = o->next) {
		if (!(o->supported_capabilities & ODB_HELPER_CAP_GET_DIRECT))
			continue;
		if (odb_helper_get_many_direct(o, to_get) < 0)
			continue;
		return 0;
	}

	return -1;
}

int external_odb_put_object(const void *buf, size_t len,
			    const char *type, unsigned char *sha1)
{
	struct odb_helper *o;

	external_odb_init();

	/* For now accept only blobs */
	if (strcmp(type, "blob"))
		return 1;

	for (o = helpers; o; o = o->next) {
		int r = odb_helper_put_object(o, buf, len, type, sha1);
		if (r <= 0)
			return r;
	}
	return 1;
}
debug log:

solving de2ae70db1 ...
found de2ae70db1 in https://public-inbox.org/git/20180319133147.15413-19-chriscool@tuxfamily.org/
found 806dc8e699 in https://public-inbox.org/git/20180319133147.15413-18-chriscool@tuxfamily.org/
found 192b09e843 in https://public-inbox.org/git/20180319133147.15413-16-chriscool@tuxfamily.org/
found c3d90f39fb in https://public-inbox.org/git/20180319133147.15413-15-chriscool@tuxfamily.org/
found 8be92277d2 in https://public-inbox.org/git/20180319133147.15413-13-chriscool@tuxfamily.org/
found ae6bc017fe in https://public-inbox.org/git/20180319133147.15413-12-chriscool@tuxfamily.org/
found 9f797d66f4 in https://public-inbox.org/git/20180319133147.15413-11-chriscool@tuxfamily.org/
found ec1ec82dd9 in https://public-inbox.org/git/20180319133147.15413-10-chriscool@tuxfamily.org/
found 82ac80aa04 in https://public-inbox.org/git/20180319133147.15413-9-chriscool@tuxfamily.org/
found 9c77180d6c in https://public-inbox.org/git/20180319133147.15413-8-chriscool@tuxfamily.org/
found 5d0afb9762 in https://public-inbox.org/git/20180319133147.15413-6-chriscool@tuxfamily.org/ ||
	https://public-inbox.org/git/20180103163403.11303-11-chriscool@tuxfamily.org/
found d26e63d8b1 in https://public-inbox.org/git/20180319133147.15413-5-chriscool@tuxfamily.org/ ||
	https://public-inbox.org/git/20180103163403.11303-4-chriscool@tuxfamily.org/
found 390958dbfe in https://public-inbox.org/git/20180319133147.15413-4-chriscool@tuxfamily.org/ ||
	https://public-inbox.org/git/20180103163403.11303-3-chriscool@tuxfamily.org/
found f3ea491333 in https://public-inbox.org/git/20180319133147.15413-2-chriscool@tuxfamily.org/ ||
	https://public-inbox.org/git/20180103163403.11303-2-chriscool@tuxfamily.org/

applying [1/18] https://public-inbox.org/git/20180319133147.15413-2-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
new file mode 100644
index 0000000000..f3ea491333

Checking patch external-odb.c...
17:78: new blank line at EOF.
+
Applied patch external-odb.c cleanly.
warning: 1 line adds whitespace errors.

skipping https://public-inbox.org/git/20180103163403.11303-2-chriscool@tuxfamily.org/ for f3ea491333
index at:
100644 f3ea4913339d88091227fb073a5603625d93848e	external-odb.c

applying [2/18] https://public-inbox.org/git/20180319133147.15413-4-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index f3ea491333..390958dbfe 100644

Checking patch external-odb.c...
Applied patch external-odb.c cleanly.

skipping https://public-inbox.org/git/20180103163403.11303-3-chriscool@tuxfamily.org/ for 390958dbfe
index at:
100644 390958dbfec20409e7b9aade6993ace6ff688605	external-odb.c

applying [3/18] https://public-inbox.org/git/20180319133147.15413-5-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 390958dbfe..d26e63d8b1 100644

Checking patch external-odb.c...
Applied patch external-odb.c cleanly.

skipping https://public-inbox.org/git/20180103163403.11303-4-chriscool@tuxfamily.org/ for d26e63d8b1
index at:
100644 d26e63d8b1dcba756b374bea0ff58de864215ca9	external-odb.c

applying [4/18] https://public-inbox.org/git/20180319133147.15413-6-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index d26e63d8b1..5d0afb9762 100644

Checking patch external-odb.c...
Applied patch external-odb.c cleanly.

skipping https://public-inbox.org/git/20180103163403.11303-11-chriscool@tuxfamily.org/ for 5d0afb9762
index at:
100644 5d0afb9762069b8351adc104eec6ae945df3cc40	external-odb.c

applying [5/18] https://public-inbox.org/git/20180319133147.15413-8-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 5d0afb9762..9c77180d6c 100644


applying [6/18] https://public-inbox.org/git/20180319133147.15413-9-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 9c77180d6c..82ac80aa04 100644


applying [7/18] https://public-inbox.org/git/20180319133147.15413-10-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 82ac80aa04..ec1ec82dd9 100644


applying [8/18] https://public-inbox.org/git/20180319133147.15413-11-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index ec1ec82dd9..9f797d66f4 100644


applying [9/18] https://public-inbox.org/git/20180319133147.15413-12-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 9f797d66f4..ae6bc017fe 100644


applying [10/18] https://public-inbox.org/git/20180319133147.15413-13-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index ae6bc017fe..8be92277d2 100644


applying [11/18] https://public-inbox.org/git/20180319133147.15413-15-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 8be92277d2..c3d90f39fb 100644


applying [12/18] https://public-inbox.org/git/20180319133147.15413-16-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index c3d90f39fb..192b09e843 100644


applying [13/18] https://public-inbox.org/git/20180319133147.15413-18-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 192b09e843..806dc8e699 100644


applying [14/18] https://public-inbox.org/git/20180319133147.15413-19-chriscool@tuxfamily.org/
diff --git a/external-odb.c b/external-odb.c
index 806dc8e699..de2ae70db1 100644

Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.
Checking patch external-odb.c...
Applied patch external-odb.c cleanly.

index at:
100644 de2ae70db19c1929dc1540d4d1e099d5336420ed	external-odb.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).