]> source.dussan.org Git - jgit.git/commitdiff
Format submodule links during differences 52/1052/1
authorShawn O. Pearce <spearce@spearce.org>
Sat, 3 Jul 2010 23:59:06 +0000 (16:59 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 3 Jul 2010 23:59:06 +0000 (16:59 -0700)
Instead of crashing, output a submodule link with the simple
"Subproject commit $fullid\n" syntax used by C Git.

Change-Id: Iae8646941683fb19b73fb038217d2e3bf5f77fa9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

index 00cfe8b0871a88c17a2006b42352e8fd1cecb783..e114b9220949cb245a4e4bcc85c2100c165bf7f8 100644 (file)
@@ -46,6 +46,7 @@ package org.eclipse.jgit.diff;
 
 import static org.eclipse.jgit.lib.Constants.encode;
 import static org.eclipse.jgit.lib.Constants.encodeASCII;
+import static org.eclipse.jgit.lib.FileMode.GITLINK;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -232,16 +233,27 @@ public class DiffFormatter {
                out.write(encode("--- " + oldName + '\n'));
                out.write(encode("+++ " + newName + '\n'));
 
-               byte[] aRaw = open(ent.getOldMode(), ent.getOldId());
-               byte[] bRaw = open(ent.getNewMode(), ent.getNewId());
+               if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
+                       if (ent.getOldMode() == GITLINK) {
+                               out.write(encodeASCII("-Subproject commit "
+                                               + ent.getOldId().name() + "\n"));
+                       }
+                       if (ent.getNewMode() == GITLINK) {
+                               out.write(encodeASCII("+Subproject commit "
+                                               + ent.getNewId().name() + "\n"));
+                       }
+               } else {
+                       byte[] aRaw = open(ent.getOldMode(), ent.getOldId());
+                       byte[] bRaw = open(ent.getNewMode(), ent.getNewId());
 
-               if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
-                       out.write(encodeASCII("Binary files differ\n"));
+                       if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
+                               out.write(encodeASCII("Binary files differ\n"));
 
-               } else {
-                       RawText a = newRawText(aRaw);
-                       RawText b = newRawText(bRaw);
-                       formatEdits(a, b, new MyersDiff(a, b).getEdits());
+                       } else {
+                               RawText a = newRawText(aRaw);
+                               RawText b = newRawText(bRaw);
+                               formatEdits(a, b, new MyersDiff(a, b).getEdits());
+                       }
                }
        }