* [PATCH v2] builtin-status: submodule summary support @ 2008-04-10 15:35 Ping Yin 2008-04-10 15:35 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:35 UTC (permalink / raw) To: gitster; +Cc: git This is a resend after v1.5.5. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] git-submodule summary: --for-status option 2008-04-10 15:35 [PATCH v2] builtin-status: submodule summary support Ping Yin @ 2008-04-10 15:35 ` Ping Yin 2008-04-10 15:35 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:35 UTC (permalink / raw) To: gitster; +Cc: git, Ping Yin The --for-status option is mainly used by builtin-status/commit. It adds 'Modified submodules:' line at top and '# ' prefix to all following lines. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 17 ++++++++++++++++- t/t7401-submodule-summary.sh | 13 +++++++++++++ 2 files changed, 29 insertions(+), 1 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 56ec353..d7937a5 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -342,6 +342,7 @@ set_name_rev () { # cmd_summary() { summary_limit=-1 + for_status= # parse $args after "submodule ... summary". while test $# -ne 0 @@ -350,6 +351,9 @@ cmd_summary() { --cached) cached="$1" ;; + --for-status) + for_status="$1" + ;; -n|--summary-limit) if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2" then @@ -398,6 +402,12 @@ cmd_summary() { ) test -n "$modules" && + if test -n "$for_status"; then + echo "# Modified submodules:" + echo "#" + else + true + fi && git diff-index $cached --raw $head -- $modules | grep -e '^:160000' -e '^:[0-7]* 160000' | cut -c2- | @@ -499,7 +509,12 @@ cmd_summary() { echo fi echo - done + done | + if test -n "$for_status"; then + sed -e "s|^|# |" -e 's|^# $|#|' + else + cat + fi } # # List all submodules, prefixed with: diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 0f3c42a..1dbb39d 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -192,4 +192,17 @@ test_expect_success 'given commit' " EOF " +test_expect_success '--for-status' " + git submodule summary --for-status HEAD^ >actual && + diff actual - <<-EOF +# Modified submodules: +# +# * sm1 $head6...0000000: +# +# * sm2 0000000...$head7 (2): +# > Add foo9 +# +EOF +" + test_done -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-10 15:35 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin @ 2008-04-10 15:35 ` Ping Yin 2008-04-10 15:35 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano 0 siblings, 2 replies; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:35 UTC (permalink / raw) To: gitster; +Cc: git, Ping Yin 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 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] buitin-status: Add tests for submodule summary 2008-04-10 15:35 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin @ 2008-04-10 15:35 ` Ping Yin 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano 1 sibling, 0 replies; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:35 UTC (permalink / raw) To: gitster; +Cc: git, Ping Yin Signed-off-by: Ping Yin <pkufranky@gmail.com> --- t/t7502-status.sh | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 134 insertions(+), 0 deletions(-) diff --git a/t/t7502-status.sh b/t/t7502-status.sh index cd08516..33882c9 100755 --- a/t/t7502-status.sh +++ b/t/t7502-status.sh @@ -149,4 +149,138 @@ test_expect_success 'status of partial commit excluding new file in index' ' test_cmp expect output ' +test_expect_success "setup status submodule summary" ' + test_create_repo sm && + cd sm && + : >foo && + git add foo && + git commit -m "Add foo" && + cd .. && + git add sm +' + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary is disabled by default" ' + git status > output && + git diff expect output +' + +head=$(cd sm && git rev-parse --short=7 --verify HEAD) + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Modified submodules: +# +# * sm 0000000...$head (1): +# > Add foo +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary" ' + git config status.submodulesummary 10 && + git status > output && + git diff expect output +' + + +cat > expect <<EOF +# On branch master +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +no changes added to commit (use "git add" and/or "git commit -a") +EOF +test_expect_success "status submodule summary (clean submodule)" ' + git commit -m "commit submodule" && + git config status.submodulesummary 10 && + ! git status > output && + git diff expect output +' + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD^1 <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Modified submodules: +# +# * sm 0000000...$head (1): +# > Add foo +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary (--amend)" ' + git config status.submodulesummary 10 && + git status --amend > output && + git diff expect output +' + test_done -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-10 15:35 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin 2008-04-10 15:35 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin @ 2008-04-11 22:31 ` Junio C Hamano 2008-04-12 5:28 ` Ping Yin ` (2 more replies) 1 sibling, 3 replies; 9+ messages in thread From: Junio C Hamano @ 2008-04-11 22:31 UTC (permalink / raw) To: Ping Yin; +Cc: git, Johannes Sixt Ping Yin <pkufranky@gmail.com> writes: > 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. This begs an obvious question "What if I want to have an unlimited summary in the status output?" > 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]). > + The docs quote configuration variables in typewriter face by using backticks (pay attention to how status.relativePaths is quoted in your hunk header comment). > 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; Don't initialize to 0. BSS takes care of it. > 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) > +{ > ... > + 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); I recall we had some clean-up on how file descriptors are inherited and duped around when run_command() runs a subprocess. Hannes, is this dup() consistent with how the things ought to be these days? > @@ -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); With this code, you would feed a NULL to atoi() with: [status] submoduleSummary How about making this a bool-or-number, and boolean true gives whatever the default limit (may be unlimited) when no --summary-limit is given? We may want to have git_config_bool_or_int() in config.c so that the caller can tell if the value is boolean true or integer 1, which would be a reasonable improvement independent from this submodule summary codepath. int git_config_bool_or_int(const char *name, const char *value, int *is_bool) { *is_bool = 1; if (!value) return 1; if (!*value) return 0; if (!strcasecmp(value, "true") || !strcasecmp(value, "yes")) return 1; if (!strcasecmp(value, "false") || !strcasecmp(value, "no")) return 0; *is_bool = 0; return git_config_int(name, value) != 0; } With that, your configuration parser can do something like: if (!strcmp(k, "status.submodulesummary")) { int is_bool, val; val = git_config_bool_or_int(k, v, &b); if (is_bool || val <= 0) { wt_status_submodule_summary_enabled = val; } else { wt_status_submodule_summary = val; wt_status_submodule_summary_enabled = 1; } } and skip the call to wt_status_print_submodule_summary() when not enabled. > int wt_status_relative_paths = 1; > int wt_status_use_color = -1; > +int wt_status_submodule_summary = -1; /* unspecified */ +int wt_status_submodule_summary_enabled; The call site in wt_status_print() would look like: ... wt_status_print_changed(s); if (wt_status_submodule_summary_enabled > 0) wt_status_print_submodule_summary(s); wt_status_print_untracked(s); ... and the wt_status_print_submodule_summary() would not add --summary-limit parameter if wt_status_submodule_summary is left unspecified (i.e. -1). ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano @ 2008-04-12 5:28 ` Ping Yin 2008-04-12 14:47 ` Ping Yin 2008-04-12 16:13 ` Johannes Sixt 2 siblings, 0 replies; 9+ messages in thread From: Ping Yin @ 2008-04-12 5:28 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Johannes Sixt On Sat, Apr 12, 2008 at 6:31 AM, Junio C Hamano <junio@pobox.com> wrote: > int git_config_bool_or_int(const char *name, const char *value, int *is_bool) > { > *is_bool = 1; > if (!value) > return 1; > if (!*value) > return 0; > if (!strcasecmp(value, "true") || !strcasecmp(value, "yes")) > return 1; > if (!strcasecmp(value, "false") || !strcasecmp(value, "no")) > return 0; > *is_bool = 0; > return git_config_int(name, value) != 0; > } > > With that, your configuration parser can do something like: > > > if (!strcmp(k, "status.submodulesummary")) { > int is_bool, val; > val = git_config_bool_or_int(k, v, &b); > if (is_bool || val <= 0) { > wt_status_submodule_summary_enabled = val; > } else { > wt_status_submodule_summary = val; > wt_status_submodule_summary_enabled = 1; > } > } > > and skip the call to wt_status_print_submodule_summary() when not > enabled. > > > > int wt_status_relative_paths = 1; > > int wt_status_use_color = -1; > > +int wt_status_submodule_summary = -1; /* unspecified */ > +int wt_status_submodule_summary_enabled; > > The call site in wt_status_print() would look like: > > ... > > wt_status_print_changed(s); > if (wt_status_submodule_summary_enabled > 0) > > wt_status_print_submodule_summary(s); > wt_status_print_untracked(s); > ... > How about the following? diff --git a/config.c b/config.c index 0624494..e614456 100644 --- a/config.c +++ b/config.c @@ -316,6 +316,21 @@ int git_config_bool(const char *name, const char *value) return git_config_int(name, value) != 0; } +int git_config_bool_or_int(const char *name, const char *value, int *is_bool) +{ + *is_bool = 1; + if (!value) + return 1; + if (!*value) + return 0; + if (!strcasecmp(value, "true") || !strcasecmp(value, "yes")) + return 1; + if (!strcasecmp(value, "false") || !strcasecmp(value, "no")) + return 0; + *is_bool = 0; + return git_config_int(name, value); +} + int git_config_string(const char **dest, const char *var, const char *value) { if (!value) diff --git a/wt-status.c b/wt-status.c index 22385f5..3baa128 100644 --- a/wt-status.c +++ b/wt-status.c @@ -366,7 +366,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); + 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")) { -- Ping Yin ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano 2008-04-12 5:28 ` Ping Yin @ 2008-04-12 14:47 ` Ping Yin 2008-04-12 16:13 ` Johannes Sixt 2 siblings, 0 replies; 9+ messages in thread From: Ping Yin @ 2008-04-12 14:47 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Johannes Sixt On Sat, Apr 12, 2008 at 6:31 AM, Junio C Hamano <junio@pobox.com> wrote: > > +static void wt_status_print_submodule_summary(struct wt_status *s) > > +{ > > ... > > > + 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); > > I recall we had some clean-up on how file descriptors are inherited and > duped around when run_command() runs a subprocess. Hannes, is this dup() > consistent with how the things ought to be these days? I think dup is needed, as commit c20181e3a3 says, run_command still will close passed in positive descripors. start_command(), if .in/.out > 0, closes file descriptors, not the callers Callers of start_command() can set the members .in and .out of struct child_process to a value > 0 to specify that this descriptor is used as the stdin or stdout of the child process. Previously, if start_command() was successful, this descriptor was closed upon return. Here we now make sure that the descriptor is also closed in case of failures. All callers are updated not to close the file descriptor themselves after start_command() was called. -- Ping Yin ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano 2008-04-12 5:28 ` Ping Yin 2008-04-12 14:47 ` Ping Yin @ 2008-04-12 16:13 ` Johannes Sixt 2 siblings, 0 replies; 9+ messages in thread From: Johannes Sixt @ 2008-04-12 16:13 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, Ping Yin On Saturday 12 April 2008 00:31, Junio C Hamano wrote: > Ping Yin <pkufranky@gmail.com> writes: > > +static void wt_status_print_submodule_summary(struct wt_status *s) > > +{ > > ... > > + 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); > > I recall we had some clean-up on how file descriptors are inherited and > duped around when run_command() runs a subprocess. Hannes, is this dup() > consistent with how the things ought to be these days? Yes, this dup() is required and correct. -- Hannes ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH/RFC] submodule: fallback to .gitmodules and multiple level module definition
@ 2008-04-10 15:50 Ping Yin
2008-04-10 15:50 ` [PATCH/RFC 1/7] git-submodule: Extract functions module_info and module_url Ping Yin
0 siblings, 1 reply; 9+ messages in thread
From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw)
To: git; +Cc: gitster
This patch series has two functional improvements for submodule
- Fall back on .gitmodules if info not found in $GIT_DIR/config
- multi-level module definition
Patches 1,2,4 is mainly code refactor but the second one also
has some semantic change.
The other patches do the real functional changes.
Ping Yin (7):
git-submodule: Extract functions module_info and module_url
git-submodule: Extract absolute_url & move absolute url logic to module_clone
git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config
git-submodule: Extract module_add from cmd_add
git-submodule: multi-level module definition
git-submodule: Don't die when command fails for one submodule
git-submodule: "update --force" to enforce cloning non-submodule
git-submodule.sh | 326 ++++++++++++++++++++++++++++++++------------
t/t7400-submodule-basic.sh | 31 ++++-
2 files changed, 267 insertions(+), 90 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH/RFC 1/7] git-submodule: Extract functions module_info and module_url 2008-04-10 15:50 [PATCH/RFC] submodule: fallback to .gitmodules and multiple level module definition Ping Yin @ 2008-04-10 15:50 ` Ping Yin 2008-04-10 15:50 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin module_info is extracted to remove the logic redundance which acquires module names and urls by path filter in several places. module_url is also extracted to prepare for an alternative logic to get url by module name. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 56ec353..a5002e1 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -82,6 +82,25 @@ module_name() echo "$name" } +module_url() { + git config submodule.$1.url +} + +module_info() { + git ls-files --stage -- "$@" | grep -e '^160000 ' | + while read mode sha1 stage path + do + name=$(module_name "$path") + if test -n "$name" + then + url=$(module_url "$name") + echo "$sha1 $path $name $url" + else + echo "$sha1 $path " + fi + done +} + # # Clone a submodule # @@ -232,12 +251,11 @@ cmd_init() shift done - git ls-files --stage -- "$@" | grep '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do + test -n "$name" || exit # Skip already registered paths - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) test -z "$url" || continue url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url) @@ -286,11 +304,10 @@ cmd_update() shift done - git ls-files --stage -- "$@" | grep '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" then # Only mention uninitialized submodules when its @@ -537,11 +554,10 @@ cmd_status() shift done - git ls-files --stage -- "$@" | grep '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" || ! test -d "$path"/.git then say "-$sha1 $path" -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] git-submodule summary: --for-status option 2008-04-10 15:50 ` [PATCH/RFC 1/7] git-submodule: Extract functions module_info and module_url Ping Yin @ 2008-04-10 15:50 ` Ping Yin 2008-04-10 15:50 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin The --for-status option is mainly used by builtin-status/commit. It adds 'Modified submodules:' line at top and '# ' prefix to all following lines. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 17 ++++++++++++++++- t/t7401-submodule-summary.sh | 13 +++++++++++++ 2 files changed, 29 insertions(+), 1 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 56ec353..d7937a5 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -342,6 +342,7 @@ set_name_rev () { # cmd_summary() { summary_limit=-1 + for_status= # parse $args after "submodule ... summary". while test $# -ne 0 @@ -350,6 +351,9 @@ cmd_summary() { --cached) cached="$1" ;; + --for-status) + for_status="$1" + ;; -n|--summary-limit) if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2" then @@ -398,6 +402,12 @@ cmd_summary() { ) test -n "$modules" && + if test -n "$for_status"; then + echo "# Modified submodules:" + echo "#" + else + true + fi && git diff-index $cached --raw $head -- $modules | grep -e '^:160000' -e '^:[0-7]* 160000' | cut -c2- | @@ -499,7 +509,12 @@ cmd_summary() { echo fi echo - done + done | + if test -n "$for_status"; then + sed -e "s|^|# |" -e 's|^# $|#|' + else + cat + fi } # # List all submodules, prefixed with: diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 0f3c42a..1dbb39d 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -192,4 +192,17 @@ test_expect_success 'given commit' " EOF " +test_expect_success '--for-status' " + git submodule summary --for-status HEAD^ >actual && + diff actual - <<-EOF +# Modified submodules: +# +# * sm1 $head6...0000000: +# +# * sm2 0000000...$head7 (2): +# > Add foo9 +# +EOF +" + test_done -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] builtin-status: submodule summary support 2008-04-10 15:50 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin @ 2008-04-10 15:50 ` Ping Yin 2008-04-10 15:50 ` [PATCH/RFC 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin 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 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH/RFC 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone 2008-04-10 15:50 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin @ 2008-04-10 15:50 ` Ping Yin 2008-04-10 15:50 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin 0 siblings, 1 reply; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin Extract function absolute_url to remove code redundance and inconsistence in cmd_init and cmd_add when resolving relative url/path to absolute one. Also move resolving absolute url logic from cmd_add to module_clone which results in a litte behaviour change: cmd_update originally doesn't resolve absolute url but now it will. This behaviour change breaks t7400 which uses relative url './.subrepo'. However, this test originally doesn't mean to test relative url, so fix the url as '.subrepo'. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 41 ++++++++++++++++++----------------------- t/t7400-submodule-basic.sh | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index a5002e1..4d56135 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -65,6 +65,21 @@ resolve_relative_url () echo "$remoteurl/$url" } +# Resolve relative url/path to absolute one +absolute_url () { + case "$1" in + ./*|../*) + # dereference source url relative to parent's url + url="$(resolve_relative_url $1)" ;; + *) + # Turn the source into an absolute path if it is local + url=$(get_repo_base "$1") || + url=$1 + ;; + esac + echo "$url" +} + # # Map submodule path to submodule name # @@ -112,7 +127,7 @@ module_info() { module_clone() { path=$1 - url=$2 + url=$(absolute_url "$2") # If there already is a directory at the submodule path, # expect it to be empty (since that is the default checkout @@ -195,21 +210,7 @@ cmd_add() die "'$path' already exists and is not a valid git repo" fi else - case "$repo" in - ./*|../*) - # dereference source url relative to parent's url - realrepo="$(resolve_relative_url $repo)" ;; - *) - # Turn the source into an absolute path if - # it is local - if base=$(get_repo_base "$repo"); then - repo="$base" - fi - realrepo=$repo - ;; - esac - - module_clone "$path" "$realrepo" || exit + module_clone "$path" "$repo" || exit (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) || die "Unable to checkout submodule '$path'" fi @@ -262,13 +263,7 @@ cmd_init() test -z "$url" && die "No url found for submodule path '$path' in .gitmodules" - # Possibly a url relative to parent - case "$url" in - ./*|../*) - url="$(resolve_relative_url "$url")" - ;; - esac - + url=$(absolute_url "$url") git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ef85a8..e5d59b8 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' ' then echo "[OOPS] init succeeded but submodule url is wrong" false - elif ! git config submodule.example.url ./.subrepo + elif ! git config submodule.example.url .subrepo then echo "[OOPS] init succeeded but update of url failed" false -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] buitin-status: Add tests for submodule summary 2008-04-10 15:50 ` [PATCH/RFC 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin @ 2008-04-10 15:50 ` Ping Yin 0 siblings, 0 replies; 9+ messages in thread From: Ping Yin @ 2008-04-10 15:50 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin Signed-off-by: Ping Yin <pkufranky@gmail.com> --- t/t7502-status.sh | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 134 insertions(+), 0 deletions(-) diff --git a/t/t7502-status.sh b/t/t7502-status.sh index cd08516..33882c9 100755 --- a/t/t7502-status.sh +++ b/t/t7502-status.sh @@ -149,4 +149,138 @@ test_expect_success 'status of partial commit excluding new file in index' ' test_cmp expect output ' +test_expect_success "setup status submodule summary" ' + test_create_repo sm && + cd sm && + : >foo && + git add foo && + git commit -m "Add foo" && + cd .. && + git add sm +' + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary is disabled by default" ' + git status > output && + git diff expect output +' + +head=$(cd sm && git rev-parse --short=7 --verify HEAD) + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Modified submodules: +# +# * sm 0000000...$head (1): +# > Add foo +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary" ' + git config status.submodulesummary 10 && + git status > output && + git diff expect output +' + + +cat > expect <<EOF +# On branch master +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +no changes added to commit (use "git add" and/or "git commit -a") +EOF +test_expect_success "status submodule summary (clean submodule)" ' + git commit -m "commit submodule" && + git config status.submodulesummary 10 && + ! git status > output && + git diff expect output +' + +cat > expect <<EOF +# On branch master +# Changes to be committed: +# (use "git reset HEAD^1 <file>..." to unstage) +# +# new file: dir2/added +# new file: sm +# +# Changed but not updated: +# (use "git add <file>..." to update what will be committed) +# +# modified: dir1/modified +# +# Modified submodules: +# +# * sm 0000000...$head (1): +# > Add foo +# +# Untracked files: +# (use "git add <file>..." to include in what will be committed) +# +# dir1/untracked +# dir2/modified +# dir2/untracked +# expect +# output +# untracked +EOF +test_expect_success "status submodule summary (--amend)" ' + git config status.submodulesummary 10 && + git status --amend > output && + git diff expect output +' + test_done -- 1.5.5.23.g2a5f ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-04-12 16:14 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-04-10 15:35 [PATCH v2] builtin-status: submodule summary support Ping Yin 2008-04-10 15:35 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin 2008-04-10 15:35 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin 2008-04-10 15:35 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin 2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano 2008-04-12 5:28 ` Ping Yin 2008-04-12 14:47 ` Ping Yin 2008-04-12 16:13 ` Johannes Sixt -- strict thread matches above, loose matches on Subject: below -- 2008-04-10 15:50 [PATCH/RFC] submodule: fallback to .gitmodules and multiple level module definition Ping Yin 2008-04-10 15:50 ` [PATCH/RFC 1/7] git-submodule: Extract functions module_info and module_url Ping Yin 2008-04-10 15:50 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin 2008-04-10 15:50 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin 2008-04-10 15:50 ` [PATCH/RFC 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin 2008-04-10 15:50 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).