aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-08-01 18:47:59 -0400
committerMatthias Sohn2018-08-11 07:14:38 -0400
commit89b461417285208d1e3ca1b4f9d659e828c7aa2c (patch)
tree757180ed9dcc9343e3620b39eb144e070b727558
parentfbe808a18a21a6abb35a965cf2bb5bde026d2248 (diff)
downloadegit-89b461417285208d1e3ca1b4f9d659e828c7aa2c.tar.gz
egit-89b461417285208d1e3ca1b4f9d659e828c7aa2c.tar.xz
egit-89b461417285208d1e3ca1b4f9d659e828c7aa2c.zip
Simplify operations on FileDiffs
Since commit 9df32ed FileDiffs carry along the repository they belong to, so it's no longer necessary to store it and pass it through separately. Change-Id: I05b78c98d3b8dfbe6a7aca9061771d9c05eac615 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java20
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java26
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java32
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java28
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java2
8 files changed, 49 insertions, 74 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
index 835c61686..fa3279eed 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
@@ -391,9 +391,8 @@ public class BlameInformationControl extends AbstractInformationControl
revision.getCommit(), parent, reader);
if (diffEntry != null) {
FileDiff fileDiff = new FileDiff(revision.getRepository(),
- revision.getCommit(),
- diffEntry);
- document.setDefault(revision.getRepository(), fileDiff);
+ revision.getCommit(), diffEntry);
+ document.setDefault(fileDiff);
}
}
document.connect(diffFormatter);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java
index 39c46af07..7234437ec 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java
@@ -21,6 +21,7 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
@@ -56,8 +57,6 @@ public class DiffDocument extends Document {
private Pattern oldPathPattern;
- private Repository defaultRepository;
-
private FileDiff defaultFileDiff;
private int[] maximumLineNumbers;
@@ -92,10 +91,12 @@ public class DiffDocument extends Document {
public void connect(DiffRegionFormatter formatter) {
regions = formatter.getRegions();
fileRegions = formatter.getFileRegions();
- if ((fileRegions == null || fileRegions.length == 0)
- && defaultRepository != null && defaultFileDiff != null) {
- fileRegions = new FileDiffRegion[] { new FileDiffRegion(
- defaultRepository, defaultFileDiff, 0, getLength()) };
+ if (fileRegions == null || fileRegions.length == 0) {
+ FileDiff implicitFileDiff = defaultFileDiff;
+ if (implicitFileDiff != null) {
+ fileRegions = new FileDiffRegion[] {
+ new FileDiffRegion(implicitFileDiff, 0, getLength()) };
+ }
}
newPathPattern = Pattern.compile(
Pattern.quote(formatter.getNewPrefix()) + "\\S+"); //$NON-NLS-1$
@@ -122,13 +123,10 @@ public class DiffDocument extends Document {
* a connected {@link DiffRegionFormatter}. Useful if the document is
* used for only individual edits from a file.
*
- * @param repository
- * to use if none set explicitly
* @param fileDiff
* to use if none set explicitly
*/
- public void setDefault(Repository repository, FileDiff fileDiff) {
- defaultRepository = repository;
+ public void setDefault(@NonNull FileDiff fileDiff) {
defaultFileDiff = fileDiff;
}
@@ -166,7 +164,7 @@ public class DiffDocument extends Document {
}
FileDiffRegion findFileRegion(int offset) {
- FileDiffRegion key = new FileDiffRegion(null, null, offset, 0);
+ Region key = new Region(offset, 0);
int i = Arrays.binarySearch(fileRegions, key, (a, b) -> {
if (!TextUtilities.overlaps(a, b)) {
return a.getOffset() - b.getOffset();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
index b89ca7008..84c636318 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
@@ -178,8 +178,8 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
.equals(DiffEntry.ChangeType.ADD))
.collect(Collectors.toList());
Collection<FileDiffRegion> existing = haveNew.stream()
- .filter(diff -> new Path(diff.getRepository().getWorkTree()
- .getAbsolutePath())
+ .filter(diff -> new Path(diff.getDiff().getRepository()
+ .getWorkTree().getAbsolutePath())
.append(diff.getDiff().getNewPath())
.toFile().exists())
.collect(Collectors.toList());
@@ -190,10 +190,12 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
@Override
public void run() {
for (FileDiffRegion fileDiff : existing) {
- File file = new Path(fileDiff.getRepository()
- .getWorkTree().getAbsolutePath()).append(
- fileDiff.getDiff().getNewPath())
- .toFile();
+ File file = new Path(
+ fileDiff.getDiff().getRepository()
+ .getWorkTree().getAbsolutePath())
+ .append(fileDiff.getDiff()
+ .getNewPath())
+ .toFile();
DiffViewer.openFileInEditor(file, -1);
}
}
@@ -206,8 +208,8 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
@Override
public void run() {
for (FileDiffRegion fileDiff : haveNew) {
- DiffViewer.openInEditor(fileDiff.getRepository(),
- fileDiff.getDiff(), DiffEntry.Side.NEW, -1);
+ DiffViewer.openInEditor(fileDiff.getDiff(),
+ DiffEntry.Side.NEW, -1);
}
}
});
@@ -219,8 +221,8 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
@Override
public void run() {
for (FileDiffRegion fileDiff : haveOld) {
- DiffViewer.openInEditor(fileDiff.getRepository(),
- fileDiff.getDiff(), DiffEntry.Side.OLD, -1);
+ DiffViewer.openInEditor(fileDiff.getDiff(),
+ DiffEntry.Side.OLD, -1);
}
}
});
@@ -235,9 +237,7 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
public void run() {
FileDiffRegion fileDiff = selected.iterator()
.next();
- DiffViewer.showTwoWayFileDiff(
- fileDiff.getRepository(),
- fileDiff.getDiff());
+ DiffViewer.showTwoWayFileDiff(fileDiff.getDiff());
}
});
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
index cc3f9ccb0..a44143a29 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
@@ -67,7 +67,6 @@ import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB;
@@ -587,14 +586,13 @@ public class DiffEditorPage extends TextEditor
document)) {
SubMonitor progress = SubMonitor.convert(monitor,
diffs.length);
- Repository repository = commit.getRepository();
for (FileDiff diff : diffs) {
if (progress.isCanceled()) {
break;
}
progress.subTask(diff.getPath());
try {
- formatter.write(repository, diff);
+ formatter.write(diff);
} catch (IOException ignore) {
// Ignored
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
index 82b27b9d3..f1eae81d4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffRegionFormatter.java
@@ -141,20 +141,15 @@ public class DiffRegionFormatter extends DiffFormatter {
}
/**
- * Region giving access to the {@link FileDiff} and its {@link Repository}
- * that generated the content.
+ * Region giving access to the {@link FileDiff} that generated the content.
*/
public static class FileDiffRegion extends Region {
- private final FileDiff diff;
-
- private final Repository repository;
+ private final @NonNull FileDiff diff;
/**
* Creates a new {@link FileDiffRegion}.
*
- * @param repository
- * the {@link FileDiff} belongs to
* @param fileDiff
* the range belongs to
* @param start
@@ -162,11 +157,10 @@ public class DiffRegionFormatter extends DiffFormatter {
* @param length
* of the range
*/
- public FileDiffRegion(Repository repository, FileDiff fileDiff,
+ public FileDiffRegion(@NonNull FileDiff fileDiff,
int start, int length) {
super(start, length);
this.diff = fileDiff;
- this.repository = repository;
}
/**
@@ -174,19 +168,11 @@ public class DiffRegionFormatter extends DiffFormatter {
*
* @return the {@link FileDiff}
*/
+ @NonNull
public FileDiff getDiff() {
return diff;
}
- /**
- * Retrieves the {@link Repository}.
- *
- * @return the {@link Repository}
- */
- public Repository getRepository() {
- return repository;
- }
-
@Override
public boolean equals(Object object) {
return super.equals(object);
@@ -199,7 +185,7 @@ public class DiffRegionFormatter extends DiffFormatter {
@Override
public String toString() {
- return "[FileDiffRange " + (diff == null ? "null" : diff.getPath()) //$NON-NLS-1$ //$NON-NLS-2$
+ return "[FileDiffRange " + diff.getPath() //$NON-NLS-1$
+ ' ' + super.toString() + ']';
}
}
@@ -305,21 +291,19 @@ public class DiffRegionFormatter extends DiffFormatter {
/**
* Write diff
*
- * @param repository
* @param diff
* @return this formatter
* @throws IOException
*/
- public DiffRegionFormatter write(Repository repository, FileDiff diff)
+ public DiffRegionFormatter write(FileDiff diff)
throws IOException {
+ Repository repository = diff.getRepository();
this.stream.charset = CompareCoreUtils.getResourceEncoding(repository,
diff.getPath());
int start = stream.offset;
diff.outputDiff(null, repository, this, true);
flush();
- fileRegions
- .add(new FileDiffRegion(repository, diff, start,
- stream.offset - start));
+ fileRegions.add(new FileDiffRegion(diff, start, stream.offset - start));
return this;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
index f758e60bd..4950ebb48 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
@@ -563,7 +563,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
m.end() - m.start());
if (TextUtilities.overlaps(region, linkRegion)) {
if (side == DiffEntry.Side.NEW) {
- File file = new Path(fileRange.getRepository()
+ File file = new Path(fileRange.getDiff().getRepository()
.getWorkTree().getAbsolutePath()).append(
fileRange.getDiff().getNewPath())
.toFile();
@@ -602,7 +602,8 @@ public class DiffViewer extends HyperlinkSourceViewer {
links.add(
new CompareLink(linkRegion, fileRange, lineNo));
}
- File file = new Path(fileRange.getRepository().getWorkTree()
+ File file = new Path(
+ fileRange.getDiff().getRepository().getWorkTree()
.getAbsolutePath())
.append(fileRange.getDiff().getNewPath())
.toFile();
@@ -667,14 +668,11 @@ public class DiffViewer extends HyperlinkSourceViewer {
private static class CompareLink extends RevealLink {
- protected final Repository repository;
-
protected final FileDiff fileDiff;
public CompareLink(IRegion region, FileDiffRegion fileRange,
int lineNo) {
super(region, lineNo);
- this.repository = fileRange.getRepository();
this.fileDiff = fileRange.getDiff();
}
@@ -687,7 +685,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
public void open() {
// No way to selectAndReveal a line or a diff node in a
// CompareEditor?
- showTwoWayFileDiff(repository, fileDiff);
+ showTwoWayFileDiff(fileDiff);
}
}
@@ -714,7 +712,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
@Override
public void open() {
- openInEditor(repository, fileDiff, side, lineNo);
+ openInEditor(fileDiff, side, lineNo);
}
}
@@ -745,8 +743,6 @@ public class DiffViewer extends HyperlinkSourceViewer {
* Opens either the new or the old version of a {@link FileDiff} in an
* editor.
*
- * @param repository
- * the {@link FileDiff} belongs to
* @param d
* the {@link FileDiff}
* @param side
@@ -754,16 +750,17 @@ public class DiffViewer extends HyperlinkSourceViewer {
* @param lineNoToReveal
* if >= 0, select and reveals the given line
*/
- public static void openInEditor(Repository repository, FileDiff d,
- DiffEntry.Side side, int lineNoToReveal) {
+ public static void openInEditor(FileDiff d, DiffEntry.Side side,
+ int lineNoToReveal) {
ObjectId[] blobs = d.getBlobs();
switch (side) {
case OLD:
- openInEditor(repository, d.getOldPath(), d.getCommit().getParent(0),
+ openInEditor(d.getRepository(), d.getOldPath(),
+ d.getCommit().getParent(0),
blobs[0], lineNoToReveal);
break;
default:
- openInEditor(repository, d.getNewPath(), d.getCommit(),
+ openInEditor(d.getRepository(), d.getNewPath(), d.getCommit(),
blobs[blobs.length - 1], lineNoToReveal);
break;
}
@@ -796,12 +793,10 @@ public class DiffViewer extends HyperlinkSourceViewer {
* Shows a two-way diff between the old and new versions of a
* {@link FileDiff} in a compare editor.
*
- * @param repository
- * the {@link FileDiff} belongs to
* @param d
* the {@link FileDiff} to show
*/
- public static void showTwoWayFileDiff(Repository repository, FileDiff d) {
+ public static void showTwoWayFileDiff(FileDiff d) {
String np = d.getNewPath();
String op = d.getOldPath();
RevCommit c = d.getCommit();
@@ -831,6 +826,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
+ Repository repository = d.getRepository();
if (oldCommit != null && newCommit != null && repository != null) {
IFile file = np != null
? ResourceUtil.getFileForLocation(repository, np, false)
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
index 0a97359f4..63120ae91 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
@@ -432,11 +432,11 @@ public class CommitFileDiffViewer extends TableViewer {
}
private void openThisVersionInEditor(FileDiff d) {
- DiffViewer.openInEditor(d.getRepository(), d, DiffEntry.Side.NEW, -1);
+ DiffViewer.openInEditor(d, DiffEntry.Side.NEW, -1);
}
private void openPreviousVersionInEditor(FileDiff d) {
- DiffViewer.openInEditor(d.getRepository(), d, DiffEntry.Side.OLD, -1);
+ DiffViewer.openInEditor(d, DiffEntry.Side.OLD, -1);
}
private void showAnnotations(FileDiff d) {
@@ -470,7 +470,7 @@ public class CommitFileDiffViewer extends TableViewer {
void showTwoWayFileDiff(final FileDiff d) {
if (d.getBlobs().length <= 2) {
- DiffViewer.showTwoWayFileDiff(d.getRepository(), d);
+ DiffViewer.showTwoWayFileDiff(d);
} else {
MessageDialog.openInformation(
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 7265f7e0e..581456fde 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -2516,7 +2516,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
progress.subTask(diff.getPath());
try {
- formatter.write(diff.getRepository(), diff);
+ formatter.write(diff);
} catch (IOException ignore) {
// Ignored
}