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 <pkufranky@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ping Yin 2008-04-12 23:05:32 +08:00 committed by Junio C Hamano
parent d0f64dd44d
commit ac8d5afca6
2 changed files with 46 additions and 0 deletions

View File

@ -52,6 +52,11 @@ If the config variable `status.relativePaths` is set to false, then all
paths shown are relative to the repository root, not to the current paths shown are relative to the repository root, not to the current
directory. directory.
If `status.submodulesummary` is set to a non zero number or true (identical
to -1 or an unlimited 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 See Also
-------- --------
linkgit:gitignore[5] linkgit:gitignore[5]

View File

@ -8,9 +8,11 @@
#include "revision.h" #include "revision.h"
#include "diffcore.h" #include "diffcore.h"
#include "quote.h" #include "quote.h"
#include "run-command.h"
int wt_status_relative_paths = 1; int wt_status_relative_paths = 1;
int wt_status_use_color = -1; int wt_status_use_color = -1;
int wt_status_submodule_summary;
static char wt_status_colors[][COLOR_MAXLEN] = { static char wt_status_colors[][COLOR_MAXLEN] = {
"", /* WT_STATUS_HEADER: normal */ "", /* WT_STATUS_HEADER: normal */
"\033[32m", /* WT_STATUS_UPDATED: green */ "\033[32m", /* WT_STATUS_UPDATED: green */
@ -220,6 +222,36 @@ static void wt_status_print_changed(struct wt_status *s)
run_diff_files(&rev, 0); 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
};
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) static void wt_status_print_untracked(struct wt_status *s)
{ {
struct dir_struct dir; struct dir_struct dir;
@ -308,6 +340,8 @@ void wt_status_print(struct wt_status *s)
} }
wt_status_print_changed(s); wt_status_print_changed(s);
if (wt_status_submodule_summary)
wt_status_print_submodule_summary(s);
wt_status_print_untracked(s); wt_status_print_untracked(s);
if (s->verbose && !s->is_initial) if (s->verbose && !s->is_initial)
@ -330,6 +364,13 @@ void wt_status_print(struct wt_status *s)
int git_status_config(const char *k, const char *v) int git_status_config(const char *k, const char *v)
{ {
if (!strcmp(k, "status.submodulesummary")) {
int is_bool;
wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
if (is_bool && wt_status_submodule_summary)
wt_status_submodule_summary = -1;
return 0;
}
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
wt_status_use_color = git_config_colorbool(k, v, -1); wt_status_use_color = git_config_colorbool(k, v, -1);
return 0; return 0;