Skip to content

Commit ac8d5af

Browse files
pkufrankygitster
authored andcommitted
builtin-status: submodule summary support
This commit teaches 'git commit/status' show a new 'Modified submodules' section, which is an output from: git submodule summary --cached --for-status --summary-limit <limit> just before the 'Untracked files' section. The <limit> is given by the config variable status.submodulesummary to limit the submodule summary size. status.submodulesummary is a bool/int variable with value: - false or 0 by default to disable the summary, or - positive number to limit the summary size, or - true or negative number to unlimit the summary size. Also mention status.submodulesummary in the documentation. Signed-off-by: Ping Yin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0f64dd commit ac8d5af

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Documentation/git-status.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ If the config variable `status.relativePaths` is set to false, then all
5252
paths shown are relative to the repository root, not to the current
5353
directory.
5454

55+
If `status.submodulesummary` is set to a non zero number or true (identical
56+
to -1 or an unlimited number), the submodule summary will be enabled and a
57+
summary of commits for modified submodules will be shown (see --summary-limit
58+
option of linkgit:git-submodule[1]).
59+
5560
See Also
5661
--------
5762
linkgit:gitignore[5]

wt-status.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include "revision.h"
99
#include "diffcore.h"
1010
#include "quote.h"
11+
#include "run-command.h"
1112

1213
int wt_status_relative_paths = 1;
1314
int wt_status_use_color = -1;
15+
int wt_status_submodule_summary;
1416
static char wt_status_colors[][COLOR_MAXLEN] = {
1517
"", /* WT_STATUS_HEADER: normal */
1618
"\033[32m", /* WT_STATUS_UPDATED: green */
@@ -220,6 +222,36 @@ static void wt_status_print_changed(struct wt_status *s)
220222
run_diff_files(&rev, 0);
221223
}
222224

225+
static void wt_status_print_submodule_summary(struct wt_status *s)
226+
{
227+
struct child_process sm_summary;
228+
char summary_limit[64];
229+
char index[PATH_MAX];
230+
const char *env[] = { index, NULL };
231+
const char *argv[] = {
232+
"submodule",
233+
"summary",
234+
"--cached",
235+
"--for-status",
236+
"--summary-limit",
237+
summary_limit,
238+
s->amend ? "HEAD^" : "HEAD",
239+
NULL
240+
};
241+
242+
sprintf(summary_limit, "%d", wt_status_submodule_summary);
243+
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
244+
245+
memset(&sm_summary, 0, sizeof(sm_summary));
246+
sm_summary.argv = argv;
247+
sm_summary.env = env;
248+
sm_summary.git_cmd = 1;
249+
sm_summary.no_stdin = 1;
250+
fflush(s->fp);
251+
sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
252+
run_command(&sm_summary);
253+
}
254+
223255
static void wt_status_print_untracked(struct wt_status *s)
224256
{
225257
struct dir_struct dir;
@@ -308,6 +340,8 @@ void wt_status_print(struct wt_status *s)
308340
}
309341

310342
wt_status_print_changed(s);
343+
if (wt_status_submodule_summary)
344+
wt_status_print_submodule_summary(s);
311345
wt_status_print_untracked(s);
312346

313347
if (s->verbose && !s->is_initial)
@@ -330,6 +364,13 @@ void wt_status_print(struct wt_status *s)
330364

331365
int git_status_config(const char *k, const char *v)
332366
{
367+
if (!strcmp(k, "status.submodulesummary")) {
368+
int is_bool;
369+
wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
370+
if (is_bool && wt_status_submodule_summary)
371+
wt_status_submodule_summary = -1;
372+
return 0;
373+
}
333374
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
334375
wt_status_use_color = git_config_colorbool(k, v, -1);
335376
return 0;

0 commit comments

Comments
 (0)