submodule summary: ignore --for-status option

The --for-status option was an undocumented option used only by wt-status.c, which inserted a header and commented out the output. We can achieve the same result within wt-status.c, without polluting the submodule command-line options. This will make it easier to disable the comments from wt-status.c later. The --for-status is kept so that another topic in flight (bc/submodule-status-ignored) can continue relying on it, although it is currently a no-op. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Sep 6, 2013 at 19:43 UTC 3ba7407b8b7b7a75f720641327207d6cfdb163a2
3 files changed +32 -20
git-submodule.sh
+1 -12
@@ -1149,18 +1149,7 @@ cmd_summary() {
1149 echo
1150 fi
1151 echo
1152 - done |
1153 - if test -n "$for_status"; then
1154 - if [ -n "$files" ]; then
1155 - gettextln "Submodules changed but not updated:" | git stripspace -c
1156 - else
1157 - gettextln "Submodule changes to be committed:" | git stripspace -c
1158 - fi
1159 - printf "\n" | git stripspace -c
1160 - git stripspace -c
1161 - else
1162 - cat
1163 - fi
1152 + done
1153 }
1154 #
1155 # List all submodules, prefixed with:
t/t7401-submodule-summary.sh
+5 -7
@@ -265,13 +265,11 @@ EOF
265 test_expect_success '--for-status' "
266 git submodule summary --for-status HEAD^ >actual &&
267 test_i18ncmp actual - <<EOF
268 -# Submodule changes to be committed:
269 -#
270 -# * sm1 $head6...0000000:
271 -#
272 -# * sm2 0000000...$head7 (2):
273 -# > Add foo9
274 -#
268 +* sm1 $head6...0000000:
269 +
270 +* sm2 0000000...$head7 (2):
271 + > Add foo9
272 +
273 EOF
274 "
275
wt-status.c
+26 -1
@@ -665,6 +665,10 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
665 char index[PATH_MAX];
666 const char *env[] = { NULL, NULL };
667 struct argv_array argv = ARGV_ARRAY_INIT;
668 + struct strbuf cmd_stdout = STRBUF_INIT;
669 + struct strbuf summary = STRBUF_INIT;
670 + char *summary_content;
671 + size_t len;
672
673 sprintf(summary_limit, "%d", s->submodule_summary);
674 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
@@ -685,9 +689,30 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
689 sm_summary.git_cmd = 1;
690 sm_summary.no_stdin = 1;
691 fflush(s->fp);
688 - sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
692 + sm_summary.out = -1;
693 +
694 run_command(&sm_summary);
695 argv_array_clear(&argv);
696 +
697 + len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
698 +
699 + /* prepend header, only if there's an actual output */
700 + if (len) {
701 + if (uncommitted)
702 + strbuf_addstr(&summary, _("Submodules changed but not updated:"));
703 + else
704 + strbuf_addstr(&summary, _("Submodule changes to be committed:"));
705 + strbuf_addstr(&summary, "\n\n");
706 + }
707 + strbuf_addbuf(&summary, &cmd_stdout);
708 + strbuf_release(&cmd_stdout);
709 +
710 + summary_content = strbuf_detach(&summary, &len);
711 + strbuf_add_commented_lines(&summary, summary_content, len);
712 + free(summary_content);
713 +
714 + fputs(summary.buf, s->fp);
715 + strbuf_release(&summary);
716 }
717
718 static void wt_status_print_other(struct wt_status *s,