Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-03-16 17:45:17 -0400
committerThomas Wolf2019-03-16 17:45:17 -0400
commitb385340dae9e2b715fe8e10e3c98ed5c698e28bf (patch)
tree295a763ae428d18b06179d8d4e3760794d9f70c9
parentdf545e2b32e999d98b8f9240360744491a2797c4 (diff)
downloadegit-b385340dae9e2b715fe8e10e3c98ed5c698e28bf.tar.gz
egit-b385340dae9e2b715fe8e10e3c98ed5c698e28bf.tar.xz
egit-b385340dae9e2b715fe8e10e3c98ed5c698e28bf.zip
Replace usages of deprecated Repository methods
getTags() and peel() are deprecated; replace by equivalent other methods. Change-Id: I1edc2ff88f0f79ea3749a53bf89ffac46d4b4c62 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java10
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryUtil.java2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java28
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java29
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java29
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommandHandler.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties1
11 files changed, 76 insertions, 55 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
index 41a51506d..ae1ecbd12 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
@@ -24,7 +24,6 @@ import org.eclipse.egit.core.test.DualRepositoryTestCase;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -68,7 +67,7 @@ public class TagOperationTest extends DualRepositoryTestCase {
@Test
public void addTag() throws Exception {
assertTrue("Tags should be empty", repository1.getRepository()
- .getTags().isEmpty());
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
TagBuilder newTag = new TagBuilder();
newTag.setTag("TheNewTag");
newTag.setMessage("Well, I'm the tag");
@@ -79,7 +78,7 @@ public class TagOperationTest extends DualRepositoryTestCase {
newTag, false);
top.execute(new NullProgressMonitor());
assertFalse("Tags should not be empty", repository1.getRepository()
- .getTags().isEmpty());
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
try {
top.execute(null);
@@ -95,17 +94,16 @@ public class TagOperationTest extends DualRepositoryTestCase {
} catch (CoreException e) {
// expected
}
- Ref tagRef = repository1.getRepository().getTags().get("TheNewTag");
try (RevWalk walk = new RevWalk(repository1.getRepository())) {
RevTag tag = walk.parseTag(repository1.getRepository().resolve(
- tagRef.getName()));
+ Constants.R_TAGS + "TheNewTag"));
newTag.setMessage("Another message");
assertFalse("Messages should differ",
tag.getFullMessage().equals(newTag.getMessage()));
top.execute(null);
tag = walk.parseTag(repository1.getRepository().resolve(
- tagRef.getName()));
+ Constants.R_TAGS + "TheNewTag"));
assertTrue("Messages be same",
tag.getFullMessage().equals(newTag.getMessage()));
walk.dispose();
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryUtil.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryUtil.java
index 556d711ac..9a29c276d 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryUtil.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryUtil.java
@@ -223,7 +223,7 @@ public class RepositoryUtil {
.equals(commitId)) {
return checkoutEntry.getToBranch();
}
- ref = repository.peel(ref);
+ ref = repository.getRefDatabase().peel(ref);
}
if (ref != null) {
ObjectId id = ref.getPeeledObjectId();
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
index 979dfbcd6..34246c7a7 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
@@ -73,6 +73,9 @@ public class CoreText extends NLS {
public static String CommitFileRevision_errorLookingUpPath;
/** */
+ public static String CommitFileRevision_errorLookingUpTags;
+
+ /** */
public static String CommitFileRevision_pathNotIn;
/** */
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
index 6677c95bc..bcb0eab3a 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
@@ -16,7 +16,8 @@ Activator_invalidPreferredMergeStrategy=The configuration of the preferred merge
CherryPickOperation_cherryPicking=Running cherry-pick on commit {0}
CommitFileRevision_pathNotIn=Path {1} not in commit {0}.
-CommitFileRevision_errorLookingUpPath=IO error looking up path {1} in {0}.
+CommitFileRevision_errorLookingUpPath=I/O error looking up path {1} in {0}.
+CommitFileRevision_errorLookingUpTags=I/O error looking up tags in {0}.
ConfigureFetchAfterCloneTask_couldNotFetch=Could not fetch with refSpec {0}
ConnectProviderOperation_autoIgnoreMetaData=Auto-ignore .metadata and .recommenders if repository is located in Eclipse workspace
ConnectProviderOperation_connecting=Connecting Git team provider.
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java
index aa8f4bf37..153f6c203 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/storage/CommitFileRevision.java
@@ -13,9 +13,9 @@
package org.eclipse.egit.core.internal.storage;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
@@ -30,6 +30,7 @@ import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -118,14 +119,23 @@ public class CommitFileRevision extends GitFileRevision implements
@Override
public ITag[] getTags() {
final Collection<GitTag> ret = new ArrayList<>();
- for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {
- Ref ref = db.peel(tag.getValue());
- ObjectId refId = ref.getPeeledObjectId();
- if (refId == null)
- refId = ref.getObjectId();
- if (!AnyObjectId.equals(refId, commit))
- continue;
- ret.add(new GitTag(tag.getKey()));
+ RefDatabase refs = db.getRefDatabase();
+ try {
+ for (Ref tag : refs.getRefsByPrefix(Constants.R_TAGS)) {
+ Ref ref = refs.peel(tag);
+ ObjectId refId = ref.getPeeledObjectId();
+ if (refId == null)
+ refId = ref.getObjectId();
+ if (AnyObjectId.equals(refId, commit)) {
+ String tagName = tag.getName()
+ .substring(Constants.R_TAGS.length());
+ ret.add(new GitTag(tagName));
+ }
+ }
+ } catch (IOException e) {
+ Activator.logError(MessageFormat.format(
+ CoreText.CommitFileRevision_errorLookingUpTags,
+ db.getDirectory().getAbsolutePath()), e);
}
return ret.toArray(new ITag[0]);
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
index 28f7de193..fce9cb21a 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
@@ -15,7 +15,7 @@ package org.eclipse.egit.ui.test.team.actions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
import java.io.File;
@@ -86,8 +86,8 @@ public class TagActionTest extends LocalRepositoryTestCase {
.setText("Here's the message text");
tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
waitInUI();
- assertTrue(lookupRepository(repositoryFile).getTags().keySet()
- .contains("AnotherTag"));
+ assertNotNull(lookupRepository(repositoryFile)
+ .exactRef(Constants.R_TAGS + "AnotherTag"));
}
@Test
@@ -136,8 +136,8 @@ public class TagActionTest extends LocalRepositoryTestCase {
.setText("Here's the first message");
tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
waitInUI();
- assertTrue(lookupRepository(repositoryFile).getTags().keySet()
- .contains("MessageChangeTag"));
+ assertNotNull(lookupRepository(repositoryFile)
+ .exactRef(Constants.R_TAGS + "MessageChangeTag"));
tagDialog = openTagDialog();
tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
.getTableItem("MessageChangeTag").select();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 0cd9f2c7b..2f1aadf33 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -4471,6 +4471,9 @@ public class UIText extends NLS {
public static String CommitEditor_couldNotGetStashIndex;
/** */
+ public static String CommitEditor_couldNotGetTags;
+
+ /** */
public static String CommitEditor_showGitRepo;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
index 5392cb6be..9492bbf8e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
@@ -375,9 +375,10 @@ public class CommitEditorPage extends FormPage
return UIText.CommitEditorPage_LabelParent;
}
- private List<Ref> getTags() {
+ private List<Ref> getTags() throws IOException {
Repository repository = getCommit().getRepository();
- List<Ref> tags = new ArrayList<>(repository.getTags().values());
+ List<Ref> tags = new ArrayList<>(
+ repository.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
Collections.sort(tags, new Comparator<Ref>() {
@Override
@@ -614,14 +615,22 @@ public class CommitEditorPage extends FormPage
RevCommit commit = repoCommit.getRevCommit();
Repository repository = repoCommit.getRepository();
List<Ref> tags = new ArrayList<>();
- for (Ref tag : getTags()) {
- tag = repository.peel(tag);
- ObjectId id = tag.getPeeledObjectId();
- if (id == null)
- id = tag.getObjectId();
- if (!commit.equals(id))
- continue;
- tags.add(tag);
+ try {
+ for (Ref tag : getTags()) {
+ tag = repository.getRefDatabase().peel(tag);
+ ObjectId id = tag.getPeeledObjectId();
+ if (id == null) {
+ id = tag.getObjectId();
+ }
+ if (commit.equals(id)) {
+ tags.add(tag);
+ }
+ }
+ } catch (IOException e) {
+ Activator.logError(MessageFormat.format(
+ UIText.CommitEditor_couldNotGetTags,
+ commit.getName(),
+ repository.getDirectory().getAbsolutePath()), e);
}
return tags;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
index 2ada86e7d..56a6c9b06 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
@@ -22,8 +22,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -288,17 +286,18 @@ public class CommitInfoBuilder {
return name;
}
- private String getTagsString() {
+ private String getTagsString() throws IOException {
StringBuilder sb = new StringBuilder();
- Map<String, Ref> tagsMap = db.getTags();
- for (Entry<String, Ref> tagEntry : tagsMap.entrySet()) {
- ObjectId target = tagEntry.getValue().getPeeledObjectId();
- if (target == null)
- target = tagEntry.getValue().getObjectId();
+ for (Ref ref : db.getRefDatabase().getRefsByPrefix(Constants.R_TAGS)) {
+ ObjectId target = ref.getPeeledObjectId();
+ if (target == null) {
+ target = ref.getObjectId();
+ }
if (target != null && target.equals(commit)) {
- if (sb.length() > 0)
+ if (sb.length() > 0) {
sb.append(", "); //$NON-NLS-1$
- sb.append(tagEntry.getKey());
+ }
+ sb.append(formatTagRef(ref));
}
}
return sb.toString();
@@ -322,15 +321,14 @@ public class CommitInfoBuilder {
throw new OperationCanceledException();
try (RevWalk revWalk = new RevWalk(db)) {
revWalk.setRetainBody(false);
- Map<String, Ref> tagsMap = db.getTags();
Ref tagRef = null;
- for (Ref ref : tagsMap.values()) {
+ for (Ref ref : db.getRefDatabase()
+ .getRefsByPrefix(Constants.R_TAGS)) {
if (monitor.isCanceled())
throw new OperationCanceledException();
// both RevCommits must be allocated using same RevWalk
- // instance,
- // otherwise isMergedInto returns wrong result!
+ // instance, otherwise isMergedInto returns wrong result!
RevCommit current = revWalk.parseCommit(commit);
// tags can point to any object, we only want tags pointing at
// commits
@@ -351,8 +349,7 @@ public class CommitInfoBuilder {
.parseCommit(tagRef.getObjectId());
// both oldTag and newTag satisfy search criteria, so
- // taking
- // the closest one
+ // taking the closest one
if (isMergedInto(revWalk, oldTag, newTag,
searchDescendant))
tagRef = ref;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommandHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommandHandler.java
index 85821835d..5fe593a48 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommandHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommandHandler.java
@@ -121,17 +121,16 @@ abstract class AbstractHistoryCommandHandler extends AbstractHandler {
protected List<RevTag> getRevTags(ExecutionEvent event)
throws ExecutionException {
Repository repo = getRepository(event);
- Collection<Ref> revTags = repo.getTags().values();
- List<RevTag> tags = new ArrayList<>();
try (RevWalk walk = new RevWalk(repo)) {
+ Collection<Ref> revTags = repo.getRefDatabase()
+ .getRefsByPrefix(Constants.R_TAGS);
+ List<RevTag> tags = new ArrayList<>();
for (Ref ref : revTags) {
- try {
- tags.add(walk.parseTag(repo.resolve(ref.getName())));
- } catch (IOException e) {
- throw new ExecutionException(e.getMessage(), e);
- }
+ tags.add(walk.parseTag(repo.resolve(ref.getName())));
}
return tags;
+ } catch (IOException e) {
+ throw new ExecutionException(e.getMessage(), e);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index b83b37f10..04c2be027 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1535,6 +1535,7 @@ CommitActionHandler_repository=Repository: {0}
CommitEditor_couldNotShowRepository=Could not show repository
CommitEditor_couldNotFindStashCommit=Could not find stash commit
CommitEditor_couldNotGetStashIndex=Could not get stash index for commit ''{0}''
+CommitEditor_couldNotGetTags=Could not get tags for commit ''{0}'' in {1}
CommitEditor_showGitRepo=Show Git Repository
CommitEditor_toolbarApplyStash=Apply Stashed Changes
CommitEditor_toolbarDeleteStash=Delete Stashed Commit...

Back to the top