git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 4/8] Add a function to set a non-default work tree
@ 2008-04-17 23:32 Daniel Barkalow
  2008-04-19 17:33 ` Johan Herland
  2008-04-20  5:07 ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Barkalow @ 2008-04-17 23:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 cache.h       |    1 +
 environment.c |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index 96dcb49..d88a4e2 100644
--- a/cache.h
+++ b/cache.h
@@ -311,6 +311,7 @@ extern char *get_index_file(void);
 extern char *get_graft_file(void);
 extern int set_git_dir(const char *path);
 extern const char *get_git_work_tree(void);
+extern void set_git_work_tree(const char *tree);
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
diff --git a/environment.c b/environment.c
index 6739a3f..d6c6a6b 100644
--- a/environment.c
+++ b/environment.c
@@ -81,6 +81,12 @@ const char *get_git_dir(void)
 	return git_dir;
 }
 
+void set_git_work_tree(const char *new_work_tree)
+{
+	get_git_work_tree(); /* make sure it's initialized */
+	work_tree = xstrdup(make_absolute_path(new_work_tree));
+}
+
 const char *get_git_work_tree(void)
 {
 	static int initialized = 0;
-- 
1.5.4.3.610.gea6cd

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] Add a function to set a non-default work tree
  2008-04-17 23:32 [PATCH 4/8] Add a function to set a non-default work tree Daniel Barkalow
@ 2008-04-19 17:33 ` Johan Herland
  2008-04-20  5:07 ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Johan Herland @ 2008-04-19 17:33 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Junio C Hamano, Johannes Schindelin

On Friday 18 April 2008, Daniel Barkalow wrote:
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> ---
>  cache.h       |    1 +
>  environment.c |    6 ++++++
>  2 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/cache.h b/cache.h
> index 96dcb49..d88a4e2 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -311,6 +311,7 @@ extern char *get_index_file(void);
>  extern char *get_graft_file(void);
>  extern int set_git_dir(const char *path);
>  extern const char *get_git_work_tree(void);
> +extern void set_git_work_tree(const char *tree);
>  
>  #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
>  
> diff --git a/environment.c b/environment.c
> index 6739a3f..d6c6a6b 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -81,6 +81,12 @@ const char *get_git_dir(void)
>  	return git_dir;
>  }
>  
> +void set_git_work_tree(const char *new_work_tree)
> +{
> +	get_git_work_tree(); /* make sure it's initialized */
> +	work_tree = xstrdup(make_absolute_path(new_work_tree));

Shouldn't we free(work_tree) before resetting it?

> +}
> +
>  const char *get_git_work_tree(void)
>  {
>  	static int initialized = 0;


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] Add a function to set a non-default work tree
  2008-04-17 23:32 [PATCH 4/8] Add a function to set a non-default work tree Daniel Barkalow
  2008-04-19 17:33 ` Johan Herland
@ 2008-04-20  5:07 ` Junio C Hamano
  2008-04-20 19:52   ` Daniel Barkalow
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2008-04-20  5:07 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Johannes Schindelin

Daniel Barkalow <barkalow@iabervon.org> writes:

> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> ---
>  cache.h       |    1 +
>  environment.c |    6 ++++++
>  2 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index 96dcb49..d88a4e2 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -311,6 +311,7 @@ extern char *get_index_file(void);
>  extern char *get_graft_file(void);
>  extern int set_git_dir(const char *path);
>  extern const char *get_git_work_tree(void);
> +extern void set_git_work_tree(const char *tree);
>  
>  #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
>  
> diff --git a/environment.c b/environment.c
> index 6739a3f..d6c6a6b 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -81,6 +81,12 @@ const char *get_git_dir(void)
>  	return git_dir;
>  }
>  
> +void set_git_work_tree(const char *new_work_tree)
> +{
> +	get_git_work_tree(); /* make sure it's initialized */
> +	work_tree = xstrdup(make_absolute_path(new_work_tree));
> +}
> +

Somehow this feels wrong.  Maybe you would need to move that "static int"
variable inside get_git_work_tree() outside so that you can reset from
this new function at will?

How should the setting of new work tree from sideways using this interface
interact with bareness of the repository?

Should it reset is_bare_repository_cfg to zero?  Should it refuse to set a
work tree if is_bare_repository_cfg is true already?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] Add a function to set a non-default work tree
  2008-04-20  5:07 ` Junio C Hamano
@ 2008-04-20 19:52   ` Daniel Barkalow
  2008-04-22  0:09     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Barkalow @ 2008-04-20 19:52 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

On Sat, 19 Apr 2008, Junio C Hamano wrote:

> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> > Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> > ---
> >  cache.h       |    1 +
> >  environment.c |    6 ++++++
> >  2 files changed, 7 insertions(+), 0 deletions(-)
> >
> > diff --git a/cache.h b/cache.h
> > index 96dcb49..d88a4e2 100644
> > --- a/cache.h
> > +++ b/cache.h
> > @@ -311,6 +311,7 @@ extern char *get_index_file(void);
> >  extern char *get_graft_file(void);
> >  extern int set_git_dir(const char *path);
> >  extern const char *get_git_work_tree(void);
> > +extern void set_git_work_tree(const char *tree);
> >  
> >  #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
> >  
> > diff --git a/environment.c b/environment.c
> > index 6739a3f..d6c6a6b 100644
> > --- a/environment.c
> > +++ b/environment.c
> > @@ -81,6 +81,12 @@ const char *get_git_dir(void)
> >  	return git_dir;
> >  }
> >  
> > +void set_git_work_tree(const char *new_work_tree)
> > +{
> > +	get_git_work_tree(); /* make sure it's initialized */
> > +	work_tree = xstrdup(make_absolute_path(new_work_tree));
> > +}
> > +
> 
> Somehow this feels wrong.  Maybe you would need to move that "static int"
> variable inside get_git_work_tree() outside so that you can reset from
> this new function at will?

Yeah, that's better.

> How should the setting of new work tree from sideways using this interface
> interact with bareness of the repository?

I'm only using it before any initialization and when I'm going to force 
the repository (which doesn't even exist yet; I haven't set git_dir let 
alone created it, let alone looked at its configuration) to be bare, so I 
hadn't considered that.

> Should it reset is_bare_repository_cfg to zero?  Should it refuse to set a
> work tree if is_bare_repository_cfg is true already?

is_bare_repository_cfg starts out -1 (not yet specified); this should 
probably set it to false and require that it not have been specified 
previously.

	-Daniel
*This .sig left intentionally blank*

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] Add a function to set a non-default work tree
  2008-04-20 19:52   ` Daniel Barkalow
@ 2008-04-22  0:09     ` Junio C Hamano
  2008-04-22  3:47       ` Daniel Barkalow
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2008-04-22  0:09 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: git, Johannes Schindelin

Daniel Barkalow <barkalow@iabervon.org> writes:

> On Sat, 19 Apr 2008, Junio C Hamano wrote:
> ...
>> How should the setting of new work tree from sideways using this interface
>> interact with bareness of the repository?
>
> I'm only using it before any initialization and when I'm going to force 
> the repository (which doesn't even exist yet; I haven't set git_dir let 
> alone created it, let alone looked at its configuration) to be bare, so I 
> hadn't considered that.

That is not quite an explanation that builds confidence in a patch that
adds a generic-sounding helper function that could be called by later
callers.  Doesn't it have a very tempting name for people to call?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/8] Add a function to set a non-default work tree
  2008-04-22  0:09     ` Junio C Hamano
@ 2008-04-22  3:47       ` Daniel Barkalow
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Barkalow @ 2008-04-22  3:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

On Mon, 21 Apr 2008, Junio C Hamano wrote:

> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> > On Sat, 19 Apr 2008, Junio C Hamano wrote:
> > ...
> >> How should the setting of new work tree from sideways using this interface
> >> interact with bareness of the repository?
> >
> > I'm only using it before any initialization and when I'm going to force 
> > the repository (which doesn't even exist yet; I haven't set git_dir let 
> > alone created it, let alone looked at its configuration) to be bare, so I 
> > hadn't considered that.
> 
> That is not quite an explanation that builds confidence in a patch that
> adds a generic-sounding helper function that could be called by later
> callers.  Doesn't it have a very tempting name for people to call?

My latest version has it die() if you've gotten meaningfully far in 
initializing the repository state. I'm also not sure there's a tempting 
use case for it aside for in setup code where it clearly works, at least 
until we've got support for dealing with multiple working trees in the 
same process or something of that sort. But, in any case, it'll now fail 
fast and obviously outside of what I've planned for.

	-Daniel
*This .sig left intentionally blank*

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/8] Add a function to set a non-default work tree
@ 2008-04-27 17:39 Daniel Barkalow
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Barkalow @ 2008-04-27 17:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

This function may only be used before the work tree is used.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 cache.h       |    1 +
 environment.c |   19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/cache.h b/cache.h
index cdde6b0..b337b3d 100644
--- a/cache.h
+++ b/cache.h
@@ -311,6 +311,7 @@ extern char *get_index_file(void);
 extern char *get_graft_file(void);
 extern int set_git_dir(const char *path);
 extern const char *get_git_work_tree(void);
+extern void set_git_work_tree(const char *tree);
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
diff --git a/environment.c b/environment.c
index 6739a3f..1919125 100644
--- a/environment.c
+++ b/environment.c
@@ -41,7 +41,7 @@ enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
 
 /* This is set by setup_git_dir_gently() and/or git_default_config() */
 char *git_work_tree_cfg;
-static const char *work_tree;
+static char *work_tree;
 
 static const char *git_dir;
 static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
@@ -81,10 +81,21 @@ const char *get_git_dir(void)
 	return git_dir;
 }
 
+static int git_work_tree_initialized;
+
+void set_git_work_tree(const char *new_work_tree)
+{
+	if (is_bare_repository_cfg >= 0)
+		die("cannot set work tree after initialization");
+	git_work_tree_initialized = 1;
+	free(work_tree);
+	work_tree = xstrdup(make_absolute_path(new_work_tree));
+	is_bare_repository_cfg = 0;
+}
+
 const char *get_git_work_tree(void)
 {
-	static int initialized = 0;
-	if (!initialized) {
+	if (!git_work_tree_initialized) {
 		work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
 		/* core.bare = true overrides implicit and config work tree */
 		if (!work_tree && is_bare_repository_cfg < 1) {
@@ -94,7 +105,7 @@ const char *get_git_work_tree(void)
 				work_tree = xstrdup(make_absolute_path(git_path(work_tree)));
 		} else if (work_tree)
 			work_tree = xstrdup(make_absolute_path(work_tree));
-		initialized = 1;
+		git_work_tree_initialized = 1;
 		if (work_tree)
 			is_bare_repository_cfg = 0;
 	}
-- 
1.5.4.3.610.gea6cd

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-04-27 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-17 23:32 [PATCH 4/8] Add a function to set a non-default work tree Daniel Barkalow
2008-04-19 17:33 ` Johan Herland
2008-04-20  5:07 ` Junio C Hamano
2008-04-20 19:52   ` Daniel Barkalow
2008-04-22  0:09     ` Junio C Hamano
2008-04-22  3:47       ` Daniel Barkalow
  -- strict thread matches above, loose matches on Subject: below --
2008-04-27 17:39 Daniel Barkalow

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).