The revision walker produces structured output, which should be a little easier to work with than the text from rev-list. Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- bundle.c | 69 ++++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 38 insertions(+), 31 deletions(-) diff --git a/bundle.c b/bundle.c index 66948f4..0dd2acb 100644 --- a/bundle.c +++ b/bundle.c @@ -196,40 +196,47 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) static int list_prerequisites(int bundle_fd, struct rev_info *revs, int argc, const char * const *argv) { - const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *)); - char buffer[1024]; - struct child_process rls; - FILE *rls_fout; + const char **argv_boundary = xmalloc((argc + 1) * sizeof(const char *)); + struct rev_info boundary_revs; + struct commit *rev; - memcpy(argv_boundary + 3, argv + 1, argc * sizeof(const char *)); - argv_boundary[0] = "rev-list"; - argv_boundary[1] = "--boundary"; - argv_boundary[2] = "--pretty=oneline"; - argv_boundary[argc + 2] = NULL; - memset(&rls, 0, sizeof(rls)); - rls.argv = argv_boundary; - rls.out = -1; - rls.git_cmd = 1; - if (start_command(&rls)) - return -1; - rls_fout = xfdopen(rls.out, "r"); - while (fgets(buffer, sizeof(buffer), rls_fout)) { - unsigned char sha1[20]; - if (buffer[0] == '-') { - write_or_die(bundle_fd, buffer, strlen(buffer)); - if (!get_sha1_hex(buffer + 1, sha1)) { - struct object *object = parse_object(sha1); - object->flags |= UNINTERESTING; - add_pending_object(revs, object, buffer); - } - } else if (!get_sha1_hex(buffer, sha1)) { - struct object *object = parse_object(sha1); - object->flags |= SHOWN; + memcpy(argv_boundary, argv, (argc + 1) * sizeof(const char *)); + + 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)) + return error("revision walk setup failed"); + + while ((rev = get_revision(&boundary_revs))) { + if (rev->object.flags & BOUNDARY) { + struct strbuf buf = STRBUF_INIT; + struct pretty_print_context ctx = {0}; + enum object_type type; + unsigned long size; + + /* + * The commit buffer is needed + * to pretty-print boundary commits. + */ + rev->buffer = read_sha1_file(rev->object.sha1, + &type, &size); + + strbuf_addch(&buf, '-'); + strbuf_add(&buf, sha1_to_hex(rev->object.sha1), 40); + strbuf_addch(&buf, ' '); + pretty_print_commit(CMIT_FMT_ONELINE, rev, &buf, &ctx); + strbuf_addch(&buf, '\n'); + write_or_die(bundle_fd, buf.buf, buf.len); + + rev->object.flags |= UNINTERESTING; + add_pending_object(revs, &rev->object, buf.buf); + strbuf_release(&buf); + } else { + rev->object.flags |= SHOWN; } } - fclose(rls_fout); - if (finish_command(&rls)) - return error("rev-list died"); return 0; } -- 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