1 Star 0 Fork 1

zb872676223 / qt5

forked from pcd / qt5 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
init-repository 21.26 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
#!/usr/bin/env perl
#############################################################################
##
## Copyright (C) 2015 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the utilities of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:LGPL21$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see http://www.qt.io/terms-conditions. For further
## information use the contact form at http://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 or version 3 as published by the Free
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
## LICENSE.LGPLv3 included in the packaging of this file. Please review the
## following information to ensure the GNU Lesser General Public License
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## As a special exception, The Qt Company gives you certain additional
## rights. These rights are described in The Qt Company LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## $QT_END_LICENSE$
##
#############################################################################
use v5.8;
use strict;
use warnings;
package Qt::InitRepository;
sub printUsage($)
{
my ($ex) = @_;
print <<EOF ;
Usage:
./init-repository [options]
This script may be run after an initial `git clone' of Qt5 in order to
check out all submodules. It fetches them from canonical URLs inferred
from the clone's origin.
Options:
Global options:
--force, -f
Force initialization (even if the submodules are already checked
out).
--force-hooks
Force initialization of hooks (even if there are already hooks in
checked out submodules).
--quiet, -q
Be quiet. Will exit cleanly if the repository is already
initialized.
Module options:
--module-subset=<module1>,<module2>...
Only initialize the specified subset of modules given as the
argument. Specified modules must already exist in .gitmodules. The
string "all" results in cloning all known modules. The strings
"essential", "addon", "preview", "deprecated", "obsolete", and
"ignore" refer to classes of modules; "default" maps to
"essential,addon,preview,deprecated", which corresponds with the
set of maintained modules and is also the default set. Module
names may be prefixed with a dash to exclude them from a bigger
set, e.g. "all,-ignore".
--no-update
Skip the `git submodule update' command.
--no-fetch
Skip the `git fetch' commands. Implied by --no-update.
--branch
Instead of checking out specific SHA1s, check out the submodule
branches that correspond with the current supermodule commit. By
default, this option will cause local commits in the submodules to
be rebased. With --no-update, the branches will be checked out, but
their heads will not move.
--ignore-submodules
Set git config to ignore submodules by default when doing operations
on the qt5 repo, such as `pull', `fetch', `diff' etc.
After using this option, pass `--ignore-submodules=none' to git to
override it as needed.
Repository options:
--berlin
Switch to internal URLs and make use of the Berlin git mirrors.
(Implies `--mirror').
--oslo
Switch to internal URLs and make use of the Oslo git mirrors.
(Implies `--mirror').
--codereview-username <Gerrit/JIRA username>
Specify the user name for the (potentially) writable `gerrit' remote
for each module, for use with the Gerrit code review tool.
If this option is omitted, the gerrit remote is created without a
username and port number, and thus relies on a correct SSH
configuration.
--alternates <path to other Qt5 repo>
Adds alternates for each submodule to another full qt5 checkout.
This makes this qt5 checkout very small, as it will use the object
store of the alternates before unique objects are stored in its own
object store.
This option has no effect when using `--no-update'.
NOTE: This will make this repo dependent on the alternate, which is
potentially dangerous! The dependency can be broken by also using
the `--copy-objects' option, or by running "git repack -a" in each
submodule, where required. Please read the note about the `--shared'
option in the documentation of `git clone' for more information.
--copy-objects
When `--alternates' is used, automatically do a "git repack -a" in
each submodule after cloning, to ensure that the repositories are
independent from the source used as a reference for cloning.
Note that this negates the disk usage benefits gained from the use
of `--alternates'.
--mirror <url-base>
Uses <url-base> as the base URL for submodule git mirrors.
For example:
--mirror user\@machine:/foo/bar/qt/
...will use the following as a mirror for qtbase:
user\@machine:/foo/bar/qt/qtbase.git
The mirror is permitted to contain a subset of the submodules; any
missing modules will fall back to the canonical URLs.
EOF
exit($ex);
}
use Carp qw( confess );
use Cwd qw( getcwd abs_path );
use English qw( -no_match_vars );
use File::Spec::Functions qw ( rel2abs );
use Getopt::Long qw( GetOptions );
my $script_path = abs_path($0);
$script_path =~ s,[/\\][^/\\]+$,,;
my $GERRIT_SSH_BASE
= 'ssh://@USER@codereview.qt-project.org@PORT@/qt/';
my $BER_MIRROR_URL_BASE
= 'git://hegel/qt/';
my $OSLO_MIRROR_URL_BASE
= 'git://qilin/qt/';
sub new
{
my ($class, @arguments) = @_;
my $self = {};
bless $self, $class;
$self->parse_arguments(@arguments);
return $self;
}
# Like `system', but possibly log the command, and die on non-zero exit code
sub exe
{
my ($self, @cmd) = @_;
if (!$self->{quiet}) {
print "+ @cmd\n";
}
if (system(@cmd) != 0) {
confess "@cmd exited with status $CHILD_ERROR";
}
return;
}
sub parse_arguments
{
my ($self) = @_;
%{$self} = (%{$self},
'alternates' => "",
'branch' => 0,
'codereview-username' => "",
'detach-alternates' => 0 ,
'force' => 0 ,
'force-hooks' => 0 ,
'ignore-submodules' => 0 ,
'mirror-url' => "",
'update' => 1 ,
'fetch' => 1 ,
'module-subset' => "default",
);
GetOptions(
'alternates=s' => \$self->{qw{ alternates }},
'branch' => \$self->{qw{ branch }},
'codereview-username=s' => \$self->{qw{ codereview-username }},
'copy-objects' => \$self->{qw{ detach-alternates }},
'force|f' => \$self->{qw{ force }},
'force-hooks' => \$self->{qw{ force-hooks }},
'ignore-submodules' => \$self->{qw{ ignore-submodules }},
'mirror=s' => \$self->{qw{ mirror-url }},
'quiet' => \$self->{qw{ quiet }},
'update!' => \$self->{qw{ update }},
'fetch!' => \$self->{qw{ fetch }},
'module-subset=s' => \$self->{qw{ module-subset }},
'help|?' => sub { printUsage(1); },
'berlin' => sub {
$self->{'mirror-url'} = $BER_MIRROR_URL_BASE;
},
'oslo' => sub {
$self->{'mirror-url'} = $OSLO_MIRROR_URL_BASE;
},
) || printUsage(2);
# Replace any double trailing slashes from end of mirror
$self->{'mirror-url'} =~ s{//+$}{/};
$self->{'module-subset'} =~ s/\bdefault\b/preview,essential,addon,deprecated/;
$self->{'module-subset'} = [ split(/,/, $self->{'module-subset'}) ];
$self->{'fetch'} = 0 if (!$self->{'update'});
return;
}
sub check_if_already_initialized
{
my ($self) = @_;
# We consider the repo as `initialized' if submodule.qtbase.url is set
if (qx(git config --get submodule.qtbase.url)) {
if (!$self->{force}) {
exit 0 if ($self->{quiet});
print "Will not reinitialize already initialized repository (use -f to force)!\n";
exit 1;
}
}
return;
}
sub git_submodule_init
{
my ($self, @init_args) = @_;
if ($self->{quiet}) {
unshift @init_args, '--quiet';
}
$self->exe('git', 'submodule', 'init', @init_args);
my $template = getcwd()."/.commit-template";
if (-e $template) {
$self->exe('git', 'config', 'commit.template', $template);
}
return;
}
use constant {
STS_PREVIEW => 1,
STS_ESSENTIAL => 2,
STS_ADDON => 3,
STS_DEPRECATED => 4,
STS_OBSOLETE => 5
};
sub git_clone_all_submodules
{
my ($self, $my_repo_base, $co_branch, @subset) = @_;
my %subdirs = ();
my %subbranches = ();
my %subbases = ();
my %subinits = ();
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 "branch") {
$subbranches{$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 'none');
} elsif ($2 eq "status") {
if ($3 eq "preview") {
$subinits{$1} = STS_PREVIEW;
} elsif ($3 eq "essential") {
$subinits{$1} = STS_ESSENTIAL;
} elsif ($3 eq "addon") {
$subinits{$1} = STS_ADDON;
} elsif ($3 eq "deprecated") {
$subinits{$1} = STS_DEPRECATED;
} elsif ($3 eq "obsolete") {
$subinits{$1} = STS_OBSOLETE;
} elsif ($3 eq "ignore") {
delete $subinits{$1};
} else {
die("Invalid subrepo status '$3' for '$1'.\n");
}
}
}
my %include = ();
foreach my $mod (@subset) {
my $del = ($mod =~ s/^-//);
my $fail = 0;
my @what;
if ($mod eq "all") {
@what = keys %subbases;
} elsif ($mod eq "essential") {
@what = grep { ($subinits{$_} || 0) eq STS_ESSENTIAL } keys %subbases;
} elsif ($mod eq "addon") {
@what = grep { ($subinits{$_} || 0) eq STS_ADDON } keys %subbases;
} elsif ($mod eq "preview") {
@what = grep { ($subinits{$_} || 0) eq STS_PREVIEW } keys %subbases;
} elsif ($mod eq "deprecated") {
@what = grep { ($subinits{$_} || 0) eq STS_DEPRECATED } keys %subbases;
} elsif ($mod eq "obsolete") {
@what = grep { ($subinits{$_} || 0) eq STS_OBSOLETE } keys %subbases;
} elsif ($mod eq "ignore") {
@what = grep { ($subinits{$_} || 0) eq 0 } keys %subbases;
} elsif (defined($subdirs{$mod})) {
push @what, $mod;
} else {
$fail = 1;
}
if ($del) {
print "Warning: excluding non-existent module '$mod'.\n"
if ($fail);
map { delete $include{$_} } @what;
} else {
die("Error: module subset names non-existent '$mod'.\n")
if ($fail);
map { $include{$_} = 1; } @what;
}
}
my @modules = sort keys %include;
$self->git_submodule_init(map { $subdirs{$_} } @modules);
# manually clone each repo here, so we can easily use reference repos, mirrors etc
my @configresult = qx(git config -l);
foreach my $line (@configresult) {
# Example line: submodule.qtqa.url=git://code.qt.io/qt/qtqa.git
next if ($line !~ /submodule\.([^.=]+)\.url=/);
my $module = $1;
if (!defined($include{$module})) {
$self->exe('git', 'config', '--remove-section', "submodule.$module");
next;
}
if ($self->{'ignore-submodules'}) {
$self->exe('git', 'config', "submodule.$module.ignore", 'all');
}
}
my $any_bad = 0;
foreach my $module (@modules) {
$any_bad = 1
if ($self->git_stat_one_submodule($subdirs{$module}));
}
die("Dirty submodule(s) present; cannot proceed.\n")
if ($any_bad);
foreach my $module (@modules) {
$self->git_clone_one_submodule($subdirs{$module}, $subbases{$module},
$co_branch && $subbranches{$module});
}
if ($co_branch) {
foreach my $module (@modules) {
my $branch = $subbranches{$module};
die("No branch defined for submodule $module.\n") if (!defined($branch));
my $orig_cwd = getcwd();
chdir($module) or confess "chdir $module: $OS_ERROR";
my $br = qx(git rev-parse -q --verify $branch);
if (!$br) {
$self->exe('git', 'checkout', '-b', $branch, "origin/$branch");
} else {
$self->exe('git', 'checkout', $branch);
}
chdir("$orig_cwd") or confess "chdir $orig_cwd: $OS_ERROR";
}
}
if ($self->{update}) {
my @cmd = ('git', 'submodule', 'update', '--force', '--no-fetch');
push @cmd, '--remote', '--rebase' if ($co_branch);
$self->exe(@cmd);
foreach my $module (@modules) {
if (-f $module.'/.gitmodules') {
my $orig_cwd = getcwd();
chdir($module) or confess "chdir $module: $OS_ERROR";
$self->git_clone_all_submodules($subbases{$module}, 0, "all");
chdir("$orig_cwd") or confess "chdir $orig_cwd: $OS_ERROR";
}
}
}
return;
}
sub git_add_remotes
{
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;
}
$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_stat_one_submodule
{
my ($self, $submodule) = @_;
return 0 if (! -e "$submodule/.git");
my $orig_cwd = getcwd();
chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
my @sts = qx(git status --porcelain --untracked=no --ignore-submodules=all);
# After a git clone --no-checkout, git status reports all files as
# staged for deletion, but we still want to update the submodule.
# It's unlikely that a genuinely dirty index would have _only_ this
# type of modifications, and it doesn't seem like a horribly big deal
# to lose them anyway, so ignore them.
@sts = grep(!/^D /, @sts);
chdir($orig_cwd) or confess "cd $orig_cwd: $OS_ERROR";
return 0 if (!@sts);
print STDERR "$submodule is dirty.\n";
return -1;
}
sub git_clone_one_submodule
{
my ($self, $submodule, $repo_basename, $branch) = @_;
my $alternates = $self->{ 'alternates' };
my $mirror_url = $self->{ 'mirror-url' };
my $protocol = $self->{ 'protocol' };
# `--reference FOO' args for the clone, if any.
my @reference_args;
if ($alternates) {
# alternates is a qt5 repo, so the submodule will be under that.
if (-e "$alternates/$submodule/.git") {
@reference_args = ('--reference', "$alternates/$submodule");
}
else {
print " *** $alternates/$submodule not found, ignoring alternate for this submodule\n";
}
}
my $do_clone = (! -e "$submodule/.git");
my $url = $self->{'base-url'}.$repo_basename;
my $mirror;
if ($mirror_url && ($do_clone || $self->{fetch})) {
$mirror = $mirror_url.$repo_basename;
}
if ($mirror) {
# Only use the mirror if it can be reached.
eval { $self->exe('git', 'ls-remote', $mirror, 'test/if/mirror/exists') };
if ($@) {
warn "mirror [$mirror] is not accessible; $url will be used\n";
undef $mirror;
}
}
if ($do_clone) {
if ($branch) {
push @reference_args, '--branch', $branch;
} else {
push @reference_args, '--no-checkout';
}
$self->exe('git', 'clone', @reference_args,
($mirror ? $mirror : $url), $submodule);
}
my $orig_cwd = getcwd();
chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
if ($mirror) {
# This is only for the user's convenience - we make no use of it.
$self->exe('git', 'config', 'remote.mirror.url', $mirror);
$self->exe('git', 'config', 'remote.mirror.fetch', '+refs/heads/*:refs/remotes/mirror/*');
}
if (!$do_clone && $self->{fetch}) {
# If we didn't clone, fetch from the right location. We always update
# the origin remote, so that submodule update --remote works.
$self->exe('git', 'config', 'remote.origin.url', ($mirror ? $mirror : $url));
$self->exe('git', 'fetch', 'origin');
}
if (!($do_clone || $self->{fetch}) || $mirror) {
# Leave the origin configured to the canonical URL. It's already correct
# if we cloned/fetched without a mirror; otherwise it may be anything.
$self->exe('git', 'config', 'remote.origin.url', $url);
}
my $template = $orig_cwd."/.commit-template";
if (-e $template) {
$self->exe('git', 'config', 'commit.template', $template);
}
$self->git_add_remotes($repo_basename);
if ($self->{'detach-alternates'}) {
$self->exe('git', 'repack', '-a');
my $alternates_path = '.git/objects/info/alternates';
if (-e $alternates_path) {
unlink($alternates_path) || confess "unlink $alternates_path: $OS_ERROR";
}
}
chdir($orig_cwd) or confess "cd $orig_cwd: $OS_ERROR";
return;
}
sub ensure_link
{
my ($self, $src, $tgt) = @_;
return if (!$self->{'force-hooks'} and -f $tgt);
unlink($tgt); # In case we have a dead symlink or pre-existing hook
print "Aliasing $src\n as $tgt ...\n" if (!$self->{quiet});
if ($^O ne "msys" && $^O ne "MSWin32") {
return if eval { symlink($src, $tgt) };
}
# Windows doesn't do (proper) symlinks. As the post_commit script needs
# them to locate itself, we write a forwarding script instead.
open SCRIPT, ">".$tgt or die "Cannot create forwarding script $tgt: $!\n";
# Make the path palatable for MSYS.
$src =~ s,\\,/,g;
$src =~ s,^(.):/,/$1/,g;
print SCRIPT "#!/bin/sh\nexec $src \"\$\@\"\n";
close SCRIPT;
}
sub git_install_hooks
{
my ($self) = @_;
my $hooks = $script_path.'/qtrepotools/git-hooks';
return if (!-d $hooks);
my @configresult = qx(git config --list --local);
foreach my $line (@configresult) {
next if ($line !~ /submodule\.([^.=]+)\.url=/);
my $module = $1;
my $module_gitdir = $module.'/.git';
if (!-d $module_gitdir) {
open GITD, $module_gitdir or die "Cannot open $module: $!\n";
my $gd = <GITD>;
close GITD;
chomp($gd);
$gd =~ s/^gitdir: // or die "Malformed .git file $module_gitdir\n";
$module_gitdir = rel2abs($gd, $module);
if (open COMD, $module_gitdir.'/commondir') {
my $cd = <COMD>;
chomp($cd);
$module_gitdir .= '/'.$cd;
$module_gitdir = abs_path($module_gitdir);
close COMD;
}
}
$self->ensure_link($hooks.'/gerrit_commit_msg_hook', $module_gitdir.'/hooks/commit-msg');
$self->ensure_link($hooks.'/git_post_commit_hook', $module_gitdir.'/hooks/post-commit');
}
}
sub run
{
my ($self) = @_;
$self->check_if_already_initialized;
chomp(my $url = `git config remote.origin.url`);
die("Have no origin remote.\n") if (!$url);
$url =~ s,\.git$,,;
$url =~ s/qt5$//;
$self->{'base-url'} = $url;
$self->git_clone_all_submodules('qt5', $self->{branch}, @{$self->{'module-subset'}});
$self->git_add_remotes('qt5');
$self->git_install_hooks;
return;
}
#==============================================================================
Qt::InitRepository->new()->run if (!caller);
1;
1
https://gitee.com/zb872676223/qt5.git
git@gitee.com:zb872676223/qt5.git
zb872676223
qt5
qt5
5.10

搜索帮助