Don't use deprecated Repository#getAllRefs in FileRepository
Also expose the potentially IOException thrown by RefDatabase#getRefs. Hence the following methods now potentially throw IOException: - AdvertiseRefsHook#advertiseRefs - ReceivePack#setAdvertisedRefs - Repository#getAdditionalHaves Bug: 534731 Change-Id: I85bc6ce5815d40be5f80042c53f4663072d96be5
This commit is contained in:
parent
c20dd8206e
commit
403338e116
|
@ -142,7 +142,7 @@ ReceivePack createReceivePack(Repository db) {
|
||||||
rp.setAdvertiseRefsHook(new AdvertiseRefsHook() {
|
rp.setAdvertiseRefsHook(new AdvertiseRefsHook() {
|
||||||
@Override
|
@Override
|
||||||
public void advertiseRefs(ReceivePack rp2)
|
public void advertiseRefs(ReceivePack rp2)
|
||||||
throws ServiceMayNotContinueException {
|
throws IOException {
|
||||||
rp.setAdvertisedRefs(rp.getRepository().getAllRefs(),
|
rp.setAdvertisedRefs(rp.getRepository().getAllRefs(),
|
||||||
null);
|
null);
|
||||||
new HidePrivateHook().advertiseRefs(rp);
|
new HidePrivateHook().advertiseRefs(rp);
|
||||||
|
|
|
@ -420,9 +420,11 @@ private File descriptionFile() {
|
||||||
* advertise that it safely has that other repository's references, without
|
* advertise that it safely has that other repository's references, without
|
||||||
* exposing any other details about the other repository. This may help a
|
* exposing any other details about the other repository. This may help a
|
||||||
* client trying to push changes avoid pushing more than it needs to.
|
* client trying to push changes avoid pushing more than it needs to.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<ObjectId> getAdditionalHaves() {
|
public Set<ObjectId> getAdditionalHaves() throws IOException {
|
||||||
return getAdditionalHaves(null);
|
return getAdditionalHaves(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,8 +440,11 @@ public Set<ObjectId> getAdditionalHaves() {
|
||||||
* Set of AlternateHandle Ids already seen
|
* Set of AlternateHandle Ids already seen
|
||||||
*
|
*
|
||||||
* @return unmodifiable collection of other known objects.
|
* @return unmodifiable collection of other known objects.
|
||||||
|
* @throws IOException
|
||||||
|
* if getting refs hits an IO error
|
||||||
*/
|
*/
|
||||||
private Set<ObjectId> getAdditionalHaves(Set<AlternateHandle.Id> skips) {
|
private Set<ObjectId> getAdditionalHaves(Set<AlternateHandle.Id> skips)
|
||||||
|
throws IOException {
|
||||||
HashSet<ObjectId> r = new HashSet<>();
|
HashSet<ObjectId> r = new HashSet<>();
|
||||||
skips = objectDatabase.addMe(skips);
|
skips = objectDatabase.addMe(skips);
|
||||||
for (AlternateHandle d : objectDatabase.myAlternates()) {
|
for (AlternateHandle d : objectDatabase.myAlternates()) {
|
||||||
|
@ -447,7 +452,7 @@ private Set<ObjectId> getAdditionalHaves(Set<AlternateHandle.Id> skips) {
|
||||||
FileRepository repo;
|
FileRepository repo;
|
||||||
|
|
||||||
repo = ((AlternateRepository) d).repository;
|
repo = ((AlternateRepository) d).repository;
|
||||||
for (Ref ref : repo.getAllRefs().values()) {
|
for (Ref ref : repo.getRefDatabase().getRefs()) {
|
||||||
if (ref.getObjectId() != null)
|
if (ref.getObjectId() != null)
|
||||||
r.add(ref.getObjectId());
|
r.add(ref.getObjectId());
|
||||||
if (ref.getPeeledObjectId() != null)
|
if (ref.getPeeledObjectId() != null)
|
||||||
|
|
|
@ -1051,13 +1051,14 @@ public String getBranch() throws IOException {
|
||||||
* <p>
|
* <p>
|
||||||
* When a repository borrows objects from another repository, it can
|
* When a repository borrows objects from another repository, it can
|
||||||
* advertise that it safely has that other repository's references, without
|
* advertise that it safely has that other repository's references, without
|
||||||
* exposing any other details about the other repository. This may help
|
* exposing any other details about the other repository. This may help a
|
||||||
* a client trying to push changes avoid pushing more than it needs to.
|
* client trying to push changes avoid pushing more than it needs to.
|
||||||
*
|
*
|
||||||
* @return unmodifiable collection of other known objects.
|
* @return unmodifiable collection of other known objects.
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Set<ObjectId> getAdditionalHaves() {
|
public Set<ObjectId> getAdditionalHaves() throws IOException {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.transport;
|
package org.eclipse.jgit.transport;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -65,10 +66,12 @@ public void advertiseRefs(UploadPack uploadPack)
|
||||||
uploadPack.getRepository(), uploadPack.getRevWalk()));
|
uploadPack.getRepository(), uploadPack.getRevWalk()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void advertiseRefs(ReceivePack receivePack)
|
public void advertiseRefs(ReceivePack receivePack)
|
||||||
throws ServiceMayNotContinueException {
|
throws IOException {
|
||||||
Map<String, Ref> refs = getAdvertisedRefs(receivePack.getRepository(),
|
Map<String, Ref> refs = getAdvertisedRefs(receivePack.getRepository(),
|
||||||
receivePack.getRevWalk());
|
receivePack.getRevWalk());
|
||||||
Set<ObjectId> haves = getAdvertisedHaves(receivePack.getRepository(),
|
Set<ObjectId> haves = getAdvertisedHaves(receivePack.getRepository(),
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.transport;
|
package org.eclipse.jgit.transport;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to allow callers to take over advertising refs to the client.
|
* Hook to allow callers to take over advertising refs to the client.
|
||||||
*
|
*
|
||||||
|
@ -89,8 +91,9 @@ void advertiseRefs(UploadPack uploadPack)
|
||||||
* if necessary.
|
* if necessary.
|
||||||
* @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
|
* @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
|
||||||
* abort; the message will be sent to the user.
|
* abort; the message will be sent to the user.
|
||||||
|
* @throws IOException
|
||||||
* @since 5.6
|
* @since 5.6
|
||||||
*/
|
*/
|
||||||
void advertiseRefs(ReceivePack receivePack)
|
void advertiseRefs(ReceivePack receivePack)
|
||||||
throws ServiceMayNotContinueException;
|
throws ServiceMayNotContinueException, IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.transport;
|
package org.eclipse.jgit.transport;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,10 +50,12 @@ public static AdvertiseRefsHook newChain(List<? extends AdvertiseRefsHook> hooks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void advertiseRefs(ReceivePack rp)
|
public void advertiseRefs(ReceivePack rp)
|
||||||
throws ServiceMayNotContinueException {
|
throws IOException {
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
hooks[i].advertiseRefs(rp);
|
hooks[i].advertiseRefs(rp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -440,9 +440,10 @@ public Map<String, Ref> getAdvertisedRefs() {
|
||||||
* explicit set of additional haves to claim as advertised. If
|
* explicit set of additional haves to claim as advertised. If
|
||||||
* null, assumes the default set of additional haves from the
|
* null, assumes the default set of additional haves from the
|
||||||
* repository.
|
* repository.
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void setAdvertisedRefs(Map<String, Ref> allRefs,
|
public void setAdvertisedRefs(Map<String, Ref> allRefs,
|
||||||
Set<ObjectId> additionalHaves) {
|
Set<ObjectId> additionalHaves) throws IOException {
|
||||||
refs = allRefs != null ? allRefs : getAllRefs();
|
refs = allRefs != null ? allRefs : getAllRefs();
|
||||||
refs = refFilter.filter(refs);
|
refs = refFilter.filter(refs);
|
||||||
advertisedHaves.clear();
|
advertisedHaves.clear();
|
||||||
|
@ -1187,8 +1188,9 @@ protected void init(final InputStream input, final OutputStream output,
|
||||||
* Get advertised refs, or the default if not explicitly advertised.
|
* Get advertised refs, or the default if not explicitly advertised.
|
||||||
*
|
*
|
||||||
* @return advertised refs, or the default if not explicitly advertised.
|
* @return advertised refs, or the default if not explicitly advertised.
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private Map<String, Ref> getAdvertisedOrDefaultRefs() {
|
private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
|
||||||
if (refs == null)
|
if (refs == null)
|
||||||
setAdvertisedRefs(null, null);
|
setAdvertisedRefs(null, null);
|
||||||
return refs;
|
return refs;
|
||||||
|
|
Loading…
Reference in New Issue