Browse Source

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>
stable-5.1
David Pursehouse 7 years ago
parent
commit
1f6d43a652
  1. 6
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  2. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
  3. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
  4. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java

6
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -757,7 +757,7 @@ public class TestRepository<R extends Repository> {
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 class TestRepository<R extends Repository> {
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 class TestRepository<R extends Repository> {
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);

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java

@ -245,7 +245,7 @@ public class PushCommandTest extends RepositoryTestCase {
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"));
}

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java

@ -972,7 +972,7 @@ public class DfsGarbageCollectorTest {
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;) {

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java

@ -115,7 +115,7 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
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);

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java

@ -146,7 +146,7 @@ public class DfsFsck {
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

Loading…
Cancel
Save