The option is to enable operation exclusively on the index, without touching working tree. Besides speeding up commit process on performance-challenged platforms it also has to ensure that the index is commited exactly how user sees it. Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx> --- builtin-commit.c | 15 +++++++++++++-- t/t7502-commit.sh | 30 ++++++++++++++++++++++++++++++ wt-status.c | 6 ++++-- wt-status.h | 1 + 4 files changed, 48 insertions(+), 4 deletions(-) Triggered by perpetual Windows/Cygwin problems.
From b7ccb6ef94fe8ed7e9ad232ba9ac772008b2b94f Mon Sep 17 00:00:00 2001 From: Alex Riesen <raa.lkml@xxxxxxxxx> Date: Tue, 27 Nov 2007 11:46:39 +0100 Subject: [PATCH] builtin-commit: add --cached to operate only on index The option is to enable operation exclusively on the index, without touching working tree. Besides speeding up commit process on performance-challenged platforms it also has to ensure that the index is commited exactly how user sees it. Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx> --- builtin-commit.c | 15 +++++++++++++-- t/t7502-commit.sh | 30 ++++++++++++++++++++++++++++++ wt-status.c | 6 ++++-- wt-status.h | 1 + 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/builtin-commit.c b/builtin-commit.c index a35881e..6aa459e 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -44,6 +44,7 @@ static int all, edit_flag, also, interactive, only, amend, signoff; static int quiet, verbose, untracked_files, no_verify; static int no_edit, initial_commit, in_merge; +static int cached_only; const char *only_include_assumed; struct strbuf message; @@ -82,6 +83,7 @@ static struct option builtin_commit_options[] = { OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"), OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"), OPT_BOOLEAN(0, "untracked-files", &untracked_files, "show all untracked files"), + OPT_BOOLEAN(0, "cached", &cached_only, "consider only cached files"), OPT_END() }; @@ -164,6 +166,10 @@ static char *prepare_index(const char **files, const char *prefix) struct path_list partial; const char **pathspec = NULL; + if (cached_only) { + commit_style = COMMIT_AS_IS; + return get_index_file(); + } if (interactive) { interactive_add(); commit_style = COMMIT_AS_IS; @@ -287,6 +293,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix) } s.verbose = verbose; s.untracked = untracked_files; + s.cached_only = cached_only; s.index_file = index_file; s.fp = fp; @@ -550,6 +557,8 @@ static int parse_and_validate_options(int argc, const char *argv[]) free(enc); } + if (all) + cached_only = 0; if (!!also + !!only + !!all + !!interactive > 1) die("Only one of --include/--only/--all/--interactive can be used."); if (argc == 0 && (also || (only && !amend))) @@ -560,11 +569,12 @@ static int parse_and_validate_options(int argc, const char *argv[]) only_include_assumed = "Explicit paths specified without -i nor -o; assuming --only paths..."; also = 0; } - if (all && argc > 0) die("Paths with -a does not make sense."); else if (interactive && argc > 0) die("Paths with --interactive does not make sense."); + else if (cached_only && argc > 0) + die("Paths with --cached does not make sense."); return argc; } @@ -678,7 +688,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) } if (!prepare_log_message(index_file, prefix) && !in_merge) { - run_status(stdout, index_file, prefix); + if (!cached_only) + run_status(stdout, index_file, prefix); rollback_index_files(); unlink(commit_editmsg); return 1; diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 21ac785..bcfadd7 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -89,4 +89,34 @@ test_expect_success 'verbose' ' ' +test_expect_success 'cached only' ' + + git reset --hard && + echo >file1 && + echo >file2 && + git add file1 file2 && + git commit --cached -mcached1 + +' + +test_expect_success 'cached only (ignore uncached)' ' + + git reset --hard && + echo file1 >file1 && + echo file2 >file2 && + git add file1 && + git status --cached | grep file2 + test $? != 0 + +' + +test_expect_success 'do not commit if index unchanged' ' + + git reset --hard && + echo change >file1 && + git commit --cached -mcached2 + test $? != 0 + +' + test_done diff --git a/wt-status.c b/wt-status.c index 0e0439f..9306491 100644 --- a/wt-status.c +++ b/wt-status.c @@ -367,8 +367,10 @@ void wt_status_print(struct wt_status *s) wt_status_print_updated(s); } - wt_status_print_changed(s); - wt_status_print_untracked(s); + if (!s->cached_only) { + wt_status_print_changed(s); + wt_status_print_untracked(s); + } if (s->verbose && !s->is_initial) wt_status_print_verbose(s); diff --git a/wt-status.h b/wt-status.h index 225fb4d..f50e780 100644 --- a/wt-status.h +++ b/wt-status.h @@ -17,6 +17,7 @@ struct wt_status { int verbose; int amend; int untracked; + int cached_only; /* These are computed during processing of the individual sections */ int commitable; int workdir_dirty; -- 1.5.3.6.1008.gbaccf