Avoid reading stdin twice for bundle --stdin. Reported-by: Joey Hess <joey@xxxxxxxxxxx> Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- bundle.c | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 37 insertions(+), 20 deletions(-) diff --git a/bundle.c b/bundle.c index 8ba6479..311c554 100644 --- a/bundle.c +++ b/bundle.c @@ -193,7 +193,17 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) (revs->min_age == -1 || revs->min_age > date); } -static void list_prerequisite(int bundle_fd, struct rev_info *revs, +static void object_array_copy(struct object_array *dest, const struct object_array *src) +{ + int i; + + for (i = 0; i < src->nr; i++) { + struct object_array_entry *e = src->objects + i; + add_object_array_with_mode(e->item, e->name, dest, e->mode); + } +} + +static void list_prerequisite(int bundle_fd, struct object_array *pending, struct commit *rev) { struct strbuf buf = STRBUF_INIT; @@ -216,45 +226,52 @@ static void list_prerequisite(int bundle_fd, struct rev_info *revs, write_or_die(bundle_fd, buf.buf, buf.len); rev->object.flags |= UNINTERESTING; - add_pending_object(revs, &rev->object, buf.buf); + add_object_array(&rev->object, buf.buf, pending); strbuf_release(&buf); } static int list_prerequisites(int bundle_fd, struct rev_info *revs, - int argc, const char * const *argv) + int argc, const char **argv) { - const char **argv_boundary = xmalloc((argc + 1) * sizeof(const char *)); - struct rev_info boundary_revs; struct commit *rev; + struct object_array pending_copy = { 0, 0, NULL }; - memcpy(argv_boundary, argv, (argc + 1) * sizeof(const char *)); + revs->simplify_history = 0; + argc = setup_revisions(argc, argv, revs, NULL); + if (argc > 1) + return error("unrecognized argument: %s", argv[1]); - init_revisions(&boundary_revs, NULL); - boundary_revs.boundary = 1; - if (setup_revisions(argc, argv_boundary, &boundary_revs, NULL) > 1) - return error("unrecognized argument: %s", argv_boundary[1]); - if (prepare_revision_walk(&boundary_revs)) + if (revs->reflog_info) + return error("bundle does not support --walk-reflogs"); + if (revs->no_walk) + return error("bundle does not support --no-walk"); + if (revs->simplify_history) + return error("bundle and history simplification do not mix"); + + object_array_copy(&pending_copy, &revs->pending); + + revs->boundary = 1; + if (prepare_revision_walk(revs)) return error("revision walk setup failed"); while ((rev = get_revision(revs))) { if (rev->object.flags & BOUNDARY) - list_prerequisite(bundle_fd, revs, rev); + list_prerequisite(bundle_fd, &pending_copy, rev); else rev->object.flags |= SHOWN; } + + if (revs->pending.objects != NULL) + return error("%u revisions pending after boundary walk", + revs->pending.nr); + revs->pending = pending_copy; return 0; } -static int bundle_list_refs(int bundle_fd, - int argc, const char **argv, struct rev_info *revs) +static int bundle_list_refs(int bundle_fd, struct rev_info *revs) { int i, ref_count = 0; - argc = setup_revisions(argc, argv, revs, NULL); - - if (argc > 1) - return error("unrecognized argument: %s'", argv[1]); - object_array_remove_duplicates(&revs->pending); for (i = 0; i < revs->pending.nr; i++) { @@ -367,7 +384,7 @@ int create_bundle(struct bundle_header *header, const char *path, return -1; /* write references */ - if (bundle_list_refs(bundle_fd, argc, argv, &revs)) + if (bundle_list_refs(bundle_fd, &revs)) return -1; /* end header */ -- 1.7.1.198.g8d802 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html