From: Phillip Wood <phillip.wood123@gmail.com>
To: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>,
phillip.wood@dunelm.org.uk,
Alexandr Miloslavskiy via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 5/5] commit: support the --pathspec-from-file option
Date: Tue, 10 Dec 2019 10:42:37 +0000 [thread overview]
Message-ID: <4401823b-8039-99b4-2436-ed2f1a571d78@gmail.com> (raw)
In-Reply-To: <25aaaca1-1c88-d2c6-b502-cd35752ce745@syntevo.com>
Hi Alexandr
Sorry it has taken me so long to reply
On 06/11/2019 15:56, Alexandr Miloslavskiy wrote:
> I think I have implemented most suggestions in PatchV2. Thanks!
>
>> It might be worth tailoring the message to the command rather than
>> having exactly the same message for commit and reset
>
> I decided to move the general comment to base commit where options are
> introduced and not repeat it where options are supported.
>
>> I wonder if there is a way of calling parse_pathspec_file() from
>> parse_and_validate_options() instead. Otherwise we end up validating
>> options here instead which is a bit messy.
>
> The code looks a bit too entangled to support that without making it
> worse. The biggest concern I have is that parse_and_validate_options()
> will populate `pathspec` and some other function will need to remember
> to clean it up. I like it better when `pathspec` is handled in one place.
I don't think it's so bad if the pathspec is cleaned up just after it is used,
the diff below applies on top of your patch - see what you think. The diff
also adds dies if --all is given with --pathspec-from-file which (together
with a test) would be worth adding to you series I think.
>
> I agree that things are not perfect, but this seems to be a consequence
> of other existing problems. For example, I would have expected a
> structure instead of a handful of global variables. That would have
> solved many problems. However, I didn't have the bravery to dive into
> this refactoring.
Yes it is a pain that the builtin functions tend to use a lot of global
variables rather than a structure.
Best Wishes
Phillip
--- >8 ---
diff --git a/builtin/commit.c b/builtin/commit.c
index ed40729355..bb9515c44b 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -330,37 +330,18 @@ static void refresh_cache_or_die(int refresh_flags)
}
static const char *prepare_index(int argc, const char **argv, const char *prefix,
+ struct pathspec *pathspec,
const struct commit *current_head, int is_status)
{
struct string_list partial = STRING_LIST_INIT_DUP;
- struct pathspec pathspec;
+
int refresh_flags = REFRESH_QUIET;
const char *ret;
if (is_status)
refresh_flags |= REFRESH_UNMERGED;
- parse_pathspec(&pathspec, 0,
- PATHSPEC_PREFER_FULL,
- prefix, argv);
- if (pathspec_from_file) {
- if (interactive)
- die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
-
- if (pathspec.nr)
- die(_("--pathspec-from-file is incompatible with pathspec arguments"));
-
- parse_pathspec_file(&pathspec, 0,
- PATHSPEC_PREFER_FULL,
- prefix, pathspec_from_file, pathspec_file_nul);
- } else if (pathspec_file_nul) {
- die(_("--pathspec-file-nul requires --pathspec-from-file"));
- }
-
- if (!pathspec.nr && (also || (only && !amend && !allow_empty)))
- die(_("No paths with --include/--only does not make sense."));
-
- if (read_cache_preload(&pathspec) < 0)
+ if (read_cache_preload(pathspec) < 0)
die(_("index file corrupt"));
if (interactive) {
@@ -411,9 +392,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
* (A) if all goes well, commit the real index;
* (B) on failure, rollback the real index.
*/
- if (all || (also && pathspec.nr)) {
+ if (all || (also && pathspec->nr)) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
- add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+ add_files_to_cache(also ? prefix : NULL, pathspec, 0);
refresh_cache_or_die(refresh_flags);
update_main_cache_tree(WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock, 0))
@@ -432,7 +413,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
* and create commit from the_index.
* We still need to refresh the index here.
*/
- if (!only && !pathspec.nr) {
+ if (!only && !pathspec->nr) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
refresh_cache_or_die(refresh_flags);
if (active_cache_changed
@@ -474,7 +455,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
die(_("cannot do a partial commit during a cherry-pick."));
}
- if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec))
+ if (list_paths(&partial, !current_head ? NULL : "HEAD", pathspec))
exit(1);
discard_cache();
@@ -505,7 +486,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
read_cache_from(ret);
out:
string_list_clear(&partial, 0);
- clear_pathspec(&pathspec);
+ clear_pathspec(pathspec);
return ret;
}
@@ -1148,6 +1129,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
const struct option *options,
const char * const usage[],
const char *prefix,
+ struct pathspec *pathspec,
struct commit *current_head,
struct wt_status *s)
{
@@ -1223,19 +1205,42 @@ static int parse_and_validate_options(int argc, const char *argv[],
die(_("paths '%s ...' with -a does not make sense"),
argv[0]);
+ if (pathspec_from_file) {
+ if (interactive)
+ die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
+
+ if (argc)
+ die(_("--pathspec-from-file is incompatible with pathspec arguments"));
+
+ if (all)
+ die(_("--pathspec-from-file is incompatible with --all"));
+
+ parse_pathspec_file(pathspec, 0,
+ PATHSPEC_PREFER_FULL,
+ prefix, pathspec_from_file, pathspec_file_nul);
+ } else if (pathspec_file_nul) {
+ die(_("--pathspec-file-nul requires --pathspec-from-file"));
+ } else {
+ parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, prefix, argv);
+ }
+
+ if (!pathspec->nr && (also || (only && !amend && !allow_empty)))
+ die(_("No paths with --include/--only does not make sense."));
+
if (status_format != STATUS_FORMAT_NONE)
dry_run = 1;
return argc;
}
static int dry_run_commit(int argc, const char **argv, const char *prefix,
+ struct pathspec *pathspec,
const struct commit *current_head, struct wt_status *s)
{
int committable;
const char *index_file;
- index_file = prepare_index(argc, argv, prefix, current_head, 1);
+ index_file = prepare_index(argc, argv, prefix, pathspec, current_head, 1);
committable = run_status(stdout, index_file, prefix, 0, s);
rollback_index_files();
@@ -1571,6 +1576,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
struct commit *current_head = NULL;
struct commit_extra_header *extra = NULL;
struct strbuf err = STRBUF_INIT;
+ struct pathspec pathspec;
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_commit_usage, builtin_commit_options);
@@ -1590,13 +1596,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
verbose = -1; /* unspecified */
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
builtin_commit_usage,
- prefix, current_head, &s);
+ prefix, &pathspec, current_head, &s);
if (verbose == -1)
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
if (dry_run)
- return dry_run_commit(argc, argv, prefix, current_head, &s);
- index_file = prepare_index(argc, argv, prefix, current_head, 0);
+ return dry_run_commit(argc, argv, prefix, &pathspec,
+ current_head, &s);
+ index_file = prepare_index(argc, argv, prefix, &pathspec, current_head,
+ 0);
/* Set up everything for writing the commit object. This includes
running hooks, writing the trees, and interacting with the user. */
next prev parent reply other threads:[~2019-12-10 10:42 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 19:26 [PATCH 0/5] Add --pathspec-from-file option for reset, commit Alexandr Miloslavskiy via GitGitGadget
2019-11-04 19:26 ` [PATCH 1/5] pathspec: add new function to parse file Alexandr Miloslavskiy via GitGitGadget
2019-11-05 15:02 ` Phillip Wood
2019-11-05 19:14 ` Alexandr Miloslavskiy
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-11-04 19:26 ` [PATCH 2/5] doc: reset: unify <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-06 4:01 ` Junio C Hamano
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-11-07 5:46 ` Junio C Hamano
2019-11-07 11:05 ` Alexandr Miloslavskiy
2019-11-08 3:04 ` Junio C Hamano
2019-11-04 19:26 ` [PATCH 3/5] reset: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-11-05 15:03 ` Phillip Wood
2019-11-05 19:22 ` Phillip Wood
2019-11-05 19:36 ` Alexandr Miloslavskiy
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-11-05 16:14 ` Phillip Wood
2019-11-05 19:37 ` Alexandr Miloslavskiy
2019-11-06 4:40 ` Junio C Hamano
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-11-04 19:26 ` [PATCH 4/5] doc: commit: unify <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-06 4:50 ` Junio C Hamano
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-11-07 5:54 ` Junio C Hamano
2019-11-07 11:39 ` Alexandr Miloslavskiy
2019-11-04 19:26 ` [PATCH 5/5] commit: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-11-05 16:27 ` Phillip Wood
2019-11-05 19:42 ` Alexandr Miloslavskiy
2019-11-06 15:56 ` Alexandr Miloslavskiy
2019-12-10 10:42 ` Phillip Wood [this message]
2019-12-11 11:43 ` Alexandr Miloslavskiy
2019-12-11 14:27 ` Phillip Wood
2019-12-11 15:06 ` Alexandr Miloslavskiy
2019-12-11 16:14 ` Junio C Hamano
2019-12-11 16:20 ` Alexandr Miloslavskiy
2019-12-12 14:56 ` Alexandr Miloslavskiy
2019-11-06 4:51 ` Junio C Hamano
2019-11-06 15:51 ` [PATCH v2 0/6] Add --pathspec-from-file option for reset, commit Alexandr Miloslavskiy via GitGitGadget
2019-11-06 15:51 ` [PATCH v2 1/6] parse-options.h: add new options `--pathspec-from-file`, `--pathspec-file-nul` Alexandr Miloslavskiy via GitGitGadget
2019-11-06 15:51 ` [PATCH v2 2/6] pathspec: add new function to parse file Alexandr Miloslavskiy via GitGitGadget
2019-11-19 5:59 ` Junio C Hamano
2019-11-19 16:50 ` Alexandr Miloslavskiy
2019-11-06 15:51 ` [PATCH v2 3/6] doc: reset: unify <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-19 6:05 ` Junio C Hamano
2019-11-19 16:52 ` Alexandr Miloslavskiy
2019-11-06 15:51 ` [PATCH v2 4/6] reset: support the `--pathspec-from-file` option Alexandr Miloslavskiy via GitGitGadget
2019-11-06 15:51 ` [PATCH v2 5/6] doc: commit: unify <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-19 6:16 ` Junio C Hamano
2019-11-19 16:53 ` Alexandr Miloslavskiy
2019-11-19 17:02 ` Alexandr Miloslavskiy
2019-11-06 15:51 ` [PATCH v2 6/6] commit: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-11-19 6:10 ` Junio C Hamano
2019-11-19 16:56 ` Alexandr Miloslavskiy
2019-11-19 16:48 ` [PATCH v3 0/6] Add --pathspec-from-file option for reset, commit Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 1/6] parse-options.h: add new options `--pathspec-from-file`, `--pathspec-file-nul` Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 2/6] pathspec: add new function to parse file Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 3/6] doc: reset: synchronize <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 4/6] reset: support the `--pathspec-from-file` option Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 5/6] doc: commit: synchronize <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-11-19 16:48 ` [PATCH v3 6/6] commit: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-11-20 4:04 ` [PATCH v3 0/6] Add --pathspec-from-file option for reset, commit Junio C Hamano
2019-11-20 9:22 ` Alexandr Miloslavskiy
2019-12-03 14:02 ` [PATCH v4 00/13] Add --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 01/13] parse-options.h: add new options `--pathspec-from-file`, `--pathspec-file-nul` Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 02/13] pathspec: add new function to parse file Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 03/13] doc: reset: synchronize <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 04/13] reset: support the `--pathspec-from-file` option Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 05/13] doc: commit: synchronize <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 06/13] commit: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 07/13] cmd_add: prepare for next patch Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 08/13] add: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 09/13] doc: checkout: remove duplicate synopsis Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 10/13] doc: checkout: fix broken text reference Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 11/13] doc: checkout: synchronize <pathspec> description Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 12/13] doc: restore: " Alexandr Miloslavskiy via GitGitGadget
2019-12-03 14:02 ` [PATCH v4 13/13] checkout, restore: support the --pathspec-from-file option Alexandr Miloslavskiy via GitGitGadget
2019-12-03 16:55 ` [PATCH v4 00/13] Add " Junio C Hamano
2019-12-03 17:06 ` Alexandr Miloslavskiy
2019-12-04 19:25 ` Junio C Hamano
2019-12-05 10:43 ` Alexandr Miloslavskiy
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4401823b-8039-99b4-2436-ed2f1a571d78@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=alexandr.miloslavskiy@syntevo.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).