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

[PATCH v2 1/8] builtin/checkout: pass branch info down to checkout_worktree

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 16, 2020, 18:05 UTC
Message-ID
<20200316180508.367809-2-sandals@crustytoothpaste.net>
In-Reply-To
<20200316180508.367809-1-sandals@crustytoothpaste.net>
From: "brian m. carlson" <bk2204@github.com>

In the future, we're going to want to use the branch info in checkout_worktree, so let's pass the whole struct branch_info down, not just the revision name. We hoist the definition of struct branch_info so it's in scope.

Signed-off-by: brian m. carlson <bk2204@github.com>
---
 builtin/checkout.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d6773818b8..8a28f48d67 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -88,6 +88,17 @@ struct checkout_opts {
 	struct tree *source_tree;
 };
 
+struct branch_info {
+	const char *name; /* The short name used */
+	const char *path; /* The full name of a real branch */
+	struct commit *commit; /* The named commit */
+	/*
+	 * if not null the branch is detached because it's already
+	 * checked out in this checkout
+	 */
+	char *checkout;
+};
+
 static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
 			      int changed)
 {
@@ -337,7 +348,8 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,
 	}
 }
 
-static int checkout_worktree(const struct checkout_opts *opts)
+static int checkout_worktree(const struct checkout_opts *opts,
+			     const struct branch_info *info)
 {
 	struct checkout state = CHECKOUT_INIT;
 	int nr_checkouts = 0, nr_unmerged = 0;
@@ -396,7 +408,7 @@ static int checkout_worktree(const struct checkout_opts *opts)
 }
 
 static int checkout_paths(const struct checkout_opts *opts,
-			  const char *revision)
+			  const struct branch_info *new_branch_info)
 {
 	int pos;
 	static char *ps_matched;
@@ -462,7 +474,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 		else
 			BUG("either flag must have been set, worktree=%d, index=%d",
 			    opts->checkout_worktree, opts->checkout_index);
-		return run_add_interactive(revision, patch_mode, &opts->pathspec);
+		return run_add_interactive(new_branch_info->name, patch_mode, &opts->pathspec);
 	}
 
 	repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -523,7 +535,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 
 	/* Now we are committed to check them out */
 	if (opts->checkout_worktree)
-		errs |= checkout_worktree(opts);
+		errs |= checkout_worktree(opts, new_branch_info);
 	else
 		remove_marked_cache_entries(&the_index, 1);
 
@@ -620,17 +632,6 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
 	}
 }
 
-struct branch_info {
-	const char *name; /* The short name used */
-	const char *path; /* The full name of a real branch */
-	struct commit *commit; /* The named commit */
-	/*
-	 * if not null the branch is detached because it's already
-	 * checked out in this checkout
-	 */
-	char *checkout;
-};
-
 static void setup_branch_path(struct branch_info *branch)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -1710,7 +1711,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
 
 	UNLEAK(opts);
 	if (opts->patch_mode || opts->pathspec.nr)
-		return checkout_paths(opts, new_branch_info.name);
+		return checkout_paths(opts, &new_branch_info);
 	else
 		return checkout_branch(opts, &new_branch_info);
 }
Previous: brian m. carlsonNext: brian m. carlson
Message 2 of 9 in “Additional metadata for filter processes”
  1. 0/8 Additional metadata for filter processesbrian m. carlson, Mar 16, 2020
  2. 1/8 builtin/checkout: pass branch info down to checkout_worktreebrian m. carlson, Mar 16, 2020
  3. 3/8 convert: provide additional metadata to filtersbrian m. carlson, Mar 16, 2020
  4. 7/8 builtin/reset: compute checkout metadata for resetbrian m. carlson, Mar 16, 2020
  5. 2/8 convert: permit passing additional metadata to filter processesbrian m. carlson, Mar 16, 2020
  6. 6/8 builtin/rebase: compute checkout metadata for rebasesbrian m. carlson, Mar 16, 2020
  7. 4/8 builtin/checkout: compute checkout metadata for checkoutsbrian m. carlson, Mar 16, 2020
  8. 8/8 t0021: test filter metadata for additional casesbrian m. carlson, Mar 16, 2020
  9. 5/8 builtin/clone: compute checkout metadata for clonesbrian m. carlson, Mar 16, 2020

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.