summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>2020-06-25 17:57:00 +0200
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2020-06-26 10:54:33 +0000
commit194a6f1987b7b2161c3d2cfae8b33a64b58db4c3 (patch)
treeee13528c88052f7469937f3cdfdbb850f2eba8a4 /bin
parent169c46dcb39eaf3e48e29e30e712e039cc84e2e7 (diff)
downloadqtrepotools-194a6f1987b7b2161c3d2cfae8b33a64b58db4c3.tar.gz
gpush/gpick: add support for url.*.{push,}insteadOf
Started-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: I00e15103c0341c0a197681161605c24f70e080be Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'bin')
-rw-r--r--bin/git_gpush.pm32
1 files changed, 29 insertions, 3 deletions
diff --git a/bin/git_gpush.pm b/bin/git_gpush.pm
index 65515bb..a94465e 100644
--- a/bin/git_gpush.pm
+++ b/bin/git_gpush.pm
@@ -313,6 +313,9 @@ sub goto_gitdir()
# `git config --list` output, plus contents of .git-gpush-aliases' [config]
our %gitconfig; # { key => [ value, ... ] }
+# Pre-processed url.*.insteadOf mappings.
+my @url_rewrites;
+my @url_rewrites_push;
sub _load_git_config()
{
@@ -321,9 +324,20 @@ sub _load_git_config()
my $cfg = open_cmd_pipe(0, 'git', 'config', '-l', '-z');
while (read_fields($cfg, my $entry)) {
$entry =~ /^([^\n]+)\n(.*)$/;
- push @{$gitconfig{$1}}, $2;
+ my ($key, $value) = ($1, $2);
+ push @{$gitconfig{$key}}, $value;
+
+ if ($key =~ /^url\.(.*)\.insteadof$/) {
+ push @url_rewrites, [ $value, $1 ];
+ } elsif ($key =~ /^url\.(.*)\.pushinsteadof$/) {
+ push @url_rewrites_push, [ $value, $1 ];
+ }
}
close_process($cfg);
+
+ # Sort backwards, so longest match is hit first.
+ @url_rewrites = sort { $$b[0] cmp $$a[0] } @url_rewrites;
+ @url_rewrites_push = sort { $$b[0] cmp $$a[0] } @url_rewrites_push;
}
sub git_configs($)
@@ -340,6 +354,17 @@ sub git_config($;$)
return scalar(@cfg) ? $cfg[-1] : $dflt;
}
+sub _rewrite_git_url($$)
+{
+ my ($url, $push) = @_;
+
+ foreach my $ent ($push ? @url_rewrites_push : @url_rewrites) {
+ my ($pfx, $sub) = @$ent;
+ return $url if ($url =~ s/^\Q$pfx\E/$sub/);
+ }
+ return $url;
+}
+
our $_indexfile;
END { unlink($_indexfile) if ($_indexfile); }
@@ -2104,9 +2129,10 @@ sub set_gerrit_config($)
{
my ($rmt) = @_;
- my $url = git_config('remote.'.$rmt.'.pushurl');
- $url = git_config('remote.'.$rmt.'.url') if (!$url);
+ my ($url, $push) = (git_config('remote.'.$rmt.'.pushurl'), 1);
+ ($url, $push) = (git_config('remote.'.$rmt.'.url'), 0) if (!$url);
fail("Remote '$rmt' does not exist.\n") if (!$url);
+ $url = _rewrite_git_url($url, $push);
if ($url =~ m,^ssh://([^/:]+)(?::(\d+))?/(.*?)(?:\.git)?/?$,) {
push @gerrit_ssh, '-p', $2 if (defined($2));
push @gerrit_ssh, $1;