Skip to content

Commit

Permalink
get submodule urls from .gitmodules
Browse files Browse the repository at this point in the history
keeping a redundant copy in the script is plain backwards.

Change-Id: Ibdd1bab9d2cb5af7d7747d5caa2afc7d6e7571ad
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
  • Loading branch information
ossilator committed Sep 23, 2014
1 parent 3ade7c4 commit 4553d9e
Showing 1 changed file with 42 additions and 75 deletions.
117 changes: 42 additions & 75 deletions init-repository
Original file line number Diff line number Diff line change
Expand Up @@ -191,47 +191,6 @@ use Getopt::Long qw( GetOptionsFromArray );
use Pod::Usage qw( pod2usage );
use Cwd qw( getcwd );

my %GERRIT_REPOS = map { $_ => "qt/$_" } qw(
qt3d
qt5
qtactiveqt
qtandroidextras
qtbase
qtconnectivity
qtdeclarative
qtdoc
qtdocgallery
qtenginio
qtfeedback
qtgraphicaleffects
qtimageformats
qtjsondb
qtlocation
qtmacextras
qtmultimedia
qtpim
qtqa
qtquick1
qtquickcontrols
qtrepotools
qtscript
qtsensors
qtserialport
qtsvg
qtsystems
qttools
qttranslations
qtwayland
qtwebchannel
qtwebengine
qtwebkit
qtwebkit-examples
qtwebsockets
qtwinextras
qtx11extras
qtxmlpatterns
);

my @DEFAULT_REPOS = qw(
qtactiveqt
qtandroidextras
Expand Down Expand Up @@ -399,16 +358,33 @@ sub git_submodule_init

sub git_clone_all_submodules
{
my ($self, @subset) = @_;
my ($self, $my_repo_base, @subset) = @_;

my %subdirs = ();
my %subbases = ();
my @submodconfig = qx(git config -l -f .gitmodules);
foreach my $line (@submodconfig) {
# Example line: submodule.qtqa.url=../qtqa.git
next if ($line !~ /^submodule\.([^.=]+)\.([^.=]+)=(.*)$/);
if ($2 eq "path") {
$subdirs{$1} = $3;
} elsif ($2 eq "url") {
my ($mod, $base) = ($1, $3);
next if ($base !~ /^\.\.\//);
$base = $my_repo_base.'/'.$base;
while ($base =~ s,/(?!\.\./)[^/]+/\.\./,/,g) {}
$subbases{$mod} = $base;
} elsif ($2 eq "update") {
push @subset, '-'.$1 if ($3 eq 'ignore');
}
}

my %include = ();
my %exclude = ();
my $include_all = 0;
foreach my $mod (@subset) {
if ($mod eq "all") {
$include_all = 1;
map { $include{$_} = 1; } keys %subbases;
} elsif ($mod =~ s/^-//) {
$exclude{$mod} = 1;
delete $include{$mod};
} else {
$include{$mod} = 1;
}
Expand All @@ -423,7 +399,7 @@ sub git_clone_all_submodules
next if ($line !~ /submodule\.([^.=]+)\.url=(.*)/);
my ($module, $url) = ($1, $2);

if (defined($exclude{$module}) || (!$include_all && !defined($include{$module}))) {
if (!defined($include{$module})) {
$self->exe('git', 'config', '--remove-section', "submodule.$module");
next;
}
Expand All @@ -432,13 +408,13 @@ sub git_clone_all_submodules
$self->exe('git', 'config', "submodule.$module.ignore", 'all');
}

$self->git_clone_one_submodule($module, $url);
$self->git_clone_one_submodule($subdirs{$module}, $subbases{$module}, $url);
if ($module eq "qtwebengine") {
$self->exe('git', 'submodule', 'update', $module);
my $orig_cwd = getcwd();
chdir($module) or confess "chdir $module: $OS_ERROR";
$self->exe('git', 'submodule', 'init');
$self->git_clone_all_submodules("all");
$self->git_clone_all_submodules($subbases{$module}, "all");
chdir("$orig_cwd") or confess "chdir $orig_cwd: $OS_ERROR";
}
}
Expand All @@ -452,35 +428,26 @@ sub git_clone_all_submodules

sub git_add_remotes
{
my ($self, $repo_basename) = @_;

my $gerrit_repo_basename = $GERRIT_REPOS{$repo_basename};
if ($gerrit_repo_basename) {
my $gerrit_repo_url;

# If given a username, make a "verbose" remote.
# Otherwise, rely on proper SSH configuration.
if ($self->{'codereview-username'}) {
$gerrit_repo_url = $GERRIT_SSH_BASE;
$gerrit_repo_url =~ s,\@USER\@,$self->{'codereview-username'}\@,;
$gerrit_repo_url =~ s,\@PORT\@,:29418,;
}
else {
$gerrit_repo_url = $GERRIT_SSH_BASE;
$gerrit_repo_url =~ s,\@[^\@]+\@,,g;
}

$gerrit_repo_url .= $gerrit_repo_basename;
$self->exe('git', 'config', 'remote.gerrit.url', $gerrit_repo_url);
$self->exe('git', 'config', 'remote.gerrit.fetch', '+refs/heads/*:refs/remotes/gerrit/*', '/heads/');
my ($self, $gerrit_repo_basename) = @_;

my $gerrit_repo_url = $GERRIT_SSH_BASE;
# If given a username, make a "verbose" remote.
# Otherwise, rely on proper SSH configuration.
if ($self->{'codereview-username'}) {
$gerrit_repo_url =~ s,\@USER\@,$self->{'codereview-username'}\@,;
$gerrit_repo_url =~ s,\@PORT\@,:29418,;
} else {
$gerrit_repo_url =~ s,\@[^\@]+\@,,g;
}

return;
$gerrit_repo_url .= $gerrit_repo_basename;
$self->exe('git', 'config', 'remote.gerrit.url', $gerrit_repo_url);
$self->exe('git', 'config', 'remote.gerrit.fetch', '+refs/heads/*:refs/remotes/gerrit/*', '/heads/');
}

sub git_clone_one_submodule
{
my ($self, $submodule, $url) = @_;
my ($self, $submodule, $repo_basename, $url) = @_;

my $alternates = $self->{ 'alternates' };
my $mirror_url = $self->{ 'mirror-url' };
Expand Down Expand Up @@ -537,7 +504,7 @@ sub git_clone_one_submodule
$self->exe('git', 'config', 'commit.template', $template);
}

$self->git_add_remotes($submodule);
$self->git_add_remotes($repo_basename);

if ($self->{'detach-alternates'}) {
$self->exe('git', 'repack', '-a');
Expand Down Expand Up @@ -591,9 +558,9 @@ sub run
$self->check_if_already_initialized;
$self->git_clone_all_submodules(@{$self->{'module-subset'}});
$self->git_clone_all_submodules('qt/qt5', @{$self->{'module-subset'}});
$self->git_add_remotes('qt5');
$self->git_add_remotes('qt/qt5');
$self->git_install_hooks;
Expand Down

0 comments on commit 4553d9e

Please sign in to comment.