* [PATCH v2] git-commit --patch
@ 2011-02-03 5:25 Conrad Irwin
2011-02-03 5:25 ` [PATCH 1/3] Use a temporary index for git commit --interactive Conrad Irwin
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Conrad Irwin @ 2011-02-03 5:25 UTC (permalink / raw)
To: git; +Cc: conrad.irwin
This patch-set adds support for git-commit --patch, and tidies up some of the
rough edges of git commit --interactive.
The motivation is to support my current workflow, which goes something like:
1. Hack out the basic structure of the feature that I'm working on, until I have
something that looks like it will work.
2. Split this into several commits with a more logical flow (i.e. some that add
support for the techniques I want to use for the actual feature, then the
feature itself).
3. Start fleshing out the implementation, and bug-fixing, with lots of
git-commit --fixup so that the changes end up in the right commit.
4. At the end of the day, a big rebase -i to make the history readable.
This is just about doable with git-add -p, or git-commit --interactive, but
it's very inefficient. I take the presence of git commit --fixup to imply that
other people are doing similar, if less extreme things, so assume that they
would like a git-commit -p too.
Conrad
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Use a temporary index for git commit --interactive
2011-02-03 5:25 [PATCH v2] git-commit --patch Conrad Irwin
@ 2011-02-03 5:25 ` Conrad Irwin
2011-02-03 5:25 ` [PATCH 2/3] Allow git commit --interactive with paths Conrad Irwin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Conrad Irwin @ 2011-02-03 5:25 UTC (permalink / raw)
To: git; +Cc: conrad.irwin
Change the behaviour of git commit --interactive so that when you abort
the commit (by leaving the commit message empty) the index remains
unchanged.
Hitherto an aborted commit --interactive has added the selected hunks to
the index regardless of whether the commit succeeded or not.
Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com>
---
Documentation/git-commit.txt | 3 ++-
builtin/commit.c | 36 ++++++++++++++++++++++++++++--------
2 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index b586c0f..ca755db 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -41,7 +41,8 @@ The content to be added can be specified in several ways:
5. by using the --interactive switch with the 'commit' command to decide one
by one which files should be part of the commit, before finalizing the
- operation. Currently, this is done by invoking 'git add --interactive'.
+ operation. Currently, this is done by invoking 'git add --interactive'
+ on a temporary index.
The `--dry-run` option can be used to obtain a
summary of what is included by any of the above for the next
diff --git a/builtin/commit.c b/builtin/commit.c
index 03cff5a..41f0e2e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -292,18 +292,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
int fd;
struct string_list partial;
const char **pathspec = NULL;
+ char *old_index_env = NULL;
int refresh_flags = REFRESH_QUIET;
if (is_status)
refresh_flags |= REFRESH_UNMERGED;
- if (interactive) {
- if (interactive_add(argc, argv, prefix) != 0)
- die("interactive add failed");
- if (read_cache_preload(NULL) < 0)
- die("index file corrupt");
- commit_style = COMMIT_AS_IS;
- return get_index_file();
- }
if (*argv)
pathspec = get_pathspec(prefix, argv);
@@ -311,6 +304,33 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
if (read_cache_preload(pathspec) < 0)
die("index file corrupt");
+ if (interactive) {
+ fd = hold_locked_index(&index_lock, 1);
+
+ refresh_cache_or_die(refresh_flags);
+
+ if (write_cache(fd, active_cache, active_nr) ||
+ close_lock_file(&index_lock))
+ die("unable to write new_index file");
+
+ old_index_env = getenv(INDEX_ENVIRONMENT);
+ setenv(INDEX_ENVIRONMENT, index_lock.filename, 1);
+
+ if (interactive_add(argc, argv, prefix) != 0)
+ die("interactive add failed");
+
+ if (old_index_env && *old_index_env)
+ setenv(INDEX_ENVIRONMENT, old_index_env, 1);
+ else
+ unsetenv(INDEX_ENVIRONMENT);
+
+ discard_cache();
+ read_cache_from(index_lock.filename);
+
+ commit_style = COMMIT_NORMAL;
+ return index_lock.filename;
+ }
+
/*
* Non partial, non as-is commit.
*
--
1.7.4.1.g1c7a9.dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] Allow git commit --interactive with paths
2011-02-03 5:25 [PATCH v2] git-commit --patch Conrad Irwin
2011-02-03 5:25 ` [PATCH 1/3] Use a temporary index for git commit --interactive Conrad Irwin
@ 2011-02-03 5:25 ` Conrad Irwin
2011-02-03 5:25 ` [PATCH 3/3] Add support for -p/--patch to git-commit Conrad Irwin
2011-02-06 21:06 ` [PATCH v2] git-commit --patch Conrad Irwin
3 siblings, 0 replies; 5+ messages in thread
From: Conrad Irwin @ 2011-02-03 5:25 UTC (permalink / raw)
To: git; +Cc: conrad.irwin
Make git commit --interactive feel more like git add --interactive by
allowing the user to restrict the list of files they have to deal with.
Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com>
---
builtin/commit.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 41f0e2e..592c2d2 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1012,8 +1012,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
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.");
if (null_termination && status_format == STATUS_FORMAT_LONG)
status_format = STATUS_FORMAT_PORCELAIN;
--
1.7.4.1.g1c7a9.dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] Add support for -p/--patch to git-commit
2011-02-03 5:25 [PATCH v2] git-commit --patch Conrad Irwin
2011-02-03 5:25 ` [PATCH 1/3] Use a temporary index for git commit --interactive Conrad Irwin
2011-02-03 5:25 ` [PATCH 2/3] Allow git commit --interactive with paths Conrad Irwin
@ 2011-02-03 5:25 ` Conrad Irwin
2011-02-06 21:06 ` [PATCH v2] git-commit --patch Conrad Irwin
3 siblings, 0 replies; 5+ messages in thread
From: Conrad Irwin @ 2011-02-03 5:25 UTC (permalink / raw)
To: git; +Cc: conrad.irwin
The --interactive flag is already shared by git add and git commit,
share the -p and --patch flags too.
Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com>
---
Documentation/git-commit.txt | 25 ++++++++++++++++---------
builtin/add.c | 6 +++---
builtin/commit.c | 10 +++++++---
commit.h | 2 +-
4 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index ca755db..81156f0 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -8,11 +8,12 @@ git-commit - Record changes to the repository
SYNOPSIS
--------
[verse]
-'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
- [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>]
- [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]
- [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]
- [--status | --no-status] [-i | -o] [--] [<file>...]
+'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
+ [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
+ [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
+ [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
+ [--date=<date>] [--cleanup=<mode>] [--status | --no-status]
+ [-i | -o] [--] [<file>...]
DESCRIPTION
-----------
@@ -39,10 +40,10 @@ The content to be added can be specified in several ways:
that have been removed from the working tree, and then perform the
actual commit;
-5. by using the --interactive switch with the 'commit' command to decide one
- by one which files should be part of the commit, before finalizing the
- operation. Currently, this is done by invoking 'git add --interactive'
- on a temporary index.
+5. by using the --interactive or --patch switches with the 'commit' command
+ to decide one by one which files or hunks should be part of the commit,
+ before finalizing the operation. Currently, this is done by invoking
+ 'git add --interactive' or 'git add --patch' on a temporary index.
The `--dry-run` option can be used to obtain a
summary of what is included by any of the above for the next
@@ -60,6 +61,12 @@ OPTIONS
been modified and deleted, but new files you have not
told git about are not affected.
+-p::
+--patch::
+ Use the interactive patch selection interface to chose
+ which changes to commit. See linkgit:git-add[1] for
+ details.
+
-C <commit>::
--reuse-message=<commit>::
Take an existing commit object, and reuse the log message
diff --git a/builtin/add.c b/builtin/add.c
index 12b964e..3d074b3 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -242,7 +242,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
return status;
}
-int interactive_add(int argc, const char **argv, const char *prefix)
+int interactive_add(int argc, const char **argv, const char *prefix, int patch)
{
const char **pathspec = NULL;
@@ -253,7 +253,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)
}
return run_add_interactive(NULL,
- patch_interactive ? "--patch" : NULL,
+ patch ? "--patch" : NULL,
pathspec);
}
@@ -378,7 +378,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (patch_interactive)
add_interactive = 1;
if (add_interactive)
- exit(interactive_add(argc - 1, argv + 1, prefix));
+ exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
if (edit_interactive)
return(edit_patch(argc, argv, prefix));
diff --git a/builtin/commit.c b/builtin/commit.c
index 592c2d2..0c53dc9 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -70,7 +70,7 @@ static const char *logfile, *force_author;
static const char *template_file;
static char *edit_message, *use_message;
static char *fixup_message, *squash_message;
-static int all, edit_flag, also, interactive, only, amend, signoff;
+static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff;
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
static int no_post_rewrite, allow_empty_message;
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
@@ -138,6 +138,7 @@ static struct option builtin_commit_options[] = {
OPT_BOOLEAN('a', "all", &all, "commit all changed files"),
OPT_BOOLEAN('i', "include", &also, "add specified files to index for commit"),
OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
+ OPT_BOOLEAN('p', "patch", &patch_interactive, "interactively add changes"),
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
@@ -316,7 +317,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
old_index_env = getenv(INDEX_ENVIRONMENT);
setenv(INDEX_ENVIRONMENT, index_lock.filename, 1);
- if (interactive_add(argc, argv, prefix) != 0)
+ if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
die("interactive add failed");
if (old_index_env && *old_index_env)
@@ -989,8 +990,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
use_message_buffer = xstrdup(commit->buffer);
}
+ if (patch_interactive)
+ interactive = 1;
+
if (!!also + !!only + !!all + !!interactive > 1)
- die("Only one of --include/--only/--all/--interactive can be used.");
+ die("Only one of --include/--only/--all/--interactive/--patch can be used.");
if (argc == 0 && (also || (only && !amend)))
die("No paths with --include/--only does not make sense.");
if (argc == 0 && only && amend)
diff --git a/commit.h b/commit.h
index eb6c5af..951c22e 100644
--- a/commit.h
+++ b/commit.h
@@ -160,7 +160,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int is_descendant_of(struct commit *, struct commit_list *);
int in_merge_bases(struct commit *, struct commit **, int);
-extern int interactive_add(int argc, const char **argv, const char *prefix);
+extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
extern int run_add_interactive(const char *revision, const char *patch_mode,
const char **pathspec);
--
1.7.4.1.g1c7a9.dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] git-commit --patch
2011-02-03 5:25 [PATCH v2] git-commit --patch Conrad Irwin
` (2 preceding siblings ...)
2011-02-03 5:25 ` [PATCH 3/3] Add support for -p/--patch to git-commit Conrad Irwin
@ 2011-02-06 21:06 ` Conrad Irwin
3 siblings, 0 replies; 5+ messages in thread
From: Conrad Irwin @ 2011-02-06 21:06 UTC (permalink / raw)
To: git; +Cc: conrad.irwin
Is there a recommended way of stirring up attention for patchsets like
this, or did I just miss the replies?
Conrad
On 2 February 2011 21:25, Conrad Irwin <conrad.irwin@gmail.com> wrote:
> This patch-set adds support for git-commit --patch, and tidies up some of the
> rough edges of git commit --interactive.
>
> The motivation is to support my current workflow, which goes something like:
>
> 1. Hack out the basic structure of the feature that I'm working on, until I have
> something that looks like it will work.
> 2. Split this into several commits with a more logical flow (i.e. some that add
> support for the techniques I want to use for the actual feature, then the
> feature itself).
> 3. Start fleshing out the implementation, and bug-fixing, with lots of
> git-commit --fixup so that the changes end up in the right commit.
> 4. At the end of the day, a big rebase -i to make the history readable.
>
> This is just about doable with git-add -p, or git-commit --interactive, but
> it's very inefficient. I take the presence of git commit --fixup to imply that
> other people are doing similar, if less extreme things, so assume that they
> would like a git-commit -p too.
>
> Conrad
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-02-06 21:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-03 5:25 [PATCH v2] git-commit --patch Conrad Irwin
2011-02-03 5:25 ` [PATCH 1/3] Use a temporary index for git commit --interactive Conrad Irwin
2011-02-03 5:25 ` [PATCH 2/3] Allow git commit --interactive with paths Conrad Irwin
2011-02-03 5:25 ` [PATCH 3/3] Add support for -p/--patch to git-commit Conrad Irwin
2011-02-06 21:06 ` [PATCH v2] git-commit --patch Conrad Irwin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.