Merge "Show resolving deltas progress to push clients"

This commit is contained in:
Chris Aniszczyk 2011-02-01 09:40:57 -05:00 committed by Code Review
commit cc5295c4b4
3 changed files with 56 additions and 22 deletions

View File

@ -168,13 +168,14 @@ public PackFile getPackFile() {
} }
@Override @Override
public PackLock parse(ProgressMonitor progress) throws IOException { public PackLock parse(ProgressMonitor receiving, ProgressMonitor resolving)
throws IOException {
tmpPack = File.createTempFile("incoming_", ".pack", db.getDirectory()); tmpPack = File.createTempFile("incoming_", ".pack", db.getDirectory());
tmpIdx = new File(db.getDirectory(), baseName(tmpPack) + ".idx"); tmpIdx = new File(db.getDirectory(), baseName(tmpPack) + ".idx");
try { try {
out = new RandomAccessFile(tmpPack, "rw"); out = new RandomAccessFile(tmpPack, "rw");
super.parse(progress); super.parse(receiving, resolving);
out.seek(packEnd); out.seek(packEnd);
out.write(packHash); out.write(packHash);

View File

@ -406,10 +406,33 @@ public List<PackedObjectInfo> getSortedObjectList(
* @throws IOException * @throws IOException
* the stream is malformed, or contains corrupt objects. * the stream is malformed, or contains corrupt objects.
*/ */
public PackLock parse(ProgressMonitor progress) throws IOException { public final PackLock parse(ProgressMonitor progress) throws IOException {
if (progress == null) return parse(progress, progress);
progress = NullProgressMonitor.INSTANCE; }
progress.start(2 /* tasks */);
/**
* Parse the pack stream.
*
* @param receiving
* receives progress feedback during the initial receiving
* objects phase. If null, {@link NullProgressMonitor} will be
* used.
* @param resolving
* receives progress feedback during the resolving objects phase.
* @return the pack lock, if one was requested by setting
* {@link #setLockMessage(String)}.
* @throws IOException
* the stream is malformed, or contains corrupt objects.
*/
public PackLock parse(ProgressMonitor receiving, ProgressMonitor resolving)
throws IOException {
if (receiving == null)
receiving = NullProgressMonitor.INSTANCE;
if (resolving == null)
resolving = NullProgressMonitor.INSTANCE;
if (receiving == resolving)
receiving.start(2 /* tasks */);
try { try {
readPackHeader(); readPackHeader();
@ -418,21 +441,25 @@ public PackLock parse(ProgressMonitor progress) throws IOException {
baseByPos = new LongMap<UnresolvedDelta>(); baseByPos = new LongMap<UnresolvedDelta>();
deferredCheckBlobs = new ArrayList<PackedObjectInfo>(); deferredCheckBlobs = new ArrayList<PackedObjectInfo>();
progress.beginTask(JGitText.get().receivingObjects, receiving.beginTask(JGitText.get().receivingObjects,
(int) objectCount); (int) objectCount);
for (int done = 0; done < objectCount; done++) { try {
indexOneObject(); for (int done = 0; done < objectCount; done++) {
progress.update(1); indexOneObject();
if (progress.isCancelled()) receiving.update(1);
throw new IOException(JGitText.get().downloadCancelled); if (receiving.isCancelled())
throw new IOException(JGitText.get().downloadCancelled);
}
readPackFooter();
endInput();
} finally {
receiving.endTask();
} }
readPackFooter();
endInput();
if (!deferredCheckBlobs.isEmpty()) if (!deferredCheckBlobs.isEmpty())
doDeferredCheckBlobs(); doDeferredCheckBlobs();
progress.endTask();
if (deltaCount > 0) { if (deltaCount > 0) {
resolveDeltas(progress); resolveDeltas(resolving);
if (entryCount < objectCount) { if (entryCount < objectCount) {
if (!isAllowThin()) { if (!isAllowThin()) {
throw new IOException(MessageFormat.format(JGitText throw new IOException(MessageFormat.format(JGitText
@ -440,7 +467,7 @@ public PackLock parse(ProgressMonitor progress) throws IOException {
(objectCount - entryCount))); (objectCount - entryCount)));
} }
resolveDeltasWithExternalBases(progress); resolveDeltasWithExternalBases(resolving);
if (entryCount < objectCount) { if (entryCount < objectCount) {
throw new IOException(MessageFormat.format(JGitText throw new IOException(MessageFormat.format(JGitText
@ -467,8 +494,6 @@ public PackLock parse(ProgressMonitor progress) throws IOException {
inflater = null; inflater = null;
objectDatabase.close(); objectDatabase.close();
} }
progress.endTask();
} }
return null; // By default there is no locking. return null; // By default there is no locking.
} }

View File

@ -77,6 +77,7 @@
import org.eclipse.jgit.lib.ObjectIdSubclassMap; import org.eclipse.jgit.lib.ObjectIdSubclassMap;
import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -162,6 +163,8 @@ public class ReceivePack {
private Writer msgs; private Writer msgs;
private SideBandOutputStream msgOut;
private PackParser parser; private PackParser parser;
/** The refs we advertised as existing at the start of the connection. */ /** The refs we advertised as existing at the start of the connection. */
@ -758,9 +761,9 @@ private void enableCapabilities() {
OutputStream out = rawOut; OutputStream out = rawOut;
rawOut = new SideBandOutputStream(CH_DATA, MAX_BUF, out); rawOut = new SideBandOutputStream(CH_DATA, MAX_BUF, out);
msgOut = new SideBandOutputStream(CH_PROGRESS, MAX_BUF, out);
pckOut = new PacketLineOut(rawOut); pckOut = new PacketLineOut(rawOut);
msgs = new OutputStreamWriter(new SideBandOutputStream(CH_PROGRESS, msgs = new OutputStreamWriter(msgOut, Constants.CHARSET);
MAX_BUF, out), Constants.CHARSET);
} }
} }
@ -780,6 +783,11 @@ private void receivePack() throws IOException {
if (timeoutIn != null) if (timeoutIn != null)
timeoutIn.setTimeout(10 * timeout * 1000); timeoutIn.setTimeout(10 * timeout * 1000);
ProgressMonitor receiving = NullProgressMonitor.INSTANCE;
ProgressMonitor resolving = NullProgressMonitor.INSTANCE;
if (sideBand)
resolving = new SideBandProgressMonitor(msgOut);
ObjectInserter ins = db.newObjectInserter(); ObjectInserter ins = db.newObjectInserter();
try { try {
String lockMsg = "jgit receive-pack"; String lockMsg = "jgit receive-pack";
@ -792,7 +800,7 @@ private void receivePack() throws IOException {
parser.setNeedBaseObjectIds(checkReferencedIsReachable); parser.setNeedBaseObjectIds(checkReferencedIsReachable);
parser.setObjectChecking(isCheckReceivedObjects()); parser.setObjectChecking(isCheckReceivedObjects());
parser.setLockMessage(lockMsg); parser.setLockMessage(lockMsg);
packLock = parser.parse(NullProgressMonitor.INSTANCE); packLock = parser.parse(receiving, resolving);
ins.flush(); ins.flush();
} finally { } finally {
ins.release(); ins.release();