From b8575015bb61d50cb3e2d2487cf47ec97ed9dfd0 Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Mon, 7 Jun 2021 15:30:09 +1000 Subject: [PATCH] Support running docs builds against worktrees The Elasticsearch convention is to use git worktrees to support multiple lines of development across different branches. A typical layout would be: - A regular checkout at `$GIT_HOME/elasticsearch` for the `master` branch - A worktree at `$GIT_HOME/elasticsearch-7.x` for the `7.x` branch - A worktree at `$GIT_HOME/elasticsearch-6.x` for the `6.x` branch This commit changes the docs build to support this structure. --- build_docs | 8 +++++++- build_docs.pl | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/build_docs b/build_docs index cb678d3136c98..3d9c334dda42d 100755 --- a/build_docs +++ b/build_docs @@ -169,7 +169,13 @@ def run_build_docs(args): extra_name = repo_name.replace('x-pack-', '') repo_mount = '/doc/%s-extra/%s' % (extra_name, repo_name) else: - repo_mount = '/doc/' + repo_name + match = re.search(r'(.*)-[0-9]+\.[0-9x]+$', repo_name) + if match is None: + repo_mount = '/doc/' + repo_name + else: + # Repo name ends with what looks like a version string (e.g. elasticsearch-7.x) + # Mount this under the unversioned project name + repo_mount = '/doc/' + match.group(1) if repo_root not in mounted_doc_repo_roots: if repo_name in mounted_doc_repo_names: raise ArgError("Can't mount two repos with the same " + diff --git a/build_docs.pl b/build_docs.pl index cb67179f093af..3963d5120a219 100755 --- a/build_docs.pl +++ b/build_docs.pl @@ -155,7 +155,7 @@ sub _guess_opts { my $toplevel = _find_toplevel( $index->parent ); my $remote = _pick_best_remote( $toplevel ); my $branch = _guess_branch( $toplevel ); - my $repo_name = _guess_repo_name( $remote ); + my $repo_name = _guess_repo_name( $remote, $toplevel ); # We couldn't find the top level so lets make a wild guess. $toplevel = $index->parent unless $toplevel; printf "Guessed toplevel=[%s] remote=[%s] branch=[%s] repo=[%s]\n", $toplevel, $remote, $branch, $repo_name; @@ -169,7 +169,7 @@ sub _guess_opts { $toplevel = _find_toplevel( $resource ); $remote = _pick_best_remote( $toplevel ); $branch = _guess_branch( $toplevel ); - $repo_name = _guess_repo_name( $remote ); + $repo_name = _guess_repo_name( $remote, $toplevel ); # We couldn't find the top level so lets make a wild guess. $toplevel = $resource unless $toplevel; $Opts->{roots}{ $repo_name } = $toplevel; @@ -188,6 +188,23 @@ sub _find_toplevel { chdir $docpath; my $toplevel = eval { run qw(git rev-parse --show-toplevel) }; chdir $original_pwd; + return $toplevel if $toplevel; + + my $d = $docpath; + while ($d) { + printf "Checking for .git directory (or file) in '%s'\n", $d; + my $git = $d->file(".git"); + my $git_stat = $git->stat(); + return $git->parent if $git_stat; + my $p = $d->parent; + if ($p eq $d) { + # Root of this filesystem + $d = undef; + } else { + $d = $p; + } + } + say "Couldn't find repo toplevel for $docpath" unless $toplevel; return $toplevel || 0; } @@ -252,9 +269,12 @@ sub _guess_branch { #=================================== sub _guess_repo_name { #=================================== - my ( $remote ) = @_; + my ( $remote, $toplevel ) = @_; - return 'repo' unless $remote; + if ( not $remote ) { + return 'repo' unless $toplevel; + return dir($toplevel)->basename; + } $remote = dir( $remote )->basename; $remote =~ s/\.git$//;