git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] setup.c: add enter_work_tree()
@ 2010-10-07  4:46 pclouds
  0 siblings, 0 replies; only message in thread
From: pclouds @ 2010-10-07  4:46 UTC (permalink / raw)
  To: git, judge.packham
  Cc: Jens.Lehmann, Junio C Hamano, jrnieder,
	Nguyễn Thái Ngọc Duy

From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

This function, apart from chdir() to worktree topdir, also invalidates
inside_work_tree so is_inside_work_tree() should reflect the new
situation correctly.

This function may be used when cwd is outside worktree and the running
command supports this case.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 To be used by builtin/grep.c when cwd is outside worktree.
 More explanation in the next patch.

 cache.h |    1 +
 setup.c |    7 +++++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index 2ef2fa3..e71db23 100644
--- a/cache.h
+++ b/cache.h
@@ -414,6 +414,7 @@ extern int set_git_dir(const char *path);
 extern const char *get_git_work_tree(void);
 extern const char *read_gitfile_gently(const char *path);
 extern void set_git_work_tree(const char *tree);
+extern void enter_work_tree();
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
diff --git a/setup.c b/setup.c
index a3b76de..3fbe928 100644
--- a/setup.c
+++ b/setup.c
@@ -208,6 +208,13 @@ int is_inside_work_tree(void)
 	return inside_work_tree;
 }
 
+void enter_work_tree(void)
+{
+	if (chdir(get_git_work_tree()))
+		die("Could not chdir to %s", get_git_work_tree());
+	inside_work_tree = -1;
+}
+
 /*
  * set_work_tree() is only ever called if you set GIT_DIR explicitly.
  * The old behaviour (which we retain here) is to set the work tree root
-- 
1.7.1.rc1.70.g788ca

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-10-07  4:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-07  4:46 [PATCH 1/2] setup.c: add enter_work_tree() pclouds

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).