in src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java [293:359]
private boolean shouldReplicate(
final Project.NameKey project, String ref, ReplicationState... states) {
try {
return threadScoper
.scope(
new Callable<Boolean>() {
@Override
public Boolean call() throws NoSuchProjectException, PermissionBackendException {
Optional<ProjectState> projectState;
try {
projectState = projectCache.get(project);
} catch (StorageException e) {
repLog.warn(
"NOT scheduling replication {}:{} because could not open source project",
project,
ref,
e);
return false;
}
if (!projectState.isPresent()) {
repLog.warn(
"NOT scheduling replication {}:{} because project does not exist",
project,
ref);
throw new NoSuchProjectException(project);
}
if (!projectState.get().statePermitsRead()) {
repLog.warn(
"NOT scheduling replication {}:{} because project is not readable",
project,
ref);
return false;
}
if (!shouldReplicate(projectState.get(), userProvider.get())) {
return false;
}
if (FetchOne.ALL_REFS.equals(ref)) {
return true;
}
try {
if (!ref.startsWith(RefNames.REFS_CHANGES)) {
permissionBackend
.user(userProvider.get())
.project(project)
.ref(ref)
.check(RefPermission.READ);
}
} catch (AuthException e) {
repLog.warn(
"NOT scheduling replication {}:{} because lack of permissions to access project/ref",
project,
ref);
return false;
}
return true;
}
})
.call();
} catch (NoSuchProjectException err) {
stateLog.error(String.format("source project %s not available", project), err, states);
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
repLog.warn("NOT scheduling replication {}:{}", project, ref);
return false;
}