Explorar el Código

Show notes in Log CLI command

Support for --no-standard-notes and --show-notes=REF options is added
to the Log command. The --show-notes option can be specified more than
once if more than one notes branch should be used for showing notes.

The notes are displayed from note branches in the order how the note
branches are specified in the command line. However, the standard note,
from the refs/notes/commits, is always displayed as first unless
the --no-standard-notes options is given.

Change-Id: I4e7940804ed9d388b625b8e8a8e25bfcf5ee15a6
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
tags/v0.12.1
Sasa Zivkov hace 13 años
padre
commit
5f3d577e5a

+ 1
- 0
org.eclipse.jgit.pgm/META-INF/MANIFEST.MF Ver fichero

org.eclipse.jgit.iplog;version="[0.12.0,0.13.0)", org.eclipse.jgit.iplog;version="[0.12.0,0.13.0)",
org.eclipse.jgit.lib;version="[0.12.0,0.13.0)", org.eclipse.jgit.lib;version="[0.12.0,0.13.0)",
org.eclipse.jgit.nls;version="[0.12.0,0.13.0)", org.eclipse.jgit.nls;version="[0.12.0,0.13.0)",
org.eclipse.jgit.notes;version="[0.12.0,0.13.0)",
org.eclipse.jgit.revplot;version="[0.12.0,0.13.0)", org.eclipse.jgit.revplot;version="[0.12.0,0.13.0)",
org.eclipse.jgit.revwalk;version="[0.12.0,0.13.0)", org.eclipse.jgit.revwalk;version="[0.12.0,0.13.0)",
org.eclipse.jgit.revwalk.filter;version="[0.12.0,0.13.0)", org.eclipse.jgit.revwalk.filter;version="[0.12.0,0.13.0)",

+ 3
- 0
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties Ver fichero

metaVar_path=path metaVar_path=path
metaVar_paths=path ... metaVar_paths=path ...
metaVar_port=PORT metaVar_port=PORT
metaVar_ref=REF
metaVar_refs=REFS metaVar_refs=REFS
metaVar_refspec=refspec metaVar_refspec=refspec
metaVar_remoteName=name metaVar_remoteName=name
usage_nameStatus=show only name and status of files usage_nameStatus=show only name and status of files
usage_noPrefix=do not show any source or destination prefix usage_noPrefix=do not show any source or destination prefix
usage_noRenames=disable rename detection usage_noRenames=disable rename detection
usage_noShowStandardNotes=Disable showing notes from the standard /refs/notes/commits branch
usage_onlyMatchAgainstAlreadyTrackedFiles=Only match <filepattern> against already tracked files in the index rather than the working tree usage_onlyMatchAgainstAlreadyTrackedFiles=Only match <filepattern> against already tracked files in the index rather than the working tree
usage_outputFile=Output file usage_outputFile=Output file
usage_path=path usage_path=path
usage_setTheGitRepositoryToOperateOn=set the git repository to operate on usage_setTheGitRepositoryToOperateOn=set the git repository to operate on
usage_showPatch=display patch usage_showPatch=display patch
usage_showRefNamesMatchingCommits=Show ref names matching commits usage_showRefNamesMatchingCommits=Show ref names matching commits
usage_showNotes=Add this ref to the list of note branches from which notes are displayed
usage_srcPrefix=show the source prefix instead of "a/" usage_srcPrefix=show the source prefix instead of "a/"
usage_symbolicVersionForTheProject=Symbolic version for the project usage_symbolicVersionForTheProject=Symbolic version for the project
usage_synchronizeIPZillaData=Synchronize IPZilla data usage_synchronizeIPZillaData=Synchronize IPZilla data

+ 120
- 0
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java Ver fichero

import java.text.DateFormat; import java.text.DateFormat;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;


import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.DiffFormatter;
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.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.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.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.eclipse.jgit.revwalk.RevWalk;


private Map<AnyObjectId, Set<Ref>> allRefsByPeeledObjectId; private Map<AnyObjectId, Set<Ref>> allRefsByPeeledObjectId;


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;


@Option(name = "--no-standard-notes", usage = "usage_noShowStandardNotes")
private boolean noStandardNotes;

private List<String> additionalNoteRefs = new ArrayList<String>();

@Option(name = "--show-notes", usage = "usage_showNotes", metaVar = "metaVar_ref")
void addAdditionalNoteRef(String notesRef) {
additionalNoteRefs.add(notesRef);
}

// BEGIN -- Options shared with Diff // BEGIN -- Options shared with Diff
@Option(name = "-p", usage = "usage_showPatch") @Option(name = "-p", usage = "usage_showPatch")
boolean showPatch; boolean showPatch;


// END -- Options shared with Diff // END -- Options shared with Diff



Log() { Log() {
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);
} }
rd.setRenameLimit(renameLimit.intValue()); rd.setRenameLimit(renameLimit.intValue());
} }


if (!noStandardNotes || additionalNoteRefs != null) {
reader = db.newObjectReader();
revWalk = new RevWalk(db);
noteMaps = new LinkedHashMap<String, NoteMap>();
if (!noStandardNotes) {
noteMaps.put(Constants.R_NOTES_COMMITS,
getNoteMap(Constants.R_NOTES_COMMITS));
}
if (additionalNoteRefs != null) {
for (String notesRef : additionalNoteRefs) {
if (!notesRef.startsWith(Constants.R_NOTES)) {
notesRef = Constants.R_NOTES + notesRef;
}
noteMaps.put(notesRef, getNoteMap(notesRef));
}
}
}

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 {
Ref notes = db.getRef(notesRef);
if (notes == null)
return null;
RevCommit notesCommit = revWalk.parseCommit(notes.getObjectId());
return NoteMap.read(reader, notesCommit);
}

@Override @Override
protected void show(final RevCommit c) throws Exception { protected void show(final RevCommit c) throws Exception {
out.print(CLIText.get().commitLabel); out.print(CLIText.get().commitLabel);
} }


out.println(); out.println();
if (showNotes(c))
out.println();

if (c.getParentCount() == 1 && (showNameAndStatusOnly || showPatch)) if (c.getParentCount() == 1 && (showNameAndStatusOnly || showPatch))
showDiff(c); showDiff(c);
out.flush(); out.flush();
} }


/**
* @param c
* @return <code>true</code> if at least one note was printed,
* <code>false</code> otherwise
* @throws IOException
*/
private boolean showNotes(RevCommit c) throws IOException {
if (noteMaps == null)
return false;

boolean printEmptyLine = false;
boolean atLeastOnePrinted = false;
for (Map.Entry<String, NoteMap> e : noteMaps.entrySet()) {
String label = null;
String notesRef = e.getKey();
if (! notesRef.equals(Constants.R_NOTES_COMMITS)) {
if (notesRef.startsWith(Constants.R_NOTES))
label = notesRef.substring(Constants.R_NOTES.length());
else
label = notesRef;
}
boolean printedNote = showNotes(c, e.getValue(), label,
printEmptyLine);
atLeastOnePrinted = atLeastOnePrinted || printedNote;
printEmptyLine = printedNote;
}
return atLeastOnePrinted;
}

/**
* @param c
* @param map
* @param label
* @param emptyLine
* @return <code>true</code> if note was printed, <code>false</code>
* otherwise
* @throws IOException
*/
private boolean showNotes(RevCommit c, NoteMap map, String label,
boolean emptyLine)
throws IOException {
ObjectId blobId = map.get(c);
if (blobId == null)
return false;
if (emptyLine)
out.println();
out.print("Notes");
if (label != null) {
out.print(" (");
out.print(label);
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);
}
return true;
}

private void showDiff(RevCommit c) throws IOException { private void showDiff(RevCommit c) throws IOException {
final RevTree a = c.getParent(0).getTree(); final RevTree a = c.getParent(0).getTree();
final RevTree b = c.getTree(); final RevTree b = c.getTree();

+ 6
- 0
org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java Ver fichero

/** Prefix for tag refs */ /** Prefix for tag refs */
public static final String R_TAGS = "refs/tags/"; public static final String R_TAGS = "refs/tags/";


/** Prefix for notes refs */
public static final String R_NOTES = "refs/notes/";

/** Standard notes ref */
public static final String R_NOTES_COMMITS = R_NOTES + "commits";

/** Prefix for any ref */ /** Prefix for any ref */
public static final String R_REFS = "refs/"; public static final String R_REFS = "refs/";



Cargando…
Cancelar
Guardar