chiark / gitweb /
worktree support: Dgit.pm: Introduce $maindir_gitdir and _commondir
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Aug 2017 18:14:40 +0000 (19:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 3 Aug 2017 08:57:52 +0000 (09:57 +0100)
A "git worktree" separates out some of the things which used to be
found in .git, into "common" things and "gitdir" things.

In this patch we simply collect the relevant informaation.  No-one
uses it yet so there is no significant functional change.

However, while we are here, we do improve an error message slightly.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm

index de37261d1820b86d54e874860932be631ab2f135..b678ba53ead7cba05a4d579ebef5ae1f5f5df6c9 100644 (file)
@@ -64,6 +64,7 @@ BEGIN {
     # implicitly uses $main::us
     %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)],
                     playground => [qw(record_maindir $maindir $local_git_cfg
     # implicitly uses $main::us
     %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)],
                     playground => [qw(record_maindir $maindir $local_git_cfg
+                                      $maindir_gitdir $maindir_gitcommon
                                       fresh_playground $playground
                                        ensure_a_playground)]);
     @EXPORT_OK   = ( @{ $EXPORT_TAGS{policyflags} },
                                       fresh_playground $playground
                                        ensure_a_playground)]);
     @EXPORT_OK   = ( @{ $EXPORT_TAGS{policyflags} },
@@ -509,11 +510,29 @@ sub git_slurp_config_src ($) {
 
 # ----- maindir -----
 
 
 # ----- maindir -----
 
+# these three all go together
 our $maindir;
 our $maindir;
+our $maindir_gitdir;
+our $maindir_gitcommon;
+
 our $local_git_cfg;
 
 sub record_maindir () {
 our $local_git_cfg;
 
 sub record_maindir () {
-    $maindir //= must_getcwd();
+    if (!defined $maindir) {
+       $maindir = must_getcwd();
+       if (!stat "$maindir/.git") {
+           fail "cannot stat $maindir/.git: $!";
+       }
+       if (-d _) {
+           # we fall back to this in case we have a pre-worktree
+           # git, which may not know git rev-parse --git-common-dir
+           $maindir_gitdir    = "$maindir/.git";
+           $maindir_gitcommon = "$maindir/.git";
+       } else {
+           $maindir_gitdir    = cmdoutput qw(git rev-parse --git-dir);
+           $maindir_gitcommon = cmdoutput qw(git rev-parse --git-common-dir);
+       }
+    }
     $local_git_cfg //= git_slurp_config_src 'local';
 }
 
     $local_git_cfg //= git_slurp_config_src 'local';
 }
 
@@ -526,7 +545,8 @@ sub ensure_a_playground_parent ($) {
     record_maindir();
     $spc = ".git/$spc";
     my $parent = dirname $spc;
     record_maindir();
     $spc = ".git/$spc";
     my $parent = dirname $spc;
-    mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!";
+    mkdir $parent or $!==EEXIST
+       or fail "failed to mkdir playground parent $parent: $!";
     return $spc;
 }    
 
     return $spc;
 }