|
1 | 1 | #include "cache.h"
|
| 2 | +#include "object-store.h" |
2 | 3 | #include "promisor-remote.h"
|
3 | 4 | #include "config.h"
|
| 5 | +#include "fetch-object.h" |
4 | 6 |
|
5 | 7 | static struct promisor_remote *promisors;
|
6 | 8 | static struct promisor_remote **promisors_tail = &promisors;
|
@@ -90,3 +92,67 @@ int has_promisor_remote(void)
|
90 | 92 | {
|
91 | 93 | return !!promisor_remote_find(NULL);
|
92 | 94 | }
|
| 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 | +} |
0 commit comments