git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] builtin-commit: add --cached to operate only on index
@ 2007-11-27 10:54 Alex Riesen
  2007-11-27 11:18 ` Johannes Schindelin
  2007-11-27 11:35 ` Johannes Sixt
  0 siblings, 2 replies; 14+ messages in thread
From: Alex Riesen @ 2007-11-27 10:54 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Junio C Hamano, Johannes Schindelin, Kristian Høgsberg

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

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@gmail.com>
---
 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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-cached-to-builtin-commit-operate-only-on-inde.patch --]
[-- Type: text/x-patch; name=0001-Add-cached-to-builtin-commit-operate-only-on-inde.patch, Size: 4642 bytes --]

From b7ccb6ef94fe8ed7e9ad232ba9ac772008b2b94f Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-11-28 21:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-27 10:54 [PATCH] builtin-commit: add --cached to operate only on index Alex Riesen
2007-11-27 11:18 ` Johannes Schindelin
2007-11-27 12:57   ` Alex Riesen
2007-11-27 11:35 ` Johannes Sixt
2007-11-27 12:48   ` Alex Riesen
2007-11-27 17:16     ` Junio C Hamano
2007-11-27 18:12       ` Alex Riesen
2007-11-27 18:18       ` Alex Riesen
2007-11-27 21:44         ` [PATCH] Do not generate full commit log message if it not going to be used Alex Riesen
2007-11-27 21:47           ` Alex Riesen
2007-11-28 12:18           ` Johannes Schindelin
2007-11-28 21:10             ` Alex Riesen
2007-11-28 21:13               ` [PATCH] Do not generate full commit log message if it is " Alex Riesen
2007-11-28 21:43               ` [PATCH] Do not generate full commit log message if it " Johannes Schindelin

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).