23
{ 3, v3_bundle_signature },
24
};
25
26
-static void add_to_ref_list(const struct object_id *oid, const char *name,
27
- struct ref_list *list)
26
+void bundle_header_init(struct bundle_header *header)
27
{
29
- ALLOC_GROW(list->list, list->nr + 1, list->alloc);
30
- oidcpy(&list->list[list->nr].oid, oid);
31
- list->list[list->nr].name = xstrdup(name);
32
- list->nr++;
28
+ struct bundle_header blank = BUNDLE_HEADER_INIT;
29
+ memcpy(header, &blank, sizeof(*header));
30
+}
31
+
32
+void bundle_header_release(struct bundle_header *header)
33
+{
34
+ string_list_clear(&header->prerequisites, 1);
35
+ string_list_clear(&header->references, 1);
36
}
37
38
static int parse_capability(struct bundle_header *header, const char *capability)
115
status = -1;
116
break;
117
} else {
118
+ struct object_id *dup = oiddup(&oid);
119
if (is_prereq)
116
- add_to_ref_list(&oid, "", &header->prerequisites);
120
+ string_list_append(&header->prerequisites, "")->util = dup;
121
else
118
- add_to_ref_list(&oid, p + 1, &header->references);
122
+ string_list_append(&header->references, p + 1)->util = dup;
123
}
124
}
125
143
144
int is_bundle(const char *path, int quiet)
145
{
142
- struct bundle_header header;
146
+ struct bundle_header header = BUNDLE_HEADER_INIT;
147
int fd = open(path, O_RDONLY);
148
149
if (fd < 0)
150
return 0;
147
- memset(&header, 0, sizeof(header));
151
fd = parse_bundle_header(fd, &header, quiet ? NULL : path);
152
if (fd >= 0)
153
close(fd);
154
+ bundle_header_release(&header);
155
return (fd >= 0);
156
}
157
154
-static int list_refs(struct ref_list *r, int argc, const char **argv)
158
+static int list_refs(struct string_list *r, int argc, const char **argv)
159
{
160
int i;
161
166
if (argc > 1) {
167
int j;
168
for (j = 1; j < argc; j++)
165
- if (!strcmp(r->list[i].name, argv[j]))
169
+ if (!strcmp(r->items[i].string, argv[j]))
170
break;
171
if (j == argc)
172
continue;
173
}
174
171
- oid = &r->list[i].oid;
172
- name = r->list[i].name;
175
+ oid = r->items[i].util;
176
+ name = r->items[i].string;
177
printf("%s %s\n", oid_to_hex(oid), name);
178
}
179
return 0;
190
* Do fast check, then if any prereqs are missing then go line by line
191
* to be verbose about the errors
192
*/
189
- struct ref_list *p = &header->prerequisites;
193
+ struct string_list *p = &header->prerequisites;
194
struct rev_info revs;
195
const char *argv[] = {NULL, "--all", NULL};
196
struct commit *commit;
202
203
repo_init_revisions(r, &revs, NULL);
204
for (i = 0; i < p->nr; i++) {
201
- struct ref_list_entry *e = p->list + i;
202
- const char *name = e->name;
203
- struct object_id *oid = &e->oid;
205
+ struct string_list_item *e = p->items + i;
206
+ const char *name = e->string;
207
+ struct object_id *oid = e->util;
208
struct object *o = parse_object(r, oid);
209
if (o) {
210
o->flags |= PREREQ_MARK;
229
i--;
230
231
for (i = 0; i < p->nr; i++) {
228
- struct ref_list_entry *e = p->list + i;
229
- const char *name = e->name;
230
- struct object_id *oid = &e->oid;
232
+ struct string_list_item *e = p->items + i;
233
+ const char *name = e->string;
234
+ const struct object_id *oid = e->util;
235
struct object *o = parse_object(r, oid);
236
assert(o); /* otherwise we'd have returned early */
237
if (o->flags & SHOWN)
243
244
/* Clean up objects used, as they will be reused. */
245
for (i = 0; i < p->nr; i++) {
242
- struct ref_list_entry *e = p->list + i;
243
- struct object_id *oid = &e->oid;
246
+ struct string_list_item *e = p->items + i;
247
+ struct object_id *oid = e->util;
248
commit = lookup_commit_reference_gently(r, oid, 1);
249
if (commit)
250
clear_commit_marks(commit, ALL_REV_FLAGS);
251
}
252
253
if (verbose) {
250
- struct ref_list *r;
254
+ struct string_list *r;
255
256
r = &header->references;
257
printf_ln(Q_("The bundle contains this ref:",