257
return list_refs(&header->references, argc, argv);
258
}
259
260
-static void show_commit(struct commit *commit)
261
-{
262
- write_or_die(1, sha1_to_hex(commit->object.sha1), 40);
263
- write_or_die(1, "\n", 1);
264
- if (commit->parents) {
265
- free_commit_list(commit->parents);
266
- commit->parents = NULL;
267
- }
268
-}
269
-
270
-static void show_object(struct object_array_entry *p)
271
-{
272
- /* An object with name "foo\n0000000..." can be used to
273
- * confuse downstream git-pack-objects very badly.
274
- */
275
- const char *ep = strchr(p->name, '\n');
276
- int len = ep ? ep - p->name : strlen(p->name);
277
- write_or_die(1, sha1_to_hex(p->item->sha1), 40);
278
- write_or_die(1, " ", 1);
279
- if (len)
280
- write_or_die(1, p->name, len);
281
- write_or_die(1, "\n", 1);
282
-}
283
-
284
-static void show_edge(struct commit *commit)
285
-{
286
- ; /* nothing to do */
287
-}
288
-
260
static int create_bundle(struct bundle_header *header, const char *path,
261
int argc, const char **argv)
262
{
263
int bundle_fd = -1;
264
const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
294
- const char **argv_pack = xmalloc(4 * sizeof(const char *));
265
+ const char **argv_pack = xmalloc(5 * sizeof(const char *));
266
int pid, in, out, i, status;
267
char buffer[1024];
268
struct rev_info revs;
298
- struct object_array tips;
269
270
bundle_fd = (!strcmp(path, "-") ? 1 :
271
open(path, O_CREAT | O_WRONLY, 0666));
289
pid = fork_with_pipe(argv_boundary, NULL, &out);
290
if (pid < 0)
291
return -1;
322
- while ((i = read_string(out, buffer, sizeof(buffer))) > 0)
292
+ while ((i = read_string(out, buffer, sizeof(buffer))) > 0) {
293
+ unsigned char sha1[20];
294
if (buffer[0] == '-') {
324
- unsigned char sha1[20];
295
write_or_die(bundle_fd, buffer, i);
296
if (!get_sha1_hex(buffer + 1, sha1)) {
297
struct object *object = parse_object(sha1);
298
object->flags |= UNINTERESTING;
299
add_pending_object(&revs, object, buffer);
300
}
301
+ } else if (!get_sha1_hex(buffer, sha1)) {
302
+ struct object *object = parse_object(sha1);
303
+ object->flags |= SHOWN;
304
}
305
+ }
306
while ((i = waitpid(pid, &status, 0)) < 0)
307
if (errno != EINTR)
308
return error("rev-list died");
310
return error("rev-list died %d", WEXITSTATUS(status));
311
312
/* write references */
339
- revs.tag_objects = 1;
340
- revs.tree_objects = 1;
341
- revs.blob_objects = 1;
313
argc = setup_revisions(argc, argv, &revs, NULL);
314
if (argc > 1)
315
return error("unrecognized argument: %s'", argv[1]);
316
346
- memset(&tips, 0, sizeof(tips));
317
for (i = 0; i < revs.pending.nr; i++) {
318
struct object_array_entry *e = revs.pending.objects + i;
319
unsigned char sha1[20];
323
continue;
324
if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
325
continue;
326
+ /*
327
+ * Make sure the refs we wrote out is correct; --max-count and
328
+ * other limiting options could have prevented all the tips
329
+ * from getting output.
330
+ */
331
+ if (!(e->item->flags & SHOWN)) {
332
+ warn("ref '%s' is excluded by the rev-list options",
333
+ e->name);
334
+ continue;
335
+ }
336
write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
337
write_or_die(bundle_fd, " ", 1);
338
write_or_die(bundle_fd, ref, strlen(ref));
339
write_or_die(bundle_fd, "\n", 1);
360
- add_object_array(e->item, e->name, &tips);
340
free(ref);
341
}
342
347
argv_pack[0] = "pack-objects";
348
argv_pack[1] = "--all-progress";
349
argv_pack[2] = "--stdout";
371
- argv_pack[3] = NULL;
350
+ argv_pack[3] = "--thin";
351
+ argv_pack[4] = NULL;
352
in = -1;
353
out = bundle_fd;
354
pid = fork_with_pipe(argv_pack, &in, &out);
355
if (pid < 0)
356
return error("Could not spawn pack-objects");
377
- close(1);
378
- dup2(in, 1);
357
+ for (i = 0; i < revs.pending.nr; i++) {
358
+ struct object *object = revs.pending.objects[i].item;
359
+ if (object->flags & UNINTERESTING)
360
+ write(in, "^", 1);
361
+ write(in, sha1_to_hex(object->sha1), 40);
362
+ write(in, "\n", 1);
363
+ }
364
close(in);
380
- prepare_revision_walk(&revs);
381
- mark_edges_uninteresting(revs.commits, &revs, show_edge);
382
- traverse_commit_list(&revs, show_commit, show_object);
383
- close(1);
365
while (waitpid(pid, &status, 0) < 0)
366
if (errno != EINTR)
367
return -1;
368
if (!WIFEXITED(status) || WEXITSTATUS(status))
369
return error ("pack-objects died");
370
390
- /*
391
- * Make sure the refs we wrote out is correct; --max-count and
392
- * other limiting options could have prevented all the tips
393
- * from getting output.
394
- */
395
- status = 0;
396
- for (i = 0; i < tips.nr; i++) {
397
- if (!(tips.objects[i].item->flags & SHOWN)) {
398
- status = 1;
399
- error("%s: not included in the resulting pack",
400
- tips.objects[i].name);
401
- }
402
- }
403
-
371
return status;
372
}
373