private final Statistics stats;
+ private final MutableState state;
+
private Statistics.ObjectType typeStats;
private List<ObjectToPack> sortedByName;
reuseDeltas = config.isReuseDeltas();
reuseValidate = true; // be paranoid by default
stats = new Statistics();
+ state = new MutableState();
}
/**
return sortedByName;
}
+ private void beginPhase(PackingPhase phase, ProgressMonitor monitor,
+ int cnt) {
+ state.phase = phase;
+ String task;
+ switch (phase) {
+ case COUNTING:
+ task = JGitText.get().countingObjects;
+ break;
+ case GETTING_SIZES:
+ task = JGitText.get().searchForSizes;
+ break;
+ case FINDING_SOURCES:
+ task = JGitText.get().searchForReuse;
+ break;
+ case COMPRESSING:
+ task = JGitText.get().compressingObjects;
+ break;
+ case WRITING:
+ task = JGitText.get().writingObjects;
+ break;
+ default:
+ throw new IllegalArgumentException(
+ MessageFormat.format(JGitText.get().illegalPackingPhase, phase));
+ }
+ monitor.beginTask(task, cnt);
+ }
+
+ private void endPhase(ProgressMonitor monitor) {
+ monitor.endTask();
+ }
+
/**
* Write the prepared pack to the supplied stream.
* <p>
long objCnt = getObjectCount();
stats.totalObjects = objCnt;
- writeMonitor.beginTask(JGitText.get().writingObjects, (int) objCnt);
+ beginPhase(PackingPhase.WRITING, writeMonitor, (int) objCnt);
long writeStart = System.currentTimeMillis();
out.writeFileHeader(PACK_VERSION_GENERATED, objCnt);
}
reader.release();
- writeMonitor.endTask();
+ endPhase(writeMonitor);
}
/**
return stats;
}
+ /** @return snapshot of the current state of this PackWriter. */
+ public State getState() {
+ return state.snapshot();
+ }
+
/** Release all resources used by this writer. */
public void release() {
reader.release();
cnt += objectsLists[Constants.OBJ_TAG].size();
long start = System.currentTimeMillis();
- monitor.beginTask(JGitText.get().searchForReuse, cnt);
+ beginPhase(PackingPhase.FINDING_SOURCES, monitor, cnt);
if (cnt <= 4096) {
// For small object counts, do everything as one list.
searchForReuse(monitor, objectsLists[Constants.OBJ_TAG]);
}
- monitor.endTask();
+ endPhase(monitor);
stats.timeSearchingForReuse = System.currentTimeMillis() - start;
}
// abort with an exception if we actually had to have it.
//
final long sizingStart = System.currentTimeMillis();
- monitor.beginTask(JGitText.get().searchForSizes, cnt);
+ beginPhase(PackingPhase.GETTING_SIZES, monitor, cnt);
AsyncObjectSizeQueue<ObjectToPack> sizeQueue = reader.getObjectSize(
Arrays.<ObjectToPack> asList(list).subList(0, cnt), false);
try {
} finally {
sizeQueue.release();
}
- monitor.endTask();
+ endPhase(monitor);
stats.timeSearchingForSizes = System.currentTimeMillis() - sizingStart;
// Sort the objects by path hash so like files are near each other,
return;
final long searchStart = System.currentTimeMillis();
- monitor.beginTask(JGitText.get().compressingObjects, nonEdgeCnt);
+ beginPhase(PackingPhase.COMPRESSING, monitor, nonEdgeCnt);
searchForDeltas(monitor, list, cnt);
- monitor.endTask();
+ endPhase(monitor);
stats.deltaSearchNonEdgeObjects = nonEdgeCnt;
stats.timeCompressing = System.currentTimeMillis() - searchStart;
throws MissingObjectException, IOException,
IncorrectObjectTypeException {
final long countingStart = System.currentTimeMillis();
- countingMonitor.beginTask(JGitText.get().countingObjects,
- ProgressMonitor.UNKNOWN);
+ beginPhase(PackingPhase.COUNTING, countingMonitor, ProgressMonitor.UNKNOWN);
if (have == null)
have = Collections.emptySet();
cachedPacks.addAll(shortCircuit);
for (CachedPack pack : shortCircuit)
countingMonitor.update((int) pack.getObjectCount());
- countingMonitor.endTask();
+ endPhase(countingMonitor);
stats.timeCounting = System.currentTimeMillis() - countingStart;
return;
}
wantObjs, haveObjs, pack);
commits = new BlockList<RevCommit>();
- countingMonitor.endTask();
- countingMonitor.beginTask(JGitText.get().countingObjects,
+ endPhase(countingMonitor);
+ beginPhase(PackingPhase.COUNTING, countingMonitor,
ProgressMonitor.UNKNOWN);
continue;
}
for (CachedPack pack : cachedPacks)
countingMonitor.update((int) pack.getObjectCount());
- countingMonitor.endTask();
+ endPhase(countingMonitor);
stats.timeCounting = System.currentTimeMillis() - countingStart;
}
reusedObjects, reusedDeltas);
}
}
+
+ private class MutableState {
+ private volatile PackingPhase phase;
+
+ MutableState() {
+ phase = PackingPhase.COUNTING;
+ }
+
+ State snapshot() {
+ return new State(phase);
+ }
+ }
+
+ /** Possible states that a PackWriter can be in. */
+ public static enum PackingPhase {
+ /** Counting objects phase. */
+ COUNTING,
+
+ /** Getting sizes phase. */
+ GETTING_SIZES,
+
+ /** Finding sources phase. */
+ FINDING_SOURCES,
+
+ /** Compressing objects phase. */
+ COMPRESSING,
+
+ /** Writing objects phase. */
+ WRITING;
+ }
+
+ /** Summary of the current state of a PackWriter. */
+ public class State {
+ private final PackingPhase phase;
+
+ State(PackingPhase phase) {
+ this.phase = phase;
+ }
+
+ /** @return the PackConfig used to build the writer. */
+ public PackConfig getConfig() {
+ return config;
+ }
+
+ /** @return the current phase of the writer. */
+ public PackingPhase getPhase() {
+ return phase;
+ }
+
+ @Override
+ public String toString() {
+ return "PackWriter.State[" + phase + "]";
+ }
+ }
}