git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nazri Ramliy <ayiehere@gmail.com>
Date
Aug 5, 2009, 09:51 UTC
Message-ID
<1249465906-3940-4-git-send-email-ayiehere@gmail.com>
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
Previous: Nazri RamliyNext: Nazri Ramliy
Message 4 of 17 in “RFC - Say goodbye to the rodent”
  1. RFC - Say goodbye to the rodentNazri Ramliy, Aug 5, 2009
  2. 1/6 Teach --id/-d to "git status"Nazri Ramliy, Aug 5, 2009
  3. 2/6 Teach --id to "git add"Nazri Ramliy, Aug 5, 2009
  4. 3/6 Teach --id to "git checkout"Nazri Ramliy, Aug 5, 2009
  5. 4/6 Teach --d to "git commit"Nazri Ramliy, Aug 5, 2009
  6. 5/6 Teach --id to "git rm"Nazri Ramliy, Aug 5, 2009
  7. 6/6 Teach --id to "git reset"Nazri Ramliy, Aug 5, 2009
  8. Alex RiesenAug 5, 2009
  9. Sverre RabbelierAug 5, 2009
  10. Junio C HamanoAug 5, 2009
  11. Sverre RabbelierAug 5, 2009
  12. Alex RiesenAug 5, 2009
  13. Sverre RabbelierAug 5, 2009
  14. Andreas EricssonAug 5, 2009
  15. Matthieu MoyAug 5, 2009
  16. Jeff KingAug 5, 2009
  17. Nicolas PitreAug 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.