Skip to content

Commit dcc8b4e

Browse files
chriscoolgitster
authored andcommitted
promisor-remote: implement promisor_remote_get_direct()
This is implemented for now by calling fetch_objects(). It fetches from all the promisor remotes. Helped-by: Ramsay Jones <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5424870 commit dcc8b4e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

promisor-remote.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "cache.h"
2+
#include "object-store.h"
23
#include "promisor-remote.h"
34
#include "config.h"
5+
#include "fetch-object.h"
46

57
static struct promisor_remote *promisors;
68
static struct promisor_remote **promisors_tail = &promisors;
@@ -90,3 +92,67 @@ int has_promisor_remote(void)
9092
{
9193
return !!promisor_remote_find(NULL);
9294
}
95+
96+
static int remove_fetched_oids(struct object_id **oids, int oid_nr, int to_free)
97+
{
98+
int i, missing_nr = 0;
99+
int *missing = xcalloc(oid_nr, sizeof(*missing));
100+
struct object_id *old_oids = *oids;
101+
struct object_id *new_oids;
102+
int old_fetch_if_missing = fetch_if_missing;
103+
104+
fetch_if_missing = 0;
105+
106+
for (i = 0; i < oid_nr; i++)
107+
if (oid_object_info_extended(the_repository, &old_oids[i], NULL, 0)) {
108+
missing[i] = 1;
109+
missing_nr++;
110+
}
111+
112+
fetch_if_missing = old_fetch_if_missing;
113+
114+
if (missing_nr) {
115+
int j = 0;
116+
new_oids = xcalloc(missing_nr, sizeof(*new_oids));
117+
for (i = 0; i < oid_nr; i++)
118+
if (missing[i])
119+
oidcpy(&new_oids[j++], &old_oids[i]);
120+
*oids = new_oids;
121+
if (to_free)
122+
free(old_oids);
123+
}
124+
125+
free(missing);
126+
127+
return missing_nr;
128+
}
129+
130+
int promisor_remote_get_direct(const struct object_id *oids, int oid_nr)
131+
{
132+
struct promisor_remote *r;
133+
struct object_id *missing_oids = (struct object_id *)oids;
134+
int missing_nr = oid_nr;
135+
int to_free = 0;
136+
int res = -1;
137+
138+
promisor_remote_init();
139+
140+
for (r = promisors; r; r = r->next) {
141+
if (fetch_objects(r->name, missing_oids, missing_nr) < 0) {
142+
if (missing_nr == 1)
143+
continue;
144+
missing_nr = remove_fetched_oids(&missing_oids, missing_nr, to_free);
145+
if (missing_nr) {
146+
to_free = 1;
147+
continue;
148+
}
149+
}
150+
res = 0;
151+
break;
152+
}
153+
154+
if (to_free)
155+
free(missing_oids);
156+
157+
return res;
158+
}

promisor-remote.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef PROMISOR_REMOTE_H
22
#define PROMISOR_REMOTE_H
33

4+
struct object_id;
5+
46
/*
57
* Promisor remote linked list
68
* Its information come from remote.XXX config entries.
@@ -12,5 +14,6 @@ struct promisor_remote {
1214

1315
extern struct promisor_remote *promisor_remote_find(const char *remote_name);
1416
extern int has_promisor_remote(void);
17+
extern int promisor_remote_get_direct(const struct object_id *oids, int oid_nr);
1518

1619
#endif /* PROMISOR_REMOTE_H */

0 commit comments

Comments
 (0)