summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-09-25 17:48:02 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2015-09-25 17:48:04 -0400
commit6715c36100d097d39e303fe2fbc4c62412c46a4a (patch)
tree3ee002161b450ada85e123fe01662617c84f7f77
parent97ef1fe89369422ca430b47e0b53277b94bfbc29 (diff)
parenta28ba3f2c7e0fa96f778c62813734807c99c61c3 (diff)
downloadjgit-6715c36100d097d39e303fe2fbc4c62412c46a4a.tar.gz
jgit-6715c36100d097d39e303fe2fbc4c62412c46a4a.zip
Merge "Show submodule difference as a hunk"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java33
2 files changed, 16 insertions, 22 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
index 02e485d41e..24b0f8141e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
@@ -241,8 +241,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
ObjectId bId = blob("b\n");
String diffHeader = makeDiffHeaderModeChange(PATH_A, PATH_A, aId, bId,
- GITLINK, REGULAR_FILE)
- + "-Subproject commit " + aId.name() + "\n";
+ GITLINK, REGULAR_FILE);
DiffEntry ad = DiffEntry.delete(PATH_A, aId);
ad.oldMode = FileMode.GITLINK;
@@ -257,7 +256,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(1, fh.getHunks().size());
HunkHeader hh = fh.getHunks().get(0);
- assertEquals(0, hh.toEditList().size());
+ assertEquals(1, hh.toEditList().size());
}
@Test
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index bcc30c35b4..15abcda561 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -665,16 +665,10 @@ public class DiffFormatter implements AutoCloseable {
format(res.header, res.a, res.b);
}
- private static void writeGitLinkDiffText(OutputStream o, DiffEntry ent)
- throws IOException {
- if (ent.getOldMode() == GITLINK) {
- o.write(encodeASCII("-Subproject commit " + ent.getOldId().name() //$NON-NLS-1$
- + "\n")); //$NON-NLS-1$
- }
- if (ent.getNewMode() == GITLINK) {
- o.write(encodeASCII("+Subproject commit " + ent.getNewId().name() //$NON-NLS-1$
- + "\n")); //$NON-NLS-1$
- }
+ private static byte[] writeGitLinkText(AbbreviatedObjectId id)
+ throws IOException {
+ return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
+ + "\n");
}
private String format(AbbreviatedObjectId id) {
@@ -938,13 +932,7 @@ public class DiffFormatter implements AutoCloseable {
formatHeader(buf, ent);
- if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
- formatOldNewPaths(buf, ent);
- writeGitLinkDiffText(buf, ent);
- editList = new EditList();
- type = PatchType.UNIFIED;
-
- } else if (ent.getOldId() == null || ent.getNewId() == null) {
+ if (ent.getOldId() == null || ent.getNewId() == null) {
// Content not changed (e.g. only mode, pure rename)
editList = new EditList();
type = PatchType.UNIFIED;
@@ -952,8 +940,15 @@ public class DiffFormatter implements AutoCloseable {
} else {
assertHaveRepository();
- byte[] aRaw = open(OLD, ent);
- byte[] bRaw = open(NEW, ent);
+ byte[] aRaw, bRaw;
+
+ if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
+ aRaw = writeGitLinkText(ent.getOldId());
+ bRaw = writeGitLinkText(ent.getNewId());
+ } else {
+ aRaw = open(OLD, ent);
+ bRaw = open(NEW, ent);
+ }
if (aRaw == BINARY || bRaw == BINARY //
|| RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {