2 #include "object-store.h"
3 #include "promisor-remote.h"
5 #include "fetch-object.h"
7 static struct promisor_remote
*promisors
;
8 static struct promisor_remote
**promisors_tail
= &promisors
;
10 static struct promisor_remote
*promisor_remote_new(const char *remote_name
)
12 struct promisor_remote
*r
;
14 if (*remote_name
== '/') {
15 warning(_("promisor remote name cannot begin with '/': %s"),
20 FLEX_ALLOC_STR(r
, name
, remote_name
);
23 promisors_tail
= &r
->next
;
28 static struct promisor_remote
*promisor_remote_lookup(const char *remote_name
,
29 struct promisor_remote
**previous
)
31 struct promisor_remote
*r
, *p
;
33 for (p
= NULL
, r
= promisors
; r
; p
= r
, r
= r
->next
)
34 if (!strcmp(r
->name
, remote_name
)) {
43 static int promisor_remote_config(const char *var
, const char *value
, void *data
)
49 if (parse_config_key(var
, "remote", &name
, &namelen
, &subkey
) < 0)
52 if (!strcmp(subkey
, "promisor")) {
55 if (!git_config_bool(var
, value
))
58 remote_name
= xmemdupz(name
, namelen
);
60 if (!promisor_remote_lookup(remote_name
, NULL
))
61 promisor_remote_new(remote_name
);
70 static void promisor_remote_init(void)
72 static int initialized
;
78 git_config(promisor_remote_config
, NULL
);
81 struct promisor_remote
*promisor_remote_find(const char *remote_name
)
83 promisor_remote_init();
88 return promisor_remote_lookup(remote_name
, NULL
);
91 int has_promisor_remote(void)
93 return !!promisor_remote_find(NULL
);
96 static int remove_fetched_oids(struct repository
*repo
,
97 struct object_id
**oids
,
98 int oid_nr
, int to_free
)
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
;
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
)) {
114 new_oids
= xcalloc(remaining_nr
, sizeof(*new_oids
));
115 for (i
= 0; i
< oid_nr
; i
++)
117 oidcpy(&new_oids
[j
++], &old_oids
[i
]);
128 int promisor_remote_get_direct(struct repository
*repo
,
129 const struct object_id
*oids
,
132 struct promisor_remote
*r
;
133 struct object_id
*remaining_oids
= (struct object_id
*)oids
;
134 int remaining_nr
= oid_nr
;
138 promisor_remote_init();
140 for (r
= promisors
; r
; r
= r
->next
) {
141 if (fetch_objects(r
->name
, remaining_oids
, remaining_nr
) < 0) {
142 if (remaining_nr
== 1)
144 remaining_nr
= remove_fetched_oids(repo
, &remaining_oids
,
145 remaining_nr
, to_free
);
156 free(remaining_oids
);