diff options
Diffstat (limited to 'src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java')
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java index 64f5152..1efad4f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java @@ -21,25 +21,22 @@ import com.google.common.base.Throwables; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Sets; -import com.google.gerrit.common.Nullable; import com.google.gerrit.extensions.events.GitReferenceUpdatedListener; +import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.metrics.Timer1; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.RefNames; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.PerThreadRequestScope; import com.google.gerrit.server.git.ProjectRunnable; -import com.google.gerrit.server.git.SearchingChangeCacheImpl; -import com.google.gerrit.server.git.TagCache; import com.google.gerrit.server.git.VisibleRefFilter; import com.google.gerrit.server.git.WorkQueue.CanceledWhileRunning; -import com.google.gerrit.server.notedb.ChangeNotes; +import com.google.gerrit.server.permissions.PermissionBackend; +import com.google.gerrit.server.permissions.PermissionBackendException; +import com.google.gerrit.server.permissions.ProjectPermission; import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.util.IdGenerator; -import com.google.gwtorm.server.OrmException; -import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.googlesource.gerrit.plugins.replication.ReplicationState.RefPushResult; @@ -90,14 +87,12 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } private final GitRepositoryManager gitManager; - private final SchemaFactory<ReviewDb> schema; + private final PermissionBackend permissionBackend; private final Destination pool; private final RemoteConfig config; private final CredentialsProvider credentialsProvider; - private final TagCache tagCache; private final PerThreadRequestScope.Scoper threadScoper; - private final ChangeNotes.Factory changeNotesFactory; - private final SearchingChangeCacheImpl changeCache; + private final VisibleRefFilter.Factory refFilterFactory; private final ReplicationQueue replicationQueue; private final Project.NameKey projectName; @@ -120,14 +115,12 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { @Inject PushOne( GitRepositoryManager grm, - SchemaFactory<ReviewDb> s, + PermissionBackend permissionBackend, Destination p, RemoteConfig c, + VisibleRefFilter.Factory rff, CredentialsFactory cpFactory, - TagCache tc, PerThreadRequestScope.Scoper ts, - ChangeNotes.Factory nf, - @Nullable SearchingChangeCacheImpl cc, ReplicationQueue rq, IdGenerator ig, ReplicationStateListener sl, @@ -135,14 +128,12 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { @Assisted Project.NameKey d, @Assisted URIish u) { gitManager = grm; - schema = s; + this.permissionBackend = permissionBackend; pool = p; config = c; + refFilterFactory = rff; credentialsProvider = cpFactory.create(c.getName()); - tagCache = tc; threadScoper = ts; - changeNotesFactory = nf; - changeCache = cc; replicationQueue = rq; projectName = d; uri = u; @@ -338,7 +329,9 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { // does not exist. In this case NoRemoteRepositoryException is not // raised. String msg = e.getMessage(); - if (msg.contains("access denied") || msg.contains("no such repository")) { + if (msg.contains("access denied") + || msg.contains("no such repository") + || msg.contains("Git repository not found")) { createRepository(); } else { repLog.error("Cannot replicate {}; Remote repository error: {}", projectName, msg); @@ -383,7 +376,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } } catch (IOException e) { stateLog.error("Cannot replicate to " + uri, e, getStatesAsArray()); - } catch (RuntimeException | Error e) { + } catch (PermissionBackendException | RuntimeException | Error e) { stateLog.error("Unexpected error during replication to " + uri, e, getStatesAsArray()); } finally { if (git != null) { @@ -430,7 +423,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { return target.getName(); } - private void runImpl() throws IOException { + private void runImpl() throws IOException, PermissionBackendException { PushResult res; try (Transport tn = Transport.open(git, uri)) { res = pushVia(tn); @@ -439,7 +432,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } private PushResult pushVia(Transport tn) - throws IOException, NotSupportedException, TransportException { + throws IOException, NotSupportedException, TransportException, PermissionBackendException { tn.applyConfig(config); tn.setCredentialsProvider(credentialsProvider); @@ -457,7 +450,8 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { return tn.push(NullProgressMonitor.INSTANCE, todo); } - private List<RemoteRefUpdate> generateUpdates(Transport tn) throws IOException { + private List<RemoteRefUpdate> generateUpdates(Transport tn) + throws IOException, PermissionBackendException { ProjectControl pc; try { pc = pool.controlFor(projectName); @@ -466,7 +460,14 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } Map<String, Ref> local = git.getAllRefs(); - if (!pc.allRefsAreVisible()) { + boolean filter; + try { + permissionBackend.user(pc.getUser()).project(projectName).check(ProjectPermission.READ); + filter = false; + } catch (AuthException e) { + filter = true; + } + if (filter) { if (!pushAllRefs) { // If we aren't mirroring, reduce the space we need to filter // to only the references we will update during this operation. @@ -480,16 +481,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } local = n; } - - try (ReviewDb db = schema.open()) { - local = - new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, git, pc, db, true) - .filter(local, true); - } catch (OrmException e) { - stateLog.error( - "Cannot read database to replicate to " + projectName, e, getStatesAsArray()); - return Collections.emptyList(); - } + local = refFilterFactory.create(pc.getProjectState(), git).filter(local, true); } return pushAllRefs ? doPushAll(tn, local) : doPushDelta(local); |