{"thread":{"id":"26396","subject":"[PATCH v2] git-commit --patch","startedAt":"2011-02-03T05:25:29Z","lastAt":"2011-02-06T21:06:31Z","messageCount":5,"participants":["Conrad Irwin"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"160308","messageId":"1296710732-12493-1-git-send-email-conrad.irwin@gmail.com","threadId":"26396","inReplyTo":null,"subject":"[PATCH v2] git-commit --patch","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2011-02-03T05:25:29Z","receivedAt":"2011-02-03T05:25:29Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"This patch-set adds support for git-commit --patch, and tidies up some of the\nrough edges of git commit --interactive.\n\nThe motivation is to support my current workflow, which goes something like:\n\n1. Hack out the basic structure of the feature that I'm working on, until I have\n   something that looks like it will work.\n2. Split this into several commits with a more logical flow (i.e. some that add\n   support for the techniques I want to use for the actual feature, then the\n   feature itself).\n3. Start fleshing out the implementation, and bug-fixing, with lots of\n   git-commit --fixup so that the changes end up in the right commit.\n4. At the end of the day, a big rebase -i to make the history readable.\n\nThis is just about doable with git-add -p, or git-commit --interactive, but\nit's very inefficient. I take the presence of git commit --fixup to imply that\nother people are doing similar, if less extreme things, so assume that they\nwould like a git-commit -p too.\n\nConrad\n"},{"id":"160311","messageId":"1296710732-12493-2-git-send-email-conrad.irwin@gmail.com","threadId":"26396","inReplyTo":"1296710732-12493-1-git-send-email-conrad.irwin@gmail.com","subject":"[PATCH 1/3] Use a temporary index for git commit --interactive","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2011-02-03T05:25:30Z","receivedAt":"2011-02-03T05:25:30Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"Change the behaviour of git commit --interactive so that when you abort\nthe commit (by leaving the commit message empty) the index remains\nunchanged.\n\nHitherto an aborted commit --interactive has added the selected hunks to\nthe index regardless of whether the commit succeeded or not.\n\nSigned-off-by: Conrad Irwin <conrad.irwin@gmail.com>\n---\n Documentation/git-commit.txt |    3 ++-\n builtin/commit.c             |   36 ++++++++++++++++++++++++++++--------\n 2 files changed, 30 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex b586c0f..ca755db 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -41,7 +41,8 @@ The content to be added can be specified in several ways:\n \n 5. by using the --interactive switch with the 'commit' command to decide one\n    by one which files should be part of the commit, before finalizing the\n-   operation.  Currently, this is done by invoking 'git add --interactive'.\n+   operation.  Currently, this is done by invoking 'git add --interactive'\n+   on a temporary index.\n \n The `--dry-run` option can be used to obtain a\n summary of what is included by any of the above for the next\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 03cff5a..41f0e2e 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -292,18 +292,11 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \tint fd;\n \tstruct string_list partial;\n \tconst char **pathspec = NULL;\n+\tchar *old_index_env = NULL;\n \tint refresh_flags = REFRESH_QUIET;\n \n \tif (is_status)\n \t\trefresh_flags |= REFRESH_UNMERGED;\n-\tif (interactive) {\n-\t\tif (interactive_add(argc, argv, prefix) != 0)\n-\t\t\tdie(\"interactive add failed\");\n-\t\tif (read_cache_preload(NULL) < 0)\n-\t\t\tdie(\"index file corrupt\");\n-\t\tcommit_style = COMMIT_AS_IS;\n-\t\treturn get_index_file();\n-\t}\n \n \tif (*argv)\n \t\tpathspec = get_pathspec(prefix, argv);\n@@ -311,6 +304,33 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \tif (read_cache_preload(pathspec) < 0)\n \t\tdie(\"index file corrupt\");\n \n+\tif (interactive) {\n+\t\tfd = hold_locked_index(&index_lock, 1);\n+\n+\t\trefresh_cache_or_die(refresh_flags);\n+\n+\t\tif (write_cache(fd, active_cache, active_nr) ||\n+\t\t    close_lock_file(&index_lock))\n+\t\t\tdie(\"unable to write new_index file\");\n+\n+\t\told_index_env = getenv(INDEX_ENVIRONMENT);\n+\t\tsetenv(INDEX_ENVIRONMENT, index_lock.filename, 1);\n+\n+\t\tif (interactive_add(argc, argv, prefix) != 0)\n+\t\t\tdie(\"interactive add failed\");\n+\n+\t\tif (old_index_env && *old_index_env)\n+\t\t\tsetenv(INDEX_ENVIRONMENT, old_index_env, 1);\n+\t\telse\n+\t\t\tunsetenv(INDEX_ENVIRONMENT);\n+\n+\t\tdiscard_cache();\n+\t\tread_cache_from(index_lock.filename);\n+\n+\t\tcommit_style = COMMIT_NORMAL;\n+\t\treturn index_lock.filename;\n+\t}\n+\n \t/*\n \t * Non partial, non as-is commit.\n \t *\n-- \n1.7.4.1.g1c7a9.dirty\n"},{"id":"160310","messageId":"1296710732-12493-3-git-send-email-conrad.irwin@gmail.com","threadId":"26396","inReplyTo":"1296710732-12493-1-git-send-email-conrad.irwin@gmail.com","subject":"[PATCH 2/3] Allow git commit --interactive with paths","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2011-02-03T05:25:31Z","receivedAt":"2011-02-03T05:25:31Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"Make git commit --interactive feel more like git add --interactive by\nallowing the user to restrict the list of files they have to deal with.\n\nSigned-off-by: Conrad Irwin <conrad.irwin@gmail.com>\n---\n builtin/commit.c |    2 --\n 1 files changed, 0 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 41f0e2e..592c2d2 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1012,8 +1012,6 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \n \tif (all && argc > 0)\n \t\tdie(\"Paths with -a does not make sense.\");\n-\telse if (interactive && argc > 0)\n-\t\tdie(\"Paths with --interactive does not make sense.\");\n \n \tif (null_termination && status_format == STATUS_FORMAT_LONG)\n \t\tstatus_format = STATUS_FORMAT_PORCELAIN;\n-- \n1.7.4.1.g1c7a9.dirty\n"},{"id":"160309","messageId":"1296710732-12493-4-git-send-email-conrad.irwin@gmail.com","threadId":"26396","inReplyTo":"1296710732-12493-1-git-send-email-conrad.irwin@gmail.com","subject":"[PATCH 3/3] Add support for -p/--patch to git-commit","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2011-02-03T05:25:32Z","receivedAt":"2011-02-03T05:25:32Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"The --interactive flag is already shared by git add and git commit,\nshare the -p and --patch flags too.\n\nSigned-off-by: Conrad Irwin <conrad.irwin@gmail.com>\n---\n Documentation/git-commit.txt |   25 ++++++++++++++++---------\n builtin/add.c                |    6 +++---\n builtin/commit.c             |   10 +++++++---\n commit.h                     |    2 +-\n 4 files changed, 27 insertions(+), 16 deletions(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex ca755db..81156f0 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -8,11 +8,12 @@ git-commit - Record changes to the repository\n SYNOPSIS\n --------\n [verse]\n-'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]\n-\t   [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>]\n-\t   [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]\n-\t   [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]\n-\t   [--status | --no-status] [-i | -o] [--] [<file>...]\n+'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]\n+\t   [--dry-run] [(-c | -C | --fixup | --squash) <commit>]\n+\t   [-F <file> | -m <msg>] [--reset-author] [--allow-empty]\n+\t   [--allow-empty-message] [--no-verify] [-e] [--author=<author>]\n+\t   [--date=<date>] [--cleanup=<mode>] [--status | --no-status]\n+\t   [-i | -o] [--] [<file>...]\n \n DESCRIPTION\n -----------\n@@ -39,10 +40,10 @@ The content to be added can be specified in several ways:\n    that have been removed from the working tree, and then perform the\n    actual commit;\n \n-5. by using the --interactive switch with the 'commit' command to decide one\n-   by one which files should be part of the commit, before finalizing the\n-   operation.  Currently, this is done by invoking 'git add --interactive'\n-   on a temporary index.\n+5. by using the --interactive or --patch switches with the 'commit' command\n+   to decide one by one which files or hunks should be part of the commit,\n+   before finalizing the operation.  Currently, this is done by invoking\n+   'git add --interactive' or 'git add --patch' on a temporary index.\n \n The `--dry-run` option can be used to obtain a\n summary of what is included by any of the above for the next\n@@ -60,6 +61,12 @@ OPTIONS\n \tbeen modified and deleted, but new files you have not\n \ttold git about are not affected.\n \n+-p::\n+--patch::\n+\tUse the interactive patch selection interface to chose\n+\twhich changes to commit. See linkgit:git-add[1] for\n+\tdetails.\n+\n -C <commit>::\n --reuse-message=<commit>::\n \tTake an existing commit object, and reuse the log message\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 12b964e..3d074b3 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -242,7 +242,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,\n \treturn status;\n }\n \n-int interactive_add(int argc, const char **argv, const char *prefix)\n+int interactive_add(int argc, const char **argv, const char *prefix, int patch)\n {\n \tconst char **pathspec = NULL;\n \n@@ -253,7 +253,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)\n \t}\n \n \treturn run_add_interactive(NULL,\n-\t\t\t\t   patch_interactive ? \"--patch\" : NULL,\n+\t\t\t\t   patch ? \"--patch\" : NULL,\n \t\t\t\t   pathspec);\n }\n \n@@ -378,7 +378,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tif (patch_interactive)\n \t\tadd_interactive = 1;\n \tif (add_interactive)\n-\t\texit(interactive_add(argc - 1, argv + 1, prefix));\n+\t\texit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));\n \n \tif (edit_interactive)\n \t\treturn(edit_patch(argc, argv, prefix));\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 592c2d2..0c53dc9 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -70,7 +70,7 @@ static const char *logfile, *force_author;\n static const char *template_file;\n static char *edit_message, *use_message;\n static char *fixup_message, *squash_message;\n-static int all, edit_flag, also, interactive, only, amend, signoff;\n+static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff;\n static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;\n static int no_post_rewrite, allow_empty_message;\n static char *untracked_files_arg, *force_date, *ignore_submodule_arg;\n@@ -138,6 +138,7 @@ static struct option builtin_commit_options[] = {\n \tOPT_BOOLEAN('a', \"all\", &all, \"commit all changed files\"),\n \tOPT_BOOLEAN('i', \"include\", &also, \"add specified files to index for commit\"),\n \tOPT_BOOLEAN(0, \"interactive\", &interactive, \"interactively add files\"),\n+\tOPT_BOOLEAN('p', \"patch\", &patch_interactive, \"interactively add changes\"),\n \tOPT_BOOLEAN('o', \"only\", &only, \"commit only specified files\"),\n \tOPT_BOOLEAN('n', \"no-verify\", &no_verify, \"bypass pre-commit hook\"),\n \tOPT_BOOLEAN(0, \"dry-run\", &dry_run, \"show what would be committed\"),\n@@ -316,7 +317,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \t\told_index_env = getenv(INDEX_ENVIRONMENT);\n \t\tsetenv(INDEX_ENVIRONMENT, index_lock.filename, 1);\n \n-\t\tif (interactive_add(argc, argv, prefix) != 0)\n+\t\tif (interactive_add(argc, argv, prefix, patch_interactive) != 0)\n \t\t\tdie(\"interactive add failed\");\n \n \t\tif (old_index_env && *old_index_env)\n@@ -989,8 +990,11 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \t\t\tuse_message_buffer = xstrdup(commit->buffer);\n \t}\n \n+\tif (patch_interactive)\n+\t\tinteractive = 1;\n+\n \tif (!!also + !!only + !!all + !!interactive > 1)\n-\t\tdie(\"Only one of --include/--only/--all/--interactive can be used.\");\n+\t\tdie(\"Only one of --include/--only/--all/--interactive/--patch can be used.\");\n \tif (argc == 0 && (also || (only && !amend)))\n \t\tdie(\"No paths with --include/--only does not make sense.\");\n \tif (argc == 0 && only && amend)\ndiff --git a/commit.h b/commit.h\nindex eb6c5af..951c22e 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -160,7 +160,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,\n int is_descendant_of(struct commit *, struct commit_list *);\n int in_merge_bases(struct commit *, struct commit **, int);\n \n-extern int interactive_add(int argc, const char **argv, const char *prefix);\n+extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);\n extern int run_add_interactive(const char *revision, const char *patch_mode,\n \t\t\t       const char **pathspec);\n \n-- \n1.7.4.1.g1c7a9.dirty\n"},{"id":"160551","messageId":"AANLkTimCS0Tj7KosZ7RJK8Q9ucxw-0qr-aV-KrbqHMHU@mail.gmail.com","threadId":"26396","inReplyTo":"1296710732-12493-1-git-send-email-conrad.irwin@gmail.com","subject":"Re: [PATCH v2] git-commit --patch","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2011-02-06T21:06:31Z","receivedAt":"2011-02-06T21:06:31Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"Is there a recommended way of stirring up attention for patchsets like\nthis, or did I just miss the replies?\n\nConrad\n\nOn 2 February 2011 21:25, Conrad Irwin <conrad.irwin@gmail.com> wrote:\n> This patch-set adds support for git-commit --patch, and tidies up some of the\n> rough edges of git commit --interactive.\n>\n> The motivation is to support my current workflow, which goes something like:\n>\n> 1. Hack out the basic structure of the feature that I'm working on, until I have\n>   something that looks like it will work.\n> 2. Split this into several commits with a more logical flow (i.e. some that add\n>   support for the techniques I want to use for the actual feature, then the\n>   feature itself).\n> 3. Start fleshing out the implementation, and bug-fixing, with lots of\n>   git-commit --fixup so that the changes end up in the right commit.\n> 4. At the end of the day, a big rebase -i to make the history readable.\n>\n> This is just about doable with git-add -p, or git-commit --interactive, but\n> it's very inefficient. I take the presence of git commit --fixup to imply that\n> other people are doing similar, if less extreme things, so assume that they\n> would like a git-commit -p too.\n>\n> Conrad\n>\n>\n"}]}