From: Nazri Ramliy <ayiehere@gmail.com>
To: git@vger.kernel.org
Cc: Nazri Ramliy <ayiehere@gmail.com>
Subject: [PATCH 3/6] Teach --id to "git checkout"
Date: Wed, 5 Aug 2009 17:51:43 +0800 [thread overview]
Message-ID: <1249465906-3940-4-git-send-email-ayiehere@gmail.com> (raw)
In-Reply-To: <1249465906-3940-3-git-send-email-ayiehere@gmail.com>
---
builtin-checkout.c | 26 +++++++++++++++++---------
1 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 8a9a474..94ef419 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -32,6 +32,7 @@ struct checkout_opts {
int writeout_error;
const char *new_branch;
+ const char *file_id;
int new_branch_log;
enum branch_track track;
};
@@ -583,6 +584,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT__QUIET(&opts.quiet),
OPT_STRING('b', NULL, &opts.new_branch, "new branch", "branch"),
+ OPT_STRING('d', "id", &opts.file_id, "FILE_ID", "file id"),
OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
OPT_SET_INT('t', "track", &opts.track, "track",
BRANCH_TRACK_EXPLICIT),
@@ -597,6 +599,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
OPT_END(),
};
int has_dash_dash;
+ char **new_argv;
memset(&opts, 0, sizeof(opts));
memset(&new, 0, sizeof(new));
@@ -608,9 +611,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, checkout_usage,
PARSE_OPT_KEEP_DASHDASH);
+ if (opts.file_id)
+ new_argv = (char **) expand_file_ids(opts.file_id, &argc, (char **) argv);
+ else
+ new_argv = (char **) argv;
+
/* --track without -b should DWIM */
if (0 < opts.track && !opts.new_branch) {
- const char *argv0 = argv[0];
+ const char *argv0 = new_argv[0];
if (!argc || !strcmp(argv0, "--"))
die ("--track needs a branch name");
if (!prefixcmp(argv0, "refs/"))
@@ -655,14 +663,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
*
*/
if (argc) {
- if (!strcmp(argv[0], "--")) { /* case (2) */
- argv++;
+ if (!strcmp(new_argv[0], "--")) { /* case (2) */
+ new_argv++;
argc--;
goto no_reference;
}
- arg = argv[0];
- has_dash_dash = (argc > 1) && !strcmp(argv[1], "--");
+ arg = new_argv[0];
+ has_dash_dash = (argc > 1) && !strcmp(new_argv[1], "--");
if (!strcmp(arg, "-"))
arg = "@{-1}";
@@ -674,7 +682,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
}
/* we can't end up being in (2) anymore, eat the argument */
- argv++;
+ new_argv++;
argc--;
new.name = arg;
@@ -702,14 +710,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
verify_non_filename(NULL, arg);
}
else {
- argv++;
+ new_argv++;
argc--;
}
}
no_reference:
if (argc) {
- const char **pathspec = get_pathspec(prefix, argv);
+ const char **pathspec = get_pathspec(prefix, (const char **) new_argv);
if (!pathspec)
die("invalid path specification");
@@ -717,7 +725,7 @@ no_reference:
/* Checkout paths */
if (opts.new_branch) {
if (argc == 1) {
- die("git checkout: updating paths is incompatible with switching branches.\nDid you intend to checkout '%s' which can not be resolved as commit?", argv[0]);
+ die("git checkout: updating paths is incompatible with switching branches.\nDid you intend to checkout '%s' which can not be resolved as commit?", new_argv[0]);
} else {
die("git checkout: updating paths is incompatible with switching branches.");
}
--
1.6.4.13.ge6580
next prev parent 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 ` Nazri Ramliy [this message]
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 ` [PATCH 6/6] Teach --id to "git reset" Nazri Ramliy
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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.