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

Re: [RFC/PATCHv2 1/5] worktree: provide better prefix to go back to original cwd

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 17, 2010, 10:01 UTC
Message-ID
<20101017094524.GA6034@do>
In-Reply-To
<4CBA63E2.8030502@gmail.com>
On Sat, Oct 16, 2010 at 07:48:02PM -0700, Chris Packham wrote:
Show 25 quoted lines
> On 16/10/10 11:42, Jonathan Nieder wrote:
> > Hi,
> > 
> > Chris Packham wrote:
> > 
> >> From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> >>
> >> When both GIT_DIR and GIT_WORK_TREE are set, if cwd is outside worktree,
> >> prefix (the one passed to every builtin commands) will be set to NULL,
> >> which means "user stays at worktree topdir".
> >>
> >> As a consequence, command line arguments are supposed to be relative
> >> to worktree topdir, not current working directory. Not very intuitive.
> > 
> > Thanks.  More detailed history for this patch:
> > 
> >  - v0: http://thread.gmane.org/gmane.comp.version-control.git/157599/focus=157601
> >  - v1: http://thread.gmane.org/gmane.comp.version-control.git/158287
> >  - v2: http://thread.gmane.org/gmane.comp.version-control.git/158369
> > 
> 
> I think I must have missed v2. I was playing around with my gmail
> filters around that time so I could have missed them. Actually now I've
> found the message it's missing the last 'm' in gmail.com. I'll grab the
> latest patch and give it a test when I get a chance.

I missed the last "m" in your email address. That's why v2 never reached you. I thought I sent you an email but probably forgot it.

Anyway v2 does not work if worktree and cwd are on different Windows drives. This on top should fix it:

---8<---
diff --git a/setup.c b/setup.c
index 2389a9e..35d2691 100644
--- a/setup.c
+++ b/setup.c
@@ -371,12 +371,8 @@ static const char *setup_prefix(const char *cwd)
 	}
 	/* get /foo/, not /foo/baa if /foo/baa1 and /foo/baa2 are given */
 	else if (worktree[len] && cwd[len]) {
-		while (len && !is_dir_sep(worktree[len]))
-			len--;
-		len++;
-
 		/* Worktree and cwd are on different drives? */
-		if (len == 3 && has_dos_drive_prefix(cwd)) {
+		if (!len && has_dos_drive_prefix(cwd)) {
 			if (startup_info) {
 				/* make_path_to_path will add the trailing slash */
 				startup_info->cwd_to_worktree = make_path_to_path(NULL, worktree);
@@ -384,6 +380,10 @@ static const char *setup_prefix(const char *cwd)
 			}
 			return NULL;
 		}
+
+		while (len && !is_dir_sep(worktree[len]))
+			len--;
+		len++;
 	}
 	else {
 		if (worktree[len]) {
---8<---

> 
> > Any thoughts about the previous questions?
> > 
> 
> I haven't caught up on the newest thread so no great revelations. Except
> that for the grep submodules use-case we can assume that the worktree
> will be a subdirectory of the cwd. I don't think we want to limit
> ourselves to that one use-case.

While at it, have you thought of support --recursive and
--full-tree [1]? There are issues with --full-tree and prefixes [2],
which is why it is dropped but I think it's a good idea.

--full-tree disregards where you stand and greps in whole repo. In a
repo with submodules, that would mean grep the supermodule and all
submodules regardless where you stand, even if you stand in a
submodule.

[1] http://mid.gmane.org/7vk4xggv27.fsf@alter.siamese.dyndns.org
[2] http://mid.gmane.org/7vskaqptvj.fsf@alter.siamese.dyndns.org
-- 
Duy
Previous: Chris PackhamNext: Chris Packham
Message 5 of 15 in “[RGC/PATCHv2] grep: submodule support”
  1. Chris PackhamOct 15, 2010
  2. 1/5 worktree: provide better prefix to go back to original cwdChris Packham, Oct 15, 2010
  3. Jonathan NiederOct 16, 2010
  4. Chris PackhamOct 17, 2010
  5. Nguyen Thai Ngoc DuyOct 17, 2010
  6. Chris PackhamOct 18, 2010
  7. 2/5 grep: output the path from cwd to worktreeChris Packham, Oct 15, 2010
  8. 3/5 grep_cache: check pathspec firstChris Packham, Oct 15, 2010
  9. 4/5 add test for git grep --recursiveChris Packham, Oct 15, 2010
  10. 5/5 grep: add support for grepping in submodulesChris Packham, Oct 15, 2010
  11. Nguyen Thai Ngoc DuyOct 17, 2010
  12. Chris PackhamOct 18, 2010
  13. Nguyen Thai Ngoc DuyOct 18, 2010
  14. Jens LehmannOct 16, 2010
  15. Chris PackhamOct 17, 2010

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.