From e0737b5ca3d2de56947a5e33f50c54b1277e533b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 6 Oct 2009 14:09:26 +0200 Subject: [PATCH] WIP: do --submodule-summary using child_processes This is super-ugly, and will suck on Windows, but Junio does not trust my words. This is _not_ meant for application, but just for quick-n-dirty testing. For one, it loses coloring, and two, it loses correct determination of fast-forwards vs non-fast-forwards, and three, it does not make the SHA-1s being correctly abbreviated. BUT. I have no inclination of wasting my time even more, even if Junio asks for it. It really sucks that I have to do this. --- submodule.c | 92 ++++++++++++++++++++----------------------------------------- 1 file changed, 30 insertions(+), 62 deletions(-) diff --git a/submodule.c b/submodule.c index b441ea1fc4..4e5c1c54cd 100644 --- a/submodule.c +++ b/submodule.c @@ -1,9 +1,6 @@ #include "cache.h" #include "submodule.h" -#include "dir.h" -#include "diff.h" -#include "commit.h" -#include "revision.h" +#include "run-command.h" int add_submodule_odb(const char *path) { @@ -37,13 +34,8 @@ void show_submodule_summary(FILE *f, const char *path, unsigned char one[20], unsigned char two[20], const char *del, const char *add, const char *reset) { - struct rev_info rev; - struct commit *commit, *left, *right; - struct commit_list *merge_bases, *list; - const char *message = NULL; struct strbuf sb = STRBUF_INIT; - static const char *format = " %m %s"; - int fast_forward = 0, fast_backward = 0; + const char *message = NULL; if (add_submodule_odb(path)) message = "(not checked out)"; @@ -51,61 +43,37 @@ void show_submodule_summary(FILE *f, const char *path, message = "(new submodule)"; else if (is_null_sha1(two)) message = "(submodule deleted)"; - else if (!(left = lookup_commit_reference(one)) || - !(right = lookup_commit_reference(two))) - message = "(commits not present)"; if (!message) { - init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, NULL); - rev.left_right = 1; - left->object.flags |= SYMMETRIC_LEFT; - add_pending_object(&rev, &left->object, path); - add_pending_object(&rev, &right->object, path); - merge_bases = get_merge_bases(left, right, 1); - if (merge_bases) { - if (merge_bases->item == left) - fast_forward = 1; - else if (merge_bases->item == right) - fast_backward = 1; - } - for (list = merge_bases; list; list = list->next) { - list->item->object.flags |= UNINTERESTING; - add_pending_object(&rev, &list->item->object, - sha1_to_hex(list->item->object.sha1)); - } - if (prepare_revision_walk(&rev)) - message = "(revision walker failed)"; - } + struct child_process child; + struct strbuf range = STRBUF_INIT; + const char* argv[] = { + "log", "--pretty=format: %m %s", "--left-right", + NULL, "--", NULL + }; - strbuf_addf(&sb, "Submodule %s %s..", path, - find_unique_abbrev(one, DEFAULT_ABBREV)); - if (!fast_backward && !fast_forward) - strbuf_addch(&sb, '.'); - strbuf_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV)); - if (message) - strbuf_addf(&sb, " %s\n", message); - else - strbuf_addf(&sb, "%s:\n", fast_backward ? " (rewind)" : ""); - fwrite(sb.buf, sb.len, 1, f); + strbuf_addf(&range, "%s...%s", + sha1_to_hex(one), sha1_to_hex(two)); + argv[3] = range.buf; + memset(&child, 0, sizeof(child)); + child.argv = argv; + child.dir = path; + child.no_stdin = 1; + child.out = fileno(f); + child.err = fileno(stderr); + child.git_cmd = 1; - if (!message) { - while ((commit = get_revision(&rev))) { - strbuf_setlen(&sb, 0); - if (commit->object.flags & SYMMETRIC_LEFT) { - if (del) - strbuf_addstr(&sb, del); - } - else if (add) - strbuf_addstr(&sb, add); - format_commit_message(commit, format, &sb, - rev.date_mode); - if (reset) - strbuf_addstr(&sb, reset); - strbuf_addch(&sb, '\n'); - fprintf(f, "%s", sb.buf); - } - clear_commit_marks(left, ~0); - clear_commit_marks(right, ~0); + fprintf(f, "Submodule %s %s:\n", path, range.buf); + fflush(f); + run_command(&child); + strbuf_release(&range); + return; } + + strbuf_addf(&sb, "Submodule %s %s...%s %s\n", path, + find_unique_abbrev(one, DEFAULT_ABBREV), + find_unique_abbrev(two, DEFAULT_ABBREV), + message); + fprintf(f, "%s", sb.buf); + strbuf_release(&sb); } -- 2.11.4.GIT