Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-03-26 Thread Junio C Hamano
Duy Nguyen pclo...@gmail.com writes:

 On Tue, Mar 25, 2014 at 08:52:13PM +0700, Duy Nguyen wrote:
 On Mon, Mar 24, 2014 at 9:52 PM, Torsten Bögershausen tbo...@web.de wrote:
  Did I report that t1501  fails when  there is a softlink in $PWD ?
  /home/tb/projects is a softlink to /disc5/projects/
 
 Yes you did and I forgot. I have fixed it, running test suite and will
 send the reroll soon.

 Junio, it seems you have picked up all minor changes after
 v5. Resending the whole series for one fix seems overkill. Could you
 just --autosquash this one in?

Gladly; thanks for a quick turnaround.

 -- 8 --
 Subject: [PATCH] fixup! setup.c: support multi-checkout repo setup

 ---
  t/t1501-worktree.sh | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

 diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
 index 2ac4424..e6ac7a4 100755
 --- a/t/t1501-worktree.sh
 +++ b/t/t1501-worktree.sh
 @@ -359,7 +359,7 @@ test_expect_success 'GIT_DIR set (1)' '
   (
   cd work 
   GIT_DIR=../gitfile git rev-parse --git-common-dir actual 
 - echo $TRASH_DIRECTORY/repo.git expect 
 + test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
   test_cmp expect actual
   )
  '
 @@ -370,7 +370,7 @@ test_expect_success 'GIT_DIR set (2)' '
   (
   cd work 
   GIT_DIR=../gitfile git rev-parse --git-common-dir actual 
 - echo $TRASH_DIRECTORY/repo.git expect 
 + test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
   test_cmp expect actual
   )
  '
 @@ -381,7 +381,7 @@ test_expect_success 'Auto discovery' '
   (
   cd work 
   git rev-parse --git-common-dir actual 
 - echo $TRASH_DIRECTORY/repo.git expect 
 + test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
   test_cmp expect actual 
   echo haha data1 
   git add data1 
 @@ -399,7 +399,7 @@ test_expect_success '$GIT_DIR/common overrides 
 core.worktree' '
   (
   cd work 
   git rev-parse --git-common-dir actual 
 - echo $TRASH_DIRECTORY/repo.git expect 
 + test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
   test_cmp expect actual 
   echo haha data2 
   git add data2 
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-03-25 Thread Duy Nguyen
On Tue, Mar 25, 2014 at 08:52:13PM +0700, Duy Nguyen wrote:
 On Mon, Mar 24, 2014 at 9:52 PM, Torsten Bögershausen tbo...@web.de wrote:
  Did I report that t1501  fails when  there is a softlink in $PWD ?
  /home/tb/projects is a softlink to /disc5/projects/
 
 Yes you did and I forgot. I have fixed it, running test suite and will
 send the reroll soon.

Junio, it seems you have picked up all minor changes after
v5. Resending the whole series for one fix seems overkill. Could you
just --autosquash this one in?

-- 8 --
Subject: [PATCH] fixup! setup.c: support multi-checkout repo setup

---
 t/t1501-worktree.sh | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 2ac4424..e6ac7a4 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -359,7 +359,7 @@ test_expect_success 'GIT_DIR set (1)' '
(
cd work 
GIT_DIR=../gitfile git rev-parse --git-common-dir actual 
-   echo $TRASH_DIRECTORY/repo.git expect 
+   test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
test_cmp expect actual
)
 '
@@ -370,7 +370,7 @@ test_expect_success 'GIT_DIR set (2)' '
(
cd work 
GIT_DIR=../gitfile git rev-parse --git-common-dir actual 
-   echo $TRASH_DIRECTORY/repo.git expect 
+   test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
test_cmp expect actual
)
 '
@@ -381,7 +381,7 @@ test_expect_success 'Auto discovery' '
(
cd work 
git rev-parse --git-common-dir actual 
-   echo $TRASH_DIRECTORY/repo.git expect 
+   test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
test_cmp expect actual 
echo haha data1 
git add data1 
@@ -399,7 +399,7 @@ test_expect_success '$GIT_DIR/common overrides 
core.worktree' '
(
cd work 
git rev-parse --git-common-dir actual 
-   echo $TRASH_DIRECTORY/repo.git expect 
+   test-path-utils real_path $TRASH_DIRECTORY/repo.git expect 
test_cmp expect actual 
echo haha data2 
git add data2 
-- 
1.9.1.345.ga1a145c
-- 8 --
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-03-25 Thread Duy Nguyen
On Mon, Mar 24, 2014 at 9:52 PM, Torsten Bögershausen tbo...@web.de wrote:
 Did I report that t1501  fails when  there is a softlink in $PWD ?
 /home/tb/projects is a softlink to /disc5/projects/

Yes you did and I forgot. I have fixed it, running test suite and will
send the reroll soon.
-- 
Duy
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-03-24 Thread Torsten Bögershausen
On 02/18/2014 02:40 PM, Nguyễn Thái Ngọc Duy wrote:
 The repo setup procedure is updated to detect $GIT_DIR/commondir and
 set $GIT_COMMON_DIR properly.

 The core.worktree is ignored when $GIT_DIR/commondir presents. This is
 because commondir repos are intended for separate/linked checkouts
 and pointing them back to a fixed core.worktree just does not make
 sense.

 Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
 ---
  Documentation/config.txt|  3 +-
  Documentation/git-rev-parse.txt |  3 ++
  builtin/rev-parse.c |  4 +++
  cache.h |  1 +
  environment.c   |  8 ++---
  setup.c | 33 +-
  t/t1501-worktree.sh | 76 
 +
  t/t1510-repo-setup.sh   |  1 +
  trace.c |  1 +
  9 files changed, 115 insertions(+), 15 deletions(-)

 diff --git a/Documentation/config.txt b/Documentation/config.txt
 index 5f4d793..cbf4d97 100644
 --- a/Documentation/config.txt
 +++ b/Documentation/config.txt
 @@ -381,7 +381,8 @@ false), while all other repositories are assumed to be 
 bare (bare
  
  core.worktree::
   Set the path to the root of the working tree.
 - This can be overridden by the GIT_WORK_TREE environment
 + This can be overridden by the GIT_WORK_TREE
 + or GIT_COMMON_DIR environment
   variable and the '--work-tree' command line option.
   The value can be an absolute path or relative to the path to
   the .git directory, which is either specified by --git-dir
 diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
 index 33e4e90..8e6ad32 100644
 --- a/Documentation/git-rev-parse.txt
 +++ b/Documentation/git-rev-parse.txt
 @@ -215,6 +215,9 @@ If `$GIT_DIR` is not defined and the current directory
  is not detected to lie in a Git repository or work tree
  print a message to stderr and exit with nonzero status.
  
 +--git-common-dir::
 + Show `$GIT_COMMON_DIR` if defined, else `$GIT_DIR`.
 +
  --is-inside-git-dir::
   When the current working directory is below the repository
   directory print true, otherwise false.
 diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
 index e50bc65..c7057ce 100644
 --- a/builtin/rev-parse.c
 +++ b/builtin/rev-parse.c
 @@ -744,6 +744,10 @@ int cmd_rev_parse(int argc, const char **argv, const 
 char *prefix)
   printf(%s%s.git\n, cwd, len  cwd[len-1] != 
 '/' ? / : );
   continue;
   }
 + if (!strcmp(arg, --git-common-dir)) {
 + puts(get_git_common_dir());
 + continue;
 + }
   if (!strcmp(arg, --resolve-git-dir)) {
   const char *gitdir = resolve_gitdir(argv[i+1]);
   if (!gitdir)
 diff --git a/cache.h b/cache.h
 index 51ade32..98b5dd3 100644
 --- a/cache.h
 +++ b/cache.h
 @@ -407,6 +407,7 @@ extern char *get_object_directory(void);
  extern char *get_index_file(void);
  extern char *get_graft_file(void);
  extern int set_git_dir(const char *path);
 +extern int get_common_dir(struct strbuf *sb, const char *gitdir);
  extern const char *get_git_namespace(void);
  extern const char *strip_namespace(const char *namespaced_ref);
  extern const char *get_git_work_tree(void);
 diff --git a/environment.c b/environment.c
 index c998120..0999fc1 100644
 --- a/environment.c
 +++ b/environment.c
 @@ -126,6 +126,7 @@ static char *expand_namespace(const char *raw_namespace)
  
  static void setup_git_env(void)
  {
 + struct strbuf sb = STRBUF_INIT;
   const char *gitfile;
   const char *shallow_file;
  
 @@ -134,12 +135,9 @@ static void setup_git_env(void)
   git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
   gitfile = read_gitfile(git_dir);
   git_dir = xstrdup(gitfile ? gitfile : git_dir);
 - git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
 - if (git_common_dir) {
 + if (get_common_dir(sb, git_dir))
   git_common_dir_env = 1;
 - git_common_dir = xstrdup(git_common_dir);
 - } else
 - git_common_dir = git_dir;
 + git_common_dir = strbuf_detach(sb, NULL);
   git_object_dir = getenv(DB_ENVIRONMENT);
   if (!git_object_dir) {
   git_object_dir = xmalloc(strlen(git_common_dir) + 9);
 diff --git a/setup.c b/setup.c
 index e56ec11..d4ac878 100644
 --- a/setup.c
 +++ b/setup.c
 @@ -170,14 +170,15 @@ void verify_non_filename(const char *prefix, const char 
 *arg)
   'git command [revision...] -- [file...]', arg);
  }
  
 -static void get_common_dir(struct strbuf *sb, const char *gitdir)
 +int get_common_dir(struct strbuf *sb, const char *gitdir)
  {
   struct strbuf data = STRBUF_INIT;
   struct strbuf path = STRBUF_INIT;
   const char *git_common_dir = 

Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-02-27 Thread Junio C Hamano
Nguyễn Thái Ngọc Duy  pclo...@gmail.com writes:

 The repo setup procedure is updated to detect $GIT_DIR/commondir and
 set $GIT_COMMON_DIR properly.

 The core.worktree is ignored when $GIT_DIR/commondir presents. This is
 because commondir repos are intended for separate/linked checkouts
 and pointing them back to a fixed core.worktree just does not make
 sense.

 Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
 ---
  Documentation/config.txt|  3 +-
  Documentation/git-rev-parse.txt |  3 ++
  builtin/rev-parse.c |  4 +++
  cache.h |  1 +
  environment.c   |  8 ++---
  setup.c | 33 +-
  t/t1501-worktree.sh | 76 
 +
  t/t1510-repo-setup.sh   |  1 +
  trace.c |  1 +
  9 files changed, 115 insertions(+), 15 deletions(-)

 diff --git a/Documentation/config.txt b/Documentation/config.txt
 index 5f4d793..cbf4d97 100644
 --- a/Documentation/config.txt
 +++ b/Documentation/config.txt
 @@ -381,7 +381,8 @@ false), while all other repositories are assumed to be 
 bare (bare
  
  core.worktree::
   Set the path to the root of the working tree.
 - This can be overridden by the GIT_WORK_TREE environment
 + This can be overridden by the GIT_WORK_TREE
 + or GIT_COMMON_DIR environment
   variable and the '--work-tree' command line option.

During my first reading, I was guessing that the reason you changed
this is because COMMON_DIR may redirect the config file from which
core.worktree may be read.  But that is probably not what you meant.
You do not want to share core.worktree between the borrowing and the
borrowed repositories.  If the presense of GIT_COMMON_DIR _disables_
core.worktree settings without supplying an alternative value, as
opposed to GIT_WORK_TREE which does override with an alternative
value, it is very different from can be overriden.

It needs a better phrasing.

By the way, do we need to do something special for core.bare as
well for a similar reason?
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-02-19 Thread Junio C Hamano
Nguyễn Thái Ngọc Duy  pclo...@gmail.com writes:

(Only nitpicks during this round of review).

 diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
 index 8f36aa9..d8bdaf4 100755
 --- a/t/t1501-worktree.sh
 +++ b/t/t1501-worktree.sh
 @@ -346,4 +346,80 @@ test_expect_success 'relative $GIT_WORK_TREE and git 
 subprocesses' '
   test_cmp expected actual
  '
  
 +test_expect_success 'Multi-worktree setup' '
 + mkdir work 
 + mkdir -p repo.git/repos/foo 
 + cp repo.git/HEAD repo.git/index repo.git/repos/foo 
 + unset GIT_DIR GIT_CONFIG GIT_WORK_TREE

Are these known to be set always when we get to this point?
Otherwise please use sane_unset.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 18/25] setup.c: support multi-checkout repo setup

2014-02-18 Thread Nguyễn Thái Ngọc Duy
The repo setup procedure is updated to detect $GIT_DIR/commondir and
set $GIT_COMMON_DIR properly.

The core.worktree is ignored when $GIT_DIR/commondir presents. This is
because commondir repos are intended for separate/linked checkouts
and pointing them back to a fixed core.worktree just does not make
sense.

Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
---
 Documentation/config.txt|  3 +-
 Documentation/git-rev-parse.txt |  3 ++
 builtin/rev-parse.c |  4 +++
 cache.h |  1 +
 environment.c   |  8 ++---
 setup.c | 33 +-
 t/t1501-worktree.sh | 76 +
 t/t1510-repo-setup.sh   |  1 +
 trace.c |  1 +
 9 files changed, 115 insertions(+), 15 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5f4d793..cbf4d97 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -381,7 +381,8 @@ false), while all other repositories are assumed to be bare 
(bare
 
 core.worktree::
Set the path to the root of the working tree.
-   This can be overridden by the GIT_WORK_TREE environment
+   This can be overridden by the GIT_WORK_TREE
+   or GIT_COMMON_DIR environment
variable and the '--work-tree' command line option.
The value can be an absolute path or relative to the path to
the .git directory, which is either specified by --git-dir
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 33e4e90..8e6ad32 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -215,6 +215,9 @@ If `$GIT_DIR` is not defined and the current directory
 is not detected to lie in a Git repository or work tree
 print a message to stderr and exit with nonzero status.
 
+--git-common-dir::
+   Show `$GIT_COMMON_DIR` if defined, else `$GIT_DIR`.
+
 --is-inside-git-dir::
When the current working directory is below the repository
directory print true, otherwise false.
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index e50bc65..c7057ce 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -744,6 +744,10 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
printf(%s%s.git\n, cwd, len  cwd[len-1] != 
'/' ? / : );
continue;
}
+   if (!strcmp(arg, --git-common-dir)) {
+   puts(get_git_common_dir());
+   continue;
+   }
if (!strcmp(arg, --resolve-git-dir)) {
const char *gitdir = resolve_gitdir(argv[i+1]);
if (!gitdir)
diff --git a/cache.h b/cache.h
index 51ade32..98b5dd3 100644
--- a/cache.h
+++ b/cache.h
@@ -407,6 +407,7 @@ extern char *get_object_directory(void);
 extern char *get_index_file(void);
 extern char *get_graft_file(void);
 extern int set_git_dir(const char *path);
+extern int get_common_dir(struct strbuf *sb, const char *gitdir);
 extern const char *get_git_namespace(void);
 extern const char *strip_namespace(const char *namespaced_ref);
 extern const char *get_git_work_tree(void);
diff --git a/environment.c b/environment.c
index c998120..0999fc1 100644
--- a/environment.c
+++ b/environment.c
@@ -126,6 +126,7 @@ static char *expand_namespace(const char *raw_namespace)
 
 static void setup_git_env(void)
 {
+   struct strbuf sb = STRBUF_INIT;
const char *gitfile;
const char *shallow_file;
 
@@ -134,12 +135,9 @@ static void setup_git_env(void)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
gitfile = read_gitfile(git_dir);
git_dir = xstrdup(gitfile ? gitfile : git_dir);
-   git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
-   if (git_common_dir) {
+   if (get_common_dir(sb, git_dir))
git_common_dir_env = 1;
-   git_common_dir = xstrdup(git_common_dir);
-   } else
-   git_common_dir = git_dir;
+   git_common_dir = strbuf_detach(sb, NULL);
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
git_object_dir = xmalloc(strlen(git_common_dir) + 9);
diff --git a/setup.c b/setup.c
index e56ec11..d4ac878 100644
--- a/setup.c
+++ b/setup.c
@@ -170,14 +170,15 @@ void verify_non_filename(const char *prefix, const char 
*arg)
'git command [revision...] -- [file...]', arg);
 }
 
-static void get_common_dir(struct strbuf *sb, const char *gitdir)
+int get_common_dir(struct strbuf *sb, const char *gitdir)
 {
struct strbuf data = STRBUF_INIT;
struct strbuf path = STRBUF_INIT;
const char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
+   int ret = 0;
if (git_common_dir) {
strbuf_addstr(sb,