From f6c4a492d06e0dd345679bfba3399dabbf778f41 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 22 May 2018 11:27:30 +0900 Subject: [PATCH] Repository: Deprecate #peel method Callers should use getRefDatabase().peel(ref) instead since it doesn't swallow the IOException. Adapt all trivial callers to user the alternative. DescribeCommand still uses the deprecated method and is not adapted in this change since it will require more refactoring to add handling of the IOException. Change-Id: I14d4a95a5e0570548753b9fc5c03d024dc3ff832 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java | 2 +- .../tst/org/eclipse/jgit/api/LogCommandTest.java | 2 +- .../tst/org/eclipse/jgit/api/TagCommandTest.java | 9 ++++++--- .../tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java | 2 +- .../src/org/eclipse/jgit/api/LogCommand.java | 2 +- .../src/org/eclipse/jgit/api/MergeCommand.java | 2 +- .../src/org/eclipse/jgit/lib/Repository.java | 2 ++ .../src/org/eclipse/jgit/transport/RefAdvertiser.java | 4 ++-- .../src/org/eclipse/jgit/transport/UploadPack.java | 2 +- 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java index 86092b27a..063600f4e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java @@ -161,7 +161,7 @@ class RebuildRefTree extends TextBuiltin { } cmds.add(new org.eclipse.jgit.internal.storage.reftree.Command( null, - db.peel(r))); + db.getRefDatabase().peel(r))); } tree.apply(cmds); return tree; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java index bd0efad01..4ef511e43 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java @@ -116,7 +116,7 @@ public class LogCommandTest extends RepositoryTestCase { Iterator log = git.log().all().call().iterator(); assertTrue(log.hasNext()); RevCommit commit = log.next(); - tag = db.peel(tag); + tag = db.getRefDatabase().peel(tag); assertEquals(commit.getName(), tag.getPeeledObjectId().getName()); assertTrue(commits.contains(commit)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java index 3b29a5bbf..a220e77e0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java @@ -67,19 +67,22 @@ public class TagCommandTest extends RepositoryTestCase { RevWalk walk = new RevWalk(db)) { RevCommit commit = git.commit().setMessage("initial commit").call(); Ref tagRef = git.tag().setName("tag").call(); - assertEquals(commit.getId(), db.peel(tagRef).getPeeledObjectId()); + assertEquals(commit.getId(), + db.getRefDatabase().peel(tagRef).getPeeledObjectId()); assertEquals("tag", walk.parseTag(tagRef.getObjectId()).getTagName()); } } @Test - public void testTagging() throws GitAPIException, JGitInternalException { + public void testTagging() + throws GitAPIException, JGitInternalException, IOException { try (Git git = new Git(db)) { git.commit().setMessage("initial commit").call(); RevCommit commit = git.commit().setMessage("second commit").call(); git.commit().setMessage("third commit").call(); Ref tagRef = git.tag().setObjectId(commit).setName("tag").call(); - assertEquals(commit.getId(), db.peel(tagRef).getPeeledObjectId()); + assertEquals(commit.getId(), + db.getRefDatabase().peel(tagRef).getPeeledObjectId()); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index fa45214f0..df31ab086 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -160,7 +160,7 @@ public class RepoCommandTest extends RepositoryTestCase { Ref ref = r.findRef(refname); if (ref == null) return null; - ref = r.peel(ref); + ref = r.getRefDatabase().peel(ref); ObjectId id = ref.getObjectId(); return id; } catch (IOException e) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index cdf8cdd8d..cf3d35fe8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -274,7 +274,7 @@ public class LogCommand extends GitCommand> { public LogCommand all() throws IOException { for (Ref ref : getRepository().getRefDatabase().getRefs()) { if(!ref.isPeeled()) - ref = getRepository().peel(ref); + ref = getRepository().getRefDatabase().peel(ref); ObjectId objectId = ref.getPeeledObjectId(); if (objectId == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index c8a9049e6..b8fa74de7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -255,7 +255,7 @@ public class MergeCommand extends GitCommand { refLogMessage.append(ref.getName()); // handle annotated tags - ref = repo.peel(ref); + ref = repo.getRefDatabase().peel(ref); ObjectId objectId = ref.getPeeledObjectId(); if (objectId == null) objectId = ref.getObjectId(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 5fb4e4008..fa283d012 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -1133,7 +1133,9 @@ public abstract class Repository implements AutoCloseable { * new Ref object representing the same data as Ref, but isPeeled() * will be true and getPeeledObjectId will contain the peeled object * (or null). + * @deprecated use {@code getRefDatabase().peel(ref)} instead. */ + @Deprecated @NonNull public Ref peel(Ref ref) { try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index 1bde49df2..dc1871b72 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -322,7 +322,7 @@ public abstract class RefAdvertiser { String peelPart = ""; //$NON-NLS-1$ if (derefTags) { if (!ref.isPeeled() && repository != null) { - ref = repository.peel(ref); + ref = repository.getRefDatabase().peel(ref); } ObjectId peeledObjectId = ref.getPeeledObjectId(); if (peeledObjectId != null) { @@ -342,7 +342,7 @@ public abstract class RefAdvertiser { if (!ref.isPeeled()) { if (repository == null) continue; - ref = repository.peel(ref); + ref = repository.getRefDatabase().peel(ref); } if (ref.getPeeledObjectId() != null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 3d4d279a5..82e6e62f0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1932,7 +1932,7 @@ public class UploadPack { } if (!ref.isPeeled()) - ref = db.peel(ref); + ref = db.getRefDatabase().peel(ref); ObjectId peeledId = ref.getPeeledObjectId(); objectId = ref.getObjectId();