Fix trivial usages of deprecated Repository#getAllRefs

Callers of getAllRefs that only iterate over the `values()` of the
returned map can be trivially fixed to call getRefDatabase().getRefs()
instead.

Only fix those where the calling method is already declared to throw
IOException, to avoid potential API changes.

Change-Id: I2b05f785077a1713953cfd42df7bf915f889f90b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-05-23 13:31:22 +09:00
parent d369b61852
commit 1f6d43a652
5 changed files with 7 additions and 7 deletions

View File

@ -757,7 +757,7 @@ public RevCommit cherryPick(AnyObjectId id) throws Exception {
public void updateServerInfo() throws Exception {
if (db instanceof FileRepository) {
final FileRepository fr = (FileRepository) db;
RefWriter rw = new RefWriter(fr.getAllRefs().values()) {
RefWriter rw = new RefWriter(fr.getRefDatabase().getRefs()) {
@Override
protected void writeFile(String name, byte[] bin)
throws IOException {
@ -852,7 +852,7 @@ public void fsck(RevObject... tips) throws MissingObjectException,
for (RevObject o : tips)
ow.markStart(ow.parseAny(o));
} else {
for (Ref r : db.getAllRefs().values())
for (Ref r : db.getRefDatabase().getRefs())
ow.markStart(ow.parseAny(r.getObjectId()));
}
@ -905,7 +905,7 @@ public void packAndPrune() throws Exception {
final File pack, idx;
try (PackWriter pw = new PackWriter(db)) {
Set<ObjectId> all = new HashSet<>();
for (Ref r : db.getAllRefs().values())
for (Ref r : db.getRefDatabase().getRefs())
all.add(r.getObjectId());
pw.preparePack(m, all, PackWriter.NONE);

View File

@ -245,7 +245,7 @@ public void testPushRefUpdate() throws Exception {
git.add().addFilepattern("f" + i).call();
commit = git.commit().setMessage("adding f" + i).call();
git.push().setRemote("test").call();
git2.getRepository().getAllRefs();
git2.getRepository().getRefDatabase().getRefs();
assertEquals("failed to update on attempt " + i, commit.getId(),
git2.getRepository().resolve("refs/heads/test"));
}

View File

@ -972,7 +972,7 @@ private void run(DfsGarbageCollector gc) throws IOException {
private static boolean isReachable(Repository repo, AnyObjectId id)
throws IOException {
try (RevWalk rw = new RevWalk(repo)) {
for (Ref ref : repo.getAllRefs().values()) {
for (Ref ref : repo.getRefDatabase().getRefs()) {
rw.markStart(rw.parseCommit(ref.getObjectId()));
}
for (RevCommit next; (next = rw.next()) != null;) {

View File

@ -115,7 +115,7 @@ private Ref branch(String name, RevCommit dst) throws Exception {
}
private void assertContains(RevCommit commit, Collection<Ref> refsThatShouldContainCommit) throws Exception {
Collection<Ref> allRefs = db.getAllRefs().values();
Collection<Ref> allRefs = db.getRefDatabase().getRefs();
Collection<Ref> sortedRefs = RefComparator.sort(allRefs);
List<Ref> actual = RevWalkUtils.findBranchesReachableFrom(commit,
rw, sortedRefs);

View File

@ -146,7 +146,7 @@ private void checkConnectivity(ProgressMonitor pm, FsckError errors)
throws IOException {
pm.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN);
try (ObjectWalk ow = new ObjectWalk(repo)) {
for (Ref r : repo.getAllRefs().values()) {
for (Ref r : repo.getRefDatabase().getRefs()) {
ObjectId objectId = r.getObjectId();
if (objectId == null) {
// skip unborn branch