From: Junio C Hamano <gitster@pobox.com>
To: Martin von Zweigbergk <martinvonz@gmail.com>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [PATCH 03/19] reset.c: pass pathspec around instead of (prefix, argv) pair
Date: Wed, 09 Jan 2013 11:26:56 -0800 [thread overview]
Message-ID: <7vy5g25f9b.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1357719376-16406-4-git-send-email-martinvonz@gmail.com> (Martin von Zweigbergk's message of "Wed, 9 Jan 2013 00:16:00 -0800")
Martin von Zweigbergk <martinvonz@gmail.com> writes:
> We use the path arguments in two places in reset.c: in
> interactive_reset() and read_from_tree(). Both of these call
> get_pathspec(), so we pass the (prefix, arv) pair to both
> functions. Move the call to get_pathspec() out of these methods, for
> two reasons: 1) One argument is simpler than two. 2) It lets us use
> the (arguably clearer) "if (pathspec)" in place of "if (i < argc)".
> ---
> If I understand correctly, this should be rebased on top of
> nd/parse-pathspec. Please let me know.
Yeah, this will conflict with the get_pathspec-to-parse_pathspec
conversion Duy has been working on.
Without the interactions with that topic, the conversion seems
straightforward to me, though.
>
> builtin/reset.c | 27 ++++++++++-----------------
> 1 file changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/builtin/reset.c b/builtin/reset.c
> index 65413d0..045c960 100644
> --- a/builtin/reset.c
> +++ b/builtin/reset.c
> @@ -153,26 +153,15 @@ static void update_index_from_diff(struct diff_queue_struct *q,
> }
> }
>
> -static int interactive_reset(const char *revision, const char **argv,
> - const char *prefix)
> -{
> - const char **pathspec = NULL;
> -
> - if (*argv)
> - pathspec = get_pathspec(prefix, argv);
> -
> - return run_add_interactive(revision, "--patch=reset", pathspec);
> -}
> -
> -static int read_from_tree(const char *prefix, const char **argv,
> - unsigned char *tree_sha1, int refresh_flags)
> +static int read_from_tree(const char **pathspec, unsigned char *tree_sha1,
> + int refresh_flags)
> {
> struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
> int index_fd;
> struct diff_options opt;
>
> memset(&opt, 0, sizeof(opt));
> - diff_tree_setup_paths(get_pathspec(prefix, (const char **)argv), &opt);
> + diff_tree_setup_paths(pathspec, &opt);
> opt.output_format = DIFF_FORMAT_CALLBACK;
> opt.format_callback = update_index_from_diff;
>
> @@ -216,6 +205,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
> const char *rev = "HEAD";
> unsigned char sha1[20], *orig = NULL, sha1_orig[20],
> *old_orig = NULL, sha1_old_orig[20];
> + const char **pathspec = NULL;
> struct commit *commit;
> struct strbuf msg = STRBUF_INIT;
> const struct option options[] = {
> @@ -287,22 +277,25 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
> die(_("Could not parse object '%s'."), rev);
> hashcpy(sha1, commit->object.sha1);
>
> + if (i < argc)
> + pathspec = get_pathspec(prefix, argv + i);
> +
> if (patch_mode) {
> if (reset_type != NONE)
> die(_("--patch is incompatible with --{hard,mixed,soft}"));
> - return interactive_reset(rev, argv + i, prefix);
> + return run_add_interactive(rev, "--patch=reset", pathspec);
> }
>
> /* git reset tree [--] paths... can be used to
> * load chosen paths from the tree into the index without
> * affecting the working tree nor HEAD. */
> - if (i < argc) {
> + if (pathspec) {
> if (reset_type == MIXED)
> warning(_("--mixed with paths is deprecated; use 'git reset -- <paths>' instead."));
> else if (reset_type != NONE)
> die(_("Cannot do %s reset with paths."),
> _(reset_type_names[reset_type]));
> - return read_from_tree(prefix, argv + i, sha1,
> + return read_from_tree(pathspec, sha1,
> quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
> }
> if (reset_type == NONE)
next prev parent reply other threads:[~2013-01-09 19:27 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-09 8:15 [PATCH 00/19] reset improvements Martin von Zweigbergk
2013-01-09 8:15 ` [PATCH 01/19] reset $pathspec: no need to discard index Martin von Zweigbergk
2013-01-09 8:15 ` [PATCH 02/19] reset $pathspec: exit with code 0 if successful Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 03/19] reset.c: pass pathspec around instead of (prefix, argv) pair Martin von Zweigbergk
2013-01-09 11:42 ` Matt Kraai
2013-01-09 19:26 ` Junio C Hamano [this message]
2013-01-10 11:05 ` Duy Nguyen
2013-01-10 23:09 ` Junio C Hamano
2013-01-11 11:10 ` Duy Nguyen
2013-01-09 8:16 ` [PATCH 04/19] reset: don't allow "git reset -- $pathspec" in bare repo Martin von Zweigbergk
2013-01-09 19:32 ` Junio C Hamano
2013-01-10 8:24 ` Martin von Zweigbergk
2013-01-10 18:04 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 05/19] reset.c: extract function for parsing arguments Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 06/19] reset.c: remove unnecessary variable 'i' Martin von Zweigbergk
2013-01-09 19:39 ` Junio C Hamano
2013-01-10 8:41 ` Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 07/19] reset.c: extract function for updating {ORIG,}HEAD Martin von Zweigbergk
2013-01-09 11:54 ` Matt Kraai
2013-01-09 8:16 ` [PATCH 08/19] reset.c: share call to die_if_unmerged_cache() Martin von Zweigbergk
2013-01-09 19:48 ` Junio C Hamano
2013-01-10 8:51 ` Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 09/19] reset.c: replace switch by if-else Martin von Zweigbergk
2013-01-09 19:53 ` Junio C Hamano
2013-01-11 6:35 ` Martin von Zweigbergk
2013-01-11 17:12 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 10/19] reset --keep: only write index file once Martin von Zweigbergk
2013-01-09 19:55 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 11/19] reset: avoid redundant error message Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 12/19] reset.c: move update_index_refresh() call out of read_from_tree() Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 13/19] reset.c: move lock, write and commit out of update_index_refresh() Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 14/19] reset [--mixed]: don't write index file twice Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 15/19] reset.c: finish entire cmd_reset() whether or not pathspec is given Martin von Zweigbergk
2013-01-09 19:59 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 16/19] reset [--mixed] --quiet: don't refresh index Martin von Zweigbergk
2013-01-09 17:01 ` Jeff King
2013-01-09 18:43 ` Martin von Zweigbergk
2013-01-09 19:12 ` Junio C Hamano
2013-01-09 19:38 ` Martin von Zweigbergk
2013-01-09 20:05 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 17/19] reset $sha1 $pathspec: require $sha1 only to be treeish Martin von Zweigbergk
2013-01-09 20:23 ` Junio C Hamano
2013-01-09 8:16 ` [PATCH 18/19] reset: allow reset on unborn branch Martin von Zweigbergk
2013-01-09 8:16 ` [PATCH 19/19] reset [--mixed]: use diff-based reset whether or not pathspec was given Martin von Zweigbergk
2013-01-09 20:27 ` Junio C Hamano
2013-01-15 5:47 ` [PATCH v2 00/19] reset improvements Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 01/19] reset $pathspec: no need to discard index Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 02/19] reset $pathspec: exit with code 0 if successful Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 03/19] reset.c: pass pathspec around instead of (prefix, argv) pair Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 04/19] reset: don't allow "git reset -- $pathspec" in bare repo Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 05/19] reset.c: extract function for parsing arguments Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 06/19] reset.c: remove unnecessary variable 'i' Martin von Zweigbergk
[not found] ` <A5E8E180685CEF45AB9E737A010799805E00DD@cdnz-ex1.corp.cubic.cub>
2013-01-15 18:36 ` Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 07/19] reset.c: extract function for updating {ORIG_,}HEAD Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 08/19] reset.c: share call to die_if_unmerged_cache() Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 09/19] reset --keep: only write index file once Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 10/19] reset: avoid redundant error message Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 11/19] reset.c: replace switch by if-else Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 12/19] reset.c: move update_index_refresh() call out of read_from_tree() Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 13/19] reset.c: move lock, write and commit out of update_index_refresh() Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 14/19] reset [--mixed]: only write index file once Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 15/19] reset.c: finish entire cmd_reset() whether or not pathspec is given Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 16/19] reset.c: inline update_index_refresh() Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 17/19] reset $sha1 $pathspec: require $sha1 only to be treeish Martin von Zweigbergk
2013-01-16 18:00 ` [PATCH v2 17/19] fixup! " Martin von Zweigbergk
2013-01-16 18:08 ` Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 18/19] reset: allow reset on unborn branch Martin von Zweigbergk
2013-01-15 5:47 ` [PATCH v2 19/19] reset [--mixed]: use diff-based reset whether or not pathspec was given Martin von Zweigbergk
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=7vy5g25f9b.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=martinvonz@gmail.com \
--cc=pclouds@gmail.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.
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).