Browse Source

Remove use of deprecated getAllRefs() in ReceivePack

Repository.getAllRefs() is deprecated and should not
be used anymore. Leverage the ref-db and the retrieval
of refs by prefix and adapt the result to the expected
refname/ref map.

Bug: 534731
Change-Id: I37a9092859f220ddc4e5063d01544f3e82208be8
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
changes/00/182200/5
Luca Milanesio 2 years ago
parent
commit
ed5be35e2e
1 changed files with 19 additions and 1 deletions
  1. 19
    1
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

+ 19
- 1
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java View File

import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;


import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.InvalidObjectIdException; import org.eclipse.jgit.errors.InvalidObjectIdException;
*/ */
public void setAdvertisedRefs(Map<String, Ref> allRefs, public void setAdvertisedRefs(Map<String, Ref> allRefs,
Set<ObjectId> additionalHaves) { Set<ObjectId> additionalHaves) {
refs = allRefs != null ? allRefs : db.getAllRefs();
refs = allRefs != null ? allRefs : getAllRefs();
refs = refFilter.filter(refs); refs = refFilter.filter(refs);
advertisedHaves.clear(); advertisedHaves.clear();


return stats; return stats;
} }


/**
* Extract the full list of refs from the ref-db.
*
* @return Map of all refname/ref
*/
private Map<String, Ref> getAllRefs() {
try {
return db.getRefDatabase().getRefs().stream()
.collect(Collectors.toMap(Ref::getName,
Function.identity()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/** /**
* Receive a list of commands from the input. * Receive a list of commands from the input.
* *

Loading…
Cancel
Save