git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nazri Ramliy <ayiehere@gmail.com>
To: git@vger.kernel.org
Cc: Nazri Ramliy <ayiehere@gmail.com>
Subject: [PATCH 6/6] Teach --id to "git reset"
Date: Wed,  5 Aug 2009 17:51:46 +0800	[thread overview]
Message-ID: <1249465906-3940-7-git-send-email-ayiehere@gmail.com> (raw)
In-Reply-To: <1249465906-3940-6-git-send-email-ayiehere@gmail.com>

---
 builtin-reset.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/builtin-reset.c b/builtin-reset.c
index 5fa1789..cad5cf5 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -183,6 +183,8 @@ static void prepend_reflog_action(const char *action, char *buf, size_t size)
 int cmd_reset(int argc, const char **argv, const char *prefix)
 {
 	int i = 0, reset_type = NONE, update_ref_status = 0, quiet = 0;
+	char *file_id;
+	char **new_argv;
 	const char *rev = "HEAD";
 	unsigned char sha1[20], *orig = NULL, sha1_orig[20],
 				*old_orig = NULL, sha1_old_orig[20];
@@ -198,6 +200,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 				"reset HEAD, index and working tree", MERGE),
 		OPT_BOOLEAN('q', NULL, &quiet,
 				"disable showing new HEAD in hard reset and progress message"),
+		OPT_STRING('d', "id", &file_id, "FILE_ID", "file id"),
 		OPT_END()
 	};
 
@@ -205,7 +208,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, git_reset_usage,
 						PARSE_OPT_KEEP_DASHDASH);
-	reflog_action = args_to_str(argv);
+	if (file_id)
+		new_argv = (char **) expand_file_ids(file_id, &argc, (char **) argv);
+	else
+		new_argv = (char **) argv;
+
+	reflog_action = args_to_str((const char **) new_argv);
 	setenv("GIT_REFLOG_ACTION", reflog_action, 0);
 
 	/*
@@ -216,30 +224,30 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	 * git reset [-opts] -- <paths>...
 	 * git reset [-opts] <paths>...
 	 *
-	 * At this point, argv[i] points immediately after [-opts].
+	 * At this point, new_argv[i] points immediately after [-opts].
 	 */
 
 	if (i < argc) {
-		if (!strcmp(argv[i], "--")) {
+		if (!strcmp(new_argv[i], "--")) {
 			i++; /* reset to HEAD, possibly with paths */
-		} else if (i + 1 < argc && !strcmp(argv[i+1], "--")) {
-			rev = argv[i];
+		} else if (i + 1 < argc && !strcmp(new_argv[i+1], "--")) {
+			rev = new_argv[i];
 			i += 2;
 		}
 		/*
-		 * Otherwise, argv[i] could be either <rev> or <paths> and
+		 * Otherwise, new_argv[i] could be either <rev> or <paths> and
 		 * has to be unambiguous.
 		 */
-		else if (!get_sha1(argv[i], sha1)) {
+		else if (!get_sha1(new_argv[i], sha1)) {
 			/*
-			 * Ok, argv[i] looks like a rev; it should not
+			 * Ok, new_argv[i] looks like a rev; it should not
 			 * be a filename.
 			 */
-			verify_non_filename(prefix, argv[i]);
-			rev = argv[i++];
+			verify_non_filename(prefix, new_argv[i]);
+			rev = new_argv[i++];
 		} else {
 			/* Otherwise we treat this as a filename */
-			verify_filename(prefix, argv[i]);
+			verify_filename(prefix, new_argv[i]);
 		}
 	}
 
@@ -260,7 +268,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		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(prefix, (const char **) argv + i, sha1,
 				quiet ? REFRESH_QUIET : REFRESH_SAY_CHANGED);
 	}
 	if (reset_type == NONE)
-- 
1.6.4.13.ge6580

  reply	other threads:[~2009-08-05  9:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05  9:51 [PATCH] RFC - Say goodbye to the rodent Nazri Ramliy
2009-08-05  9:51 ` [PATCH 1/6] Teach --id/-d to "git status" Nazri Ramliy
2009-08-05  9:51   ` [PATCH 2/6] Teach --id to "git add" Nazri Ramliy
2009-08-05  9:51     ` [PATCH 3/6] Teach --id to "git checkout" Nazri Ramliy
2009-08-05  9:51       ` [PATCH 4/6] Teach --d to "git commit" Nazri Ramliy
2009-08-05  9:51         ` [PATCH 5/6] Teach --id to "git rm" Nazri Ramliy
2009-08-05  9:51           ` Nazri Ramliy [this message]
2009-08-05 18:11   ` [PATCH 1/6] Teach --id/-d to "git status" Alex Riesen
2009-08-05 18:25     ` Sverre Rabbelier
2009-08-05 18:27       ` Junio C Hamano
2009-08-05 18:30         ` Sverre Rabbelier
2009-08-05 18:33       ` Alex Riesen
2009-08-05 18:35         ` Sverre Rabbelier
2009-08-05 10:04 ` [PATCH] RFC - Say goodbye to the rodent Andreas Ericsson
2009-08-05 11:54 ` Matthieu Moy
2009-08-05 19:02 ` Jeff King
2009-08-05 20:01   ` Nicolas Pitre

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1249465906-3940-7-git-send-email-ayiehere@gmail.com \
    --to=ayiehere@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).