diff options
author | Sasa Zivkov <sasa.zivkov@sap.com> | 2011-02-24 11:12:06 +0100 |
---|---|---|
committer | Sasa Zivkov <sasa.zivkov@sap.com> | 2011-03-01 09:29:35 +0100 |
commit | 3e1a5081d64795d6980e73dc6b5148ed0f674701 (patch) | |
tree | 01aa319e0821cce3d6548a42f1b97627cccd046c /org.eclipse.jgit.pgm/src | |
parent | 2902c7679bde83075370ff3c05e3dbbc6d637e42 (diff) | |
download | jgit-3e1a5081d64795d6980e73dc6b5148ed0f674701.tar.gz jgit-3e1a5081d64795d6980e73dc6b5148ed0f674701.zip |
Show notes in Log CLI command - Part 2
This change fixes issues identified in the commit
5f3d577e5a1e8f23a2b6ea6a2bf24516806e01b8.
Change-Id: Idbd935f5f60ad043faa0d4982b3e101ef7c07d60
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
3 files changed, 28 insertions, 39 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java index dd0f6dbea6..1c7e936343 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java @@ -130,6 +130,7 @@ public class CLIText extends TranslationBundle { /***/ public String notAnIndexFile; /***/ public String notAnObject; /***/ public String notFound; + /***/ public String noteObjectTooLargeToPrint; /***/ public String onlyOneMetaVarExpectedIn; /***/ public String pushTo; /***/ public String remoteMessage; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index d27793c5be..4a92ea624f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -64,16 +64,15 @@ import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RenameDetector; +import org.eclipse.jgit.errors.LargeObjectException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.notes.NoteMap; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; -import org.eclipse.jgit.revwalk.RevWalk; import org.kohsuke.args4j.Option; @Command(common = true, usage = "usage_viewCommitHistory") @@ -89,10 +88,6 @@ class Log extends RevWalkTextBuiltin { private Map<String, NoteMap> noteMaps; - private ObjectReader reader; - - private RevWalk revWalk; - @Option(name="--decorate", usage="usage_showRefNamesMatchingCommits") private boolean decorate; @@ -183,14 +178,6 @@ class Log extends RevWalkTextBuiltin { } @Override - protected RevWalk createWalk() { - RevWalk ret = super.createWalk(); - if (decorate) - allRefsByPeeledObjectId = getRepository().getAllRefsByPeeledObjectId(); - return ret; - } - - @Override protected void run() throws Exception { diffFmt.setRepository(db); try { @@ -202,40 +189,39 @@ class Log extends RevWalkTextBuiltin { rd.setRenameLimit(renameLimit.intValue()); } - if (!noStandardNotes || additionalNoteRefs != null) { - reader = db.newObjectReader(); - revWalk = new RevWalk(db); + if (!noStandardNotes || !additionalNoteRefs.isEmpty()) { + createWalk(); noteMaps = new LinkedHashMap<String, NoteMap>(); if (!noStandardNotes) { - noteMaps.put(Constants.R_NOTES_COMMITS, - getNoteMap(Constants.R_NOTES_COMMITS)); + addNoteMap(Constants.R_NOTES_COMMITS); } - if (additionalNoteRefs != null) { + if (!additionalNoteRefs.isEmpty()) { for (String notesRef : additionalNoteRefs) { if (!notesRef.startsWith(Constants.R_NOTES)) { notesRef = Constants.R_NOTES + notesRef; } - noteMaps.put(notesRef, getNoteMap(notesRef)); + addNoteMap(notesRef); } } } + if (decorate) + allRefsByPeeledObjectId = getRepository() + .getAllRefsByPeeledObjectId(); + super.run(); } finally { diffFmt.release(); - if (reader != null) - reader.release(); - if (revWalk != null) - revWalk.release(); } } - private NoteMap getNoteMap(String notesRef) throws IOException { + private void addNoteMap(String notesRef) throws IOException { Ref notes = db.getRef(notesRef); if (notes == null) - return null; - RevCommit notesCommit = revWalk.parseCommit(notes.getObjectId()); - return NoteMap.read(reader, notesCommit); + return; + RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId()); + noteMaps.put(notesRef, + NoteMap.read(argWalk.getObjectReader(), notesCommit)); } @Override @@ -304,7 +290,7 @@ class Log extends RevWalkTextBuiltin { } boolean printedNote = showNotes(c, e.getValue(), label, printEmptyLine); - atLeastOnePrinted = atLeastOnePrinted || printedNote; + atLeastOnePrinted |= printedNote; printEmptyLine = printedNote; } return atLeastOnePrinted; @@ -334,12 +320,16 @@ class Log extends RevWalkTextBuiltin { out.print(")"); } out.println(":"); - RawText rawText = new RawText(reader.open(blobId).getBytes()); - String s = rawText.getString(0, rawText.size(), false); - final String[] lines = s.split("\n"); - for (final String l : lines) { - out.print(" "); - out.println(l); + try { + RawText rawText = new RawText(argWalk.getObjectReader() + .open(blobId).getCachedBytes(Integer.MAX_VALUE)); + for (int i = 0; i < rawText.size(); i++) { + out.print(" "); + out.println(rawText.getString(i)); + } + } catch (LargeObjectException e) { + out.println(MessageFormat.format( + CLIText.get().noteObjectTooLargeToPrint, blobId.name())); } return true; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java index 768890c85c..474e974cd1 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java @@ -199,10 +199,8 @@ abstract class RevWalkTextBuiltin extends TextBuiltin { } protected RevWalk createWalk() { - if (objects) - return new ObjectWalk(db); if (argWalk == null) - argWalk = new RevWalk(db); + argWalk = objects ? new ObjectWalk(db) : new RevWalk(db); return argWalk; } |