{"thread":{"id":"26138","subject":"[PATCH] Add support for -p/--patch to git-commit","startedAt":"2010-12-26T15:36:34Z","lastAt":"2010-12-26T17:56:09Z","messageCount":3,"participants":["Conrad Irwin","Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"158592","messageId":"E1PWsuV-0000FH-90@scarlatti.dunvegan.biz","threadId":"26138","inReplyTo":null,"subject":"[PATCH] Add support for -p/--patch to git-commit","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2010-12-26T15:36:34Z","receivedAt":"2010-12-26T15:36:34Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"This works in the same was as git commit --interactive, and is\nequivalent to running git add -p before git commit.\n\nSigned-off-by: Conrad Irwin <conrad.irwin@gmail.com>\n---\n\nHello Git,\n\nPlease let me know of any mistakes I've made, this is a first for me.\n\nWhile this patch works as advertised, I wonder if it would be nicer to\nchange the behaviour of git commit --interactive and git commit -p to\nact on a temporary copy of the index rather than mutating the existing\nindex. I've no idea how to go about that yet, but is it something that\nshould be changed?\n\nConrad\n\n Documentation/git-commit.txt |   24 ++++++++++++++++--------\n builtin/add.c                |    6 +++---\n builtin/commit.c             |   11 ++++++-----\n commit.h                     |    2 +-\n 4 files changed, 26 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex b586c0f..fe3a14f 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,9 +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+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'.\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@@ -59,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 22ba54f..0ae3262 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@@ -296,8 +297,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \n \tif (is_status)\n \t\trefresh_flags |= REFRESH_UNMERGED;\n-\tif (interactive) {\n-\t\tif (interactive_add(argc, argv, prefix) != 0)\n+\tif (interactive || patch_interactive) {\n+\t\tif (interactive_add(argc, argv, prefix, patch_interactive) != 0)\n \t\t\tdie(\"interactive add failed\");\n \t\tif (read_cache_preload(NULL) < 0)\n \t\t\tdie(\"index file corrupt\");\n@@ -969,8 +970,8 @@ 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 (!!also + !!only + !!all + !!interactive > 1)\n-\t\tdie(\"Only one of --include/--only/--all/--interactive can be used.\");\n+\tif (!!also + !!only + !!all + !!interactive + !!patch_interactive > 1)\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.2.3\n"},{"id":"158593","messageId":"vpqr5d4cx9e.fsf@bauges.imag.fr","threadId":"26138","inReplyTo":"E1PWsuV-0000FH-90@scarlatti.dunvegan.biz","subject":"Re: [PATCH] Add support for -p/--patch to git-commit","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-12-26T16:30:21Z","receivedAt":"2010-12-26T16:30:21Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Conrad Irwin <conrad.irwin@gmail.com> writes:\n\n> Hello Git,\n>\n> Please let me know of any mistakes I've made, this is a first for\n> me.\n\nAt least one mistake:\n\nTo: unlisted-recipients:; (no To-header on input)\n\n(I guess you've Bcc-ed the Git list, please don't do that)\n\n> While this patch works as advertised, I wonder if it would be nicer to\n> change the behaviour of git commit --interactive and git commit -p to\n> act on a temporary copy of the index rather than mutating the existing\n> index. I've no idea how to go about that yet, but is it something that\n> should be changed?\n\nI don't think so. After a commit, I usually expect the index to be\nclean, ready to start preparing the next commit (except if I\nexplicitely asked the opposite), which implies that the index used for\ncommit (-i|-p) is the same as the usual one.\n\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'.\n\n... or git add --patch.\n\n> -\tif (!!also + !!only + !!all + !!interactive > 1)\n> -\t\tdie(\"Only one of --include/--only/--all/--interactive can be used.\");\n> +\tif (!!also + !!only + !!all + !!interactive + !!patch_interactive > 1)\n> +\t\tdie(\"Only one of --include/--only/--all/--interactive/--patch can be used.\");\n\nIf I read correctly, this forbids \"git commit --interactive --patch\",\nwhile \"git add --interactive --patch\" is allowed, and equivalent to\n\"--patch\" alone.\n\nOther than that, the patch looks good.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"158594","messageId":"E1PWvWg-000293-WA@scarlatti.dunvegan.biz","threadId":"26138","inReplyTo":"vpqr5d4cx9e.fsf@bauges.imag.fr","subject":"Re: [PATCH] Add support for -p/--patch to git-commit","fromName":"Conrad Irwin","fromEmail":"conrad.irwin@gmail.com","sentAt":"2010-12-26T17:56:09Z","receivedAt":"2010-12-26T17:56:09Z","isPatch":true,"sender":{"key":"conrad.irwin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94272?v=4"},"body":"This works in the same was as git commit --interactive, and is\nequivalent to running git add -p before git commit.\n\nSigned-off-by: Conrad Irwin <conrad.irwin@gmail.com>\n---\n\nOn 26 December 2010 16:30, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n>\n> At least one mistake:\n>\n> To: unlisted-recipients:; (no To-header on input)\n>\n> (I guess you've Bcc-ed the Git list, please don't do that)\n\nSorry, failed to use sendmail. (having read dire warnings about sending\npatches with gmail), second time lucky...\n\n> > While this patch works as advertised, I wonder if it would be nicer to\n> > change the behaviour of git commit --interactive and git commit -p to\n> > act on a temporary copy of the index rather than mutating the existing\n> > index. I've no idea how to go about that yet, but is it something that\n> > should be changed?\n>\n> I don't think so. After a commit, I usually expect the index to be\n> clean, ready to start preparing the next commit (except if I\n> explicitely asked the opposite), which implies that the index used for\n> commit (-i|-p) is the same as the usual one.\n\nThe reason I suggested this is so that if you abort the commit (by\nleaving the commit message empty), the index would be unchanged; at the\nmoment if you abort the commit the git-add is remembered. Certainly any\nchanges committed would be removed from the index. It also would allow\nfor git commit -p --only instead of having it always work like --include\n(which might even be better default behaviour). (It's also worth noting\nthat git commit -i is --include, not --interactive)\n\n>\n> If I read correctly, this forbids \"git commit --interactive --patch\",\n> while \"git add --interactive --patch\" is allowed, and equivalent to\n> \"--patch\" alone.\n\nWell spotted :). Relatedly, git-commit currently forbids --interactive\nwith paths, which should also be changed (though in a different commit I\nassume); I did not copy that limitation to --patch.\n\nI've updated this patch, thank you very much for the feedback.\n\nConrad\n\n\n Documentation/git-commit.txt |   24 ++++++++++++++++--------\n builtin/add.c                |    6 +++---\n builtin/commit.c             |   11 ++++++-----\n commit.h                     |    2 +-\n 4 files changed, 26 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex b586c0f..6e7ab5a 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,9 +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+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'.\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@@ -59,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 22ba54f..454308e 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@@ -296,8 +297,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \n \tif (is_status)\n \t\trefresh_flags |= REFRESH_UNMERGED;\n-\tif (interactive) {\n-\t\tif (interactive_add(argc, argv, prefix) != 0)\n+\tif (interactive || patch_interactive) {\n+\t\tif (interactive_add(argc, argv, prefix, patch_interactive) != 0)\n \t\t\tdie(\"interactive add failed\");\n \t\tif (read_cache_preload(NULL) < 0)\n \t\t\tdie(\"index file corrupt\");\n@@ -969,8 +970,8 @@ 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 (!!also + !!only + !!all + !!interactive > 1)\n-\t\tdie(\"Only one of --include/--only/--all/--interactive can be used.\");\n+\tif (!!also + !!only + !!all + !!(interactive || patch_interactive) > 1)\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.3.4.627.g3cfc9\n"}]}