git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] builtin-status: submodule summary support

From
Ping Yin <pkufranky@gmail.com>
Date
Apr 10, 2008, 15:50 UTC
Message-ID
<1207842625-9210-4-git-send-email-pkufranky@gmail.com>
In-Reply-To
<1207842625-9210-3-git-send-email-pkufranky@gmail.com>

This commit teaches 'git commit/status' show 'Modified submodules' section given by

git submodule summary --cached --for-status --summary-limit <limit>
just before 'Untracked files' section.

The <limit> is given by the config variable status.submodulesummary to limit the submodule summary size. status.submodulesummary is 0 by default which disables the summary.

Also mention status.submodulesummary in the documentation.
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 Documentation/git-status.txt |    4 ++++
 wt-status.c                  |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 3ea269a..32b6660 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -52,6 +52,10 @@ If the config variable `status.relativePaths` is set to false, then all
 paths shown are relative to the repository root, not to the current
 directory.
 
+If 'status.submodulesummary' is set to a non zero number, the submodule
+summary will be enabled and a summary of commits for modified submodules
+will be shown (see --summary-limit option of linkgit:git-submodule[1]).
+
 See Also
 --------
 linkgit:gitignore[5]
diff --git a/wt-status.c b/wt-status.c
index b3fd57b..369c519 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -8,9 +8,11 @@
 #include "revision.h"
 #include "diffcore.h"
 #include "quote.h"
+#include "run-command.h"
 
 int wt_status_relative_paths = 1;
 int wt_status_use_color = -1;
+int wt_status_submodule_summary = 0;
 static char wt_status_colors[][COLOR_MAXLEN] = {
 	"",         /* WT_STATUS_HEADER: normal */
 	"\033[32m", /* WT_STATUS_UPDATED: green */
@@ -219,6 +221,38 @@ static void wt_status_print_changed(struct wt_status *s)
 	rev.diffopt.format_callback_data = s;
 	run_diff_files(&rev, 0);
 }
+static void wt_status_print_submodule_summary(struct wt_status *s)
+{
+	struct child_process sm_summary;
+	char summary_limit[64];
+	char index[PATH_MAX];
+	const char *env[] = { index, NULL };
+	const char *argv[] = {
+		"submodule",
+		"summary",
+		"--cached",
+		"--for-status",
+		"--summary-limit",
+		summary_limit,
+		s->amend ? "HEAD^" : "HEAD",
+		NULL
+	};
+
+	if (!wt_status_submodule_summary)
+		return;
+
+	sprintf(summary_limit, "%d", wt_status_submodule_summary);
+	snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
+
+	memset(&sm_summary, 0, sizeof(sm_summary));
+	sm_summary.argv = argv;
+	sm_summary.env = env;
+	sm_summary.git_cmd = 1;
+	sm_summary.no_stdin = 1;
+	fflush(s->fp);
+	sm_summary.out = dup(fileno(s->fp));    /* run_command closes it */
+	run_command(&sm_summary);
+}
 
 static void wt_status_print_untracked(struct wt_status *s)
 {
@@ -308,6 +342,7 @@ void wt_status_print(struct wt_status *s)
 	}
 
 	wt_status_print_changed(s);
+	wt_status_print_submodule_summary(s);
 	wt_status_print_untracked(s);
 
 	if (s->verbose && !s->is_initial)
@@ -330,6 +365,10 @@ void wt_status_print(struct wt_status *s)
 
 int git_status_config(const char *k, const char *v)
 {
+	if (!strcmp(k, "status.submodulesummary")) {
+		wt_status_submodule_summary = atoi(v);
+		return 0;
+	}
 	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
 		wt_status_use_color = git_config_colorbool(k, v, -1);
 		return 0;
-- 
1.5.5.23.g2a5f
Previous: Ping YinNext: Ping Yin
Message 4 of 20 in “submodule: fallback to .gitmodules and multiple level module definition”
  1. submodule: fallback to .gitmodules and multiple level module definitionPing Yin, Apr 10, 2008
  2. 1/7 git-submodule: Extract functions module_info and module_urlPing Yin, Apr 10, 2008
  3. 1/3 git-submodule summary: --for-status optionPing Yin, Apr 10, 2008
  4. 2/3 builtin-status: submodule summary supportPing Yin, Apr 10, 2008
  5. 2/7 git-submodule: Extract absolute_url & move absolute url logic to module_clonePing Yin, Apr 10, 2008
  6. 3/3 buitin-status: Add tests for submodule summaryPing Yin, Apr 10, 2008
  7. 3/7 git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/configPing Yin, Apr 10, 2008
  8. 4/7 git-submodule: Extract module_add from cmd_addPing Yin, Apr 10, 2008
  9. 5/7 git-submodule: multi-level module definitionPing Yin, Apr 10, 2008
  10. 6/7 git-submodule: Don't die when command fails for one submodulePing Yin, Apr 10, 2008
  11. 7/7 git-submodule: "update --force" to enforce cloning non-submodulePing Yin, Apr 10, 2008
  12. Junio C HamanoApr 11, 2008
  13. Junio C HamanoApr 11, 2008
  14. Ping YinApr 12, 2008
  15. Junio C HamanoApr 11, 2008
  16. Ping YinApr 12, 2008
  17. Ping YinApr 10, 2008
  18. Junio C HamanoApr 11, 2008
  19. Ping YinApr 12, 2008
  20. Junio C HamanoApr 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.