@matheusbsbs / matheus-bagliano / commits / ac8d5afca6
Fork 0

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>

Ping Yin committed Apr 12, 2008 at 23:05 UTC ac8d5afca6931aa005aff873e4f490ff5050fc76
2 files changed +46
Documentation/git-status.txt
+5
@@ -52,6 +52,11 @@ If the config variable `status.relativePaths` is set to false, then all
52 paths shown are relative to the repository root, not to the current
53 directory.
54
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 +
60 See Also
61 --------
62 linkgit:gitignore[5]
wt-status.c
+41
@@ -8,9 +8,11 @@
8 #include "revision.h"
9 #include "diffcore.h"
10 #include "quote.h"
11 +#include "run-command.h"
12
13 int wt_status_relative_paths = 1;
14 int wt_status_use_color = -1;
15 +int wt_status_submodule_summary;
16 static char wt_status_colors[][COLOR_MAXLEN] = {
17 "", /* WT_STATUS_HEADER: normal */
18 "\033[32m", /* WT_STATUS_UPDATED: green */
@@ -220,6 +222,36 @@ static void wt_status_print_changed(struct wt_status *s)
222 run_diff_files(&rev, 0);
223 }
224
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 +
255 static void wt_status_print_untracked(struct wt_status *s)
256 {
257 struct dir_struct dir;
@@ -308,6 +340,8 @@ void wt_status_print(struct wt_status *s)
340 }
341
342 wt_status_print_changed(s);
343 + if (wt_status_submodule_summary)
344 + wt_status_print_submodule_summary(s);
345 wt_status_print_untracked(s);
346
347 if (s->verbose && !s->is_initial)
@@ -330,6 +364,13 @@ void wt_status_print(struct wt_status *s)
364
365 int git_status_config(const char *k, const char *v)
366 {
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 + }
374 if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
375 wt_status_use_color = git_config_colorbool(k, v, -1);
376 return 0;