git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
ec1ec82dd9112997ba1979076e9d3129165615d5 blob 3208 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
 
#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;
		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);
	}

	return 0;
}

static void external_odb_do_init(int force)
{
	static int initialized;

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

	git_config(external_odb_config, NULL);
}

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 (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 (!odb_helper_has_object(o, sha1))
			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 (odb_helper_get_direct(o, sha1) < 0)
			continue;
		return 0;
	}

	return -1;
}
debug log:

solving ec1ec82dd9 ...
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/11] 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...
10: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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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

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 ec1ec82dd9112997ba1979076e9d3129165615d5	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).