Skip to content

Commit 9e27bea

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]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48de315 commit 9e27bea

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

promisor-remote.c

Lines changed: 67 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,68 @@ int has_promisor_remote(void)
9092
{
9193
return !!promisor_remote_find(NULL);
9294
}
95+
96+
static int remove_fetched_oids(struct repository *repo,
97+
struct object_id **oids,
98+
int oid_nr, int to_free)
99+
{
100+
int i, remaining_nr = 0;
101+
int *remaining = xcalloc(oid_nr, sizeof(*remaining));
102+
struct object_id *old_oids = *oids;
103+
struct object_id *new_oids;
104+
105+
for (i = 0; i < oid_nr; i++)
106+
if (oid_object_info_extended(repo, &old_oids[i], NULL,
107+
OBJECT_INFO_SKIP_FETCH_OBJECT)) {
108+
remaining[i] = 1;
109+
remaining_nr++;
110+
}
111+
112+
if (remaining_nr) {
113+
int j = 0;
114+
new_oids = xcalloc(remaining_nr, sizeof(*new_oids));
115+
for (i = 0; i < oid_nr; i++)
116+
if (remaining[i])
117+
oidcpy(&new_oids[j++], &old_oids[i]);
118+
*oids = new_oids;
119+
if (to_free)
120+
free(old_oids);
121+
}
122+
123+
free(remaining);
124+
125+
return remaining_nr;
126+
}
127+
128+
int promisor_remote_get_direct(struct repository *repo,
129+
const struct object_id *oids,
130+
int oid_nr)
131+
{
132+
struct promisor_remote *r;
133+
struct object_id *remaining_oids = (struct object_id *)oids;
134+
int remaining_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, remaining_oids, remaining_nr) < 0) {
142+
if (remaining_nr == 1)
143+
continue;
144+
remaining_nr = remove_fetched_oids(repo, &remaining_oids,
145+
remaining_nr, to_free);
146+
if (remaining_nr) {
147+
to_free = 1;
148+
continue;
149+
}
150+
}
151+
res = 0;
152+
break;
153+
}
154+
155+
if (to_free)
156+
free(remaining_oids);
157+
158+
return res;
159+
}

promisor-remote.h

Lines changed: 5 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,8 @@ 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(struct repository *repo,
18+
const struct object_id *oids,
19+
int oid_nr);
1520

1621
#endif /* PROMISOR_REMOTE_H */

0 commit comments

Comments
 (0)