Browse Source

Show notes in Log CLI command - Part 2

This change fixes issues identified in the commit
5f3d577e5a.

Change-Id: Idbd935f5f60ad043faa0d4982b3e101ef7c07d60
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
tags/v0.12.1
Sasa Zivkov 13 years ago
parent
commit
3e1a5081d6

+ 1
- 0
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties View File

notAnIndexFile={0} is not an index file notAnIndexFile={0} is not an index file
notAnObject={0} is not an object notAnObject={0} is not an object
notFound=!! NOT FOUND !! notFound=!! NOT FOUND !!
noteObjectTooLargeToPrint=Note object {0} too large to print
onlyOneMetaVarExpectedIn=Only one {0} expected in {1}. onlyOneMetaVarExpectedIn=Only one {0} expected in {1}.
pushTo=To {0} pushTo=To {0}
remoteMessage=remote: {0} remoteMessage=remote: {0}

+ 1
- 0
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java View File

/***/ public String notAnIndexFile; /***/ public String notAnIndexFile;
/***/ public String notAnObject; /***/ public String notAnObject;
/***/ public String notFound; /***/ public String notFound;
/***/ public String noteObjectTooLargeToPrint;
/***/ public String onlyOneMetaVarExpectedIn; /***/ public String onlyOneMetaVarExpectedIn;
/***/ public String pushTo; /***/ public String pushTo;
/***/ public String remoteMessage; /***/ public String remoteMessage;

+ 26
- 36
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java View File

import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.diff.RenameDetector;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.notes.NoteMap; import org.eclipse.jgit.notes.NoteMap;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;


@Command(common = true, usage = "usage_viewCommitHistory") @Command(common = true, usage = "usage_viewCommitHistory")


private Map<String, NoteMap> noteMaps; private Map<String, NoteMap> noteMaps;


private ObjectReader reader;

private RevWalk revWalk;

@Option(name="--decorate", usage="usage_showRefNamesMatchingCommits") @Option(name="--decorate", usage="usage_showRefNamesMatchingCommits")
private boolean decorate; private boolean decorate;


fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US); fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US);
} }


@Override
protected RevWalk createWalk() {
RevWalk ret = super.createWalk();
if (decorate)
allRefsByPeeledObjectId = getRepository().getAllRefsByPeeledObjectId();
return ret;
}

@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
diffFmt.setRepository(db); diffFmt.setRepository(db);
rd.setRenameLimit(renameLimit.intValue()); 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>(); noteMaps = new LinkedHashMap<String, NoteMap>();
if (!noStandardNotes) { 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) { for (String notesRef : additionalNoteRefs) {
if (!notesRef.startsWith(Constants.R_NOTES)) { if (!notesRef.startsWith(Constants.R_NOTES)) {
notesRef = Constants.R_NOTES + notesRef; notesRef = Constants.R_NOTES + notesRef;
} }
noteMaps.put(notesRef, getNoteMap(notesRef));
addNoteMap(notesRef);
} }
} }
} }


if (decorate)
allRefsByPeeledObjectId = getRepository()
.getAllRefsByPeeledObjectId();

super.run(); super.run();
} finally { } finally {
diffFmt.release(); 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); Ref notes = db.getRef(notesRef);
if (notes == null) 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 @Override
} }
boolean printedNote = showNotes(c, e.getValue(), label, boolean printedNote = showNotes(c, e.getValue(), label,
printEmptyLine); printEmptyLine);
atLeastOnePrinted = atLeastOnePrinted || printedNote;
atLeastOnePrinted |= printedNote;
printEmptyLine = printedNote; printEmptyLine = printedNote;
} }
return atLeastOnePrinted; return atLeastOnePrinted;
out.print(")"); out.print(")");
} }
out.println(":"); 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; return true;
} }

+ 1
- 3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java View File

} }


protected RevWalk createWalk() { protected RevWalk createWalk() {
if (objects)
return new ObjectWalk(db);
if (argWalk == null) if (argWalk == null)
argWalk = new RevWalk(db);
argWalk = objects ? new ObjectWalk(db) : new RevWalk(db);
return argWalk; return argWalk;
} }



Loading…
Cancel
Save