From: "Alex Riesen" <raa.lkml@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Kristian Høgsberg" <krh@redhat.com>
Subject: [PATCH] builtin-commit: add --cached to operate only on index
Date: Tue, 27 Nov 2007 11:54:52 +0100 [thread overview]
Message-ID: <81b0412b0711270254i58be4d2fi5021767d99fcb753@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2007-11-27 10:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-27 10:54 Alex Riesen [this message]
2007-11-27 11:18 ` [PATCH] builtin-commit: add --cached to operate only on index 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81b0412b0711270254i58be4d2fi5021767d99fcb753@mail.gmail.com \
--to=raa.lkml@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=krh@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).