[PATCH 3/6] Teach --id to "git checkout"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]