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

Re: Built-in checkout: wrong behaviour in subdirectories

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Feb 21, 2008, 15:50 UTC
Message-ID
<alpine.LNX.1.00.0802211041190.19024@iabervon.org>
In-Reply-To
<7vd4qr2o03.fsf@gitster.siamese.dyndns.org>
On Wed, 20 Feb 2008, Junio C Hamano wrote:
Show 17 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Daniel Barkalow <barkalow@iabervon.org> writes:
> >
> >> Junio: it looks like something used to cause read-tree to be run with 
> >> pwd being the working tree root in git-checkout.sh.
> >
> > "Something"?  I think we explicitly cdup when switching
> > branches, and we should do the same in C rewrite.
> >
> >         # We are switching branches and checking out trees, so
> >         # we *NEED* to be at the toplevel.
> >         cd_to_toplevel
> 
> Isn't it just the matter of not passing prefix to topts in
> merge_working_tree()?  Your other calls to unpack_trees() do not
> seem to pass bogus prefix to it.

You're absolutely right; I think I initially misunderstood the way the wrapper sets things up beforehand, and did the later parts of the conversion correctly. But we should also drop the bunch of now-unused arguments, too:

--------------
commit 267d68e24111bc9054d1f3356842f58106c76f49
Author: Daniel Barkalow <barkalow@iabervon.org>
Date:   Thu Feb 21 10:48:46 2008 -0500
    Remove unused prefix arguments in switch_branches path
    
    This path doesn't actually care where in the tree you started out,
    since it must change the whole thing anyway. With the gratuitous bug
    removed, the argument is unused.
    
    Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 builtin-checkout.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index cddd3a9..46cb362 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -205,8 +205,7 @@ static void setup_branch_path(struct branch_info *branch)
 }
 
 static int merge_working_tree(struct checkout_opts *opts,
-			      struct branch_info *old, struct branch_info *new,
-			      const char *prefix)
+			      struct branch_info *old, struct branch_info *new)
 {
 	int ret;
 	struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
@@ -429,8 +428,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
 		adjust_to_tracking(new, opts);
 }
 
-static int switch_branches(struct checkout_opts *opts,
-			   struct branch_info *new, const char *prefix)
+static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
 {
 	int ret = 0;
 	struct branch_info old;
@@ -471,7 +469,7 @@ static int switch_branches(struct checkout_opts *opts,
 		opts->force = 1;
 	}
 
-	ret = merge_working_tree(opts, &old, new, prefix);
+	ret = merge_working_tree(opts, &old, new);
 	if (ret)
 		return ret;
 
@@ -565,5 +563,5 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 		die("Cannot switch branch to a non-commit.");
 	}
 
-	return switch_branches(&opts, &new, prefix);
+	return switch_branches(&opts, &new);
 }
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Built-in checkout: wrong behaviour in subdirectories”
  1. Clemens BuchacherFeb 20, 2008
  2. Daniel BarkalowFeb 20, 2008
  3. Junio C HamanoFeb 20, 2008
  4. Junio C HamanoFeb 20, 2008
  5. Daniel BarkalowFeb 21, 2008
  6. checkout: work from a subdirectoryJunio C Hamano, Feb 20, 2008

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.