Format submodule links during differences

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>
This commit is contained in:
Shawn O. Pearce 2010-07-03 16:59:06 -07:00
parent 5be90be996
commit bd8740dc14
1 changed files with 21 additions and 9 deletions

View File

@ -46,6 +46,7 @@
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 @@ private void formatAndDiff(DiffEntry ent) throws IOException {
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 (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
out.write(encodeASCII("Binary files differ\n"));
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 {
RawText a = newRawText(aRaw);
RawText b = newRawText(bRaw);
formatEdits(a, b, new MyersDiff(a, b).getEdits());
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"));
} else {
RawText a = newRawText(aRaw);
RawText b = newRawText(bRaw);
formatEdits(a, b, new MyersDiff(a, b).getEdits());
}
}
}