From: Martin von Zweigbergk <martinvonz@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Matt Kraai <kraai@ftbfs.org>,
Ramsay Jones <ramsay@ramsay1.demon.co.uk>,
Duy Nguyen <pclouds@gmail.com>, Jeff King <peff@peff.net>,
Martin von Zweigbergk <martinvonz@gmail.com>
Subject: [PATCH v2 17/19] reset $sha1 $pathspec: require $sha1 only to be treeish
Date: Mon, 14 Jan 2013 21:47:49 -0800 [thread overview]
Message-ID: <1358228871-7142-18-git-send-email-martinvonz@gmail.com> (raw)
In-Reply-To: <1358228871-7142-1-git-send-email-martinvonz@gmail.com>
Resetting with paths does not update HEAD and there is nothing else
that a commit should be needed for. Relax the argument parsing so only
a tree is required.
The sha1 is only passed to read_from_tree(), which already only
requires a tree.
The "rev" variable we pass to run_add_interactive() will resolve to a
tree. This is fine since interactive_reset only needs the parameter to
be a treeish and doesn't use it for display purposes.
Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com>
---
builtin/reset.c | 48 +++++++++++++++++++++++++++---------------------
t/t7102-reset.sh | 8 ++++++++
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/builtin/reset.c b/builtin/reset.c
index 520c1a5..b776867 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -178,9 +178,10 @@ static const char **parse_args(const char **argv, const char *prefix, const char
/*
* Possible arguments are:
*
- * git reset [-opts] <rev> <paths>...
- * git reset [-opts] <rev> -- <paths>...
- * git reset [-opts] -- <paths>...
+ * git reset [-opts] [<rev>]
+ * git reset [-opts] <tree> [<paths>...]
+ * git reset [-opts] <tree> -- [<paths>...]
+ * git reset [-opts] -- [<paths>...]
* git reset [-opts] <paths>...
*
* At this point, argv points immediately after [-opts].
@@ -195,11 +196,13 @@ static const char **parse_args(const char **argv, const char *prefix, const char
}
/*
* Otherwise, argv[0] could be either <rev> or <paths> and
- * has to be unambiguous.
+ * has to be unambiguous. If there is a single argument, it
+ * can not be a tree
*/
- else if (!get_sha1_committish(argv[0], unused)) {
+ else if ((!argv[1] && !get_sha1_committish(argv[0], unused)) ||
+ (argv[1] && !get_sha1_treeish(argv[0], unused))) {
/*
- * Ok, argv[0] looks like a rev; it should not
+ * Ok, argv[0] looks like a commit/tree; it should not
* be a filename.
*/
verify_non_filename(prefix, argv[0]);
@@ -241,7 +244,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
const char *rev;
unsigned char sha1[20];
const char **pathspec = NULL;
- struct commit *commit;
const struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
OPT_SET_INT(0, "mixed", &reset_type,
@@ -263,19 +265,23 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_DASHDASH);
pathspec = parse_args(argv, prefix, &rev);
- if (get_sha1_committish(rev, sha1))
- die(_("Failed to resolve '%s' as a valid ref."), rev);
-
- /*
- * NOTE: As "git reset $treeish -- $path" should be usable on
- * any tree-ish, this is not strictly correct. We are not
- * moving the HEAD to any commit; we are merely resetting the
- * entries in the index to that of a treeish.
- */
- commit = lookup_commit_reference(sha1);
- if (!commit)
- die(_("Could not parse object '%s'."), rev);
- hashcpy(sha1, commit->object.sha1);
+ if (!pathspec) {
+ struct commit *commit;
+ if (get_sha1_committish(rev, sha1))
+ die(_("Failed to resolve '%s' as a valid revision."), rev);
+ commit = lookup_commit_reference(sha1);
+ if (!commit)
+ die(_("Could not parse object '%s'."), rev);
+ hashcpy(sha1, commit->object.sha1);
+ } else {
+ struct tree *tree;
+ if (get_sha1_treeish(rev, sha1))
+ die(_("Failed to resolve '%s' as a valid tree."), rev);
+ tree = parse_tree_indirect(sha1);
+ if (!tree)
+ die(_("Could not parse object '%s'."), rev);
+ hashcpy(sha1, tree->object.sha1);
+ }
if (patch_mode) {
if (reset_type != NONE)
@@ -340,7 +346,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
update_ref_status = update_refs(rev, sha1);
if (reset_type == HARD && !update_ref_status && !quiet)
- print_new_head_line(commit);
+ print_new_head_line(lookup_commit_reference(sha1));
remove_branch_state();
}
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 81b2570..1fa2a5f 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -497,4 +497,12 @@ test_expect_success 'disambiguation (4)' '
test ! -f secondfile
'
+test_expect_success 'reset with paths accepts tree' '
+ # for simpler tests, drop last commit containing added files
+ git reset --hard HEAD^ &&
+ git reset HEAD^^{tree} -- . &&
+ git diff --cached HEAD^ --exit-code &&
+ git diff HEAD --exit-code
+'
+
test_done
--
1.8.1.1.454.gce43f05
next prev parent reply other threads:[~2013-01-15 5:49 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
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 ` Martin von Zweigbergk [this message]
2013-01-16 18:00 ` [PATCH v2 17/19] fixup! reset $sha1 $pathspec: require $sha1 only to be treeish 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=1358228871-7142-18-git-send-email-martinvonz@gmail.com \
--to=martinvonz@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kraai@ftbfs.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=ramsay@ramsay1.demon.co.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).