queueNames = Collections.emptyList();
final LogFacility log = repo.getSessionContext().getLog();
try {
File queues = repo.getFileFromRepoDir("patches.queues");
if (queues.isFile()) {
LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true);
lr.read(new LineReader.SimpleLineCollector(), queueNames = new LinkedList<String>());
}
final String queueLocation; // path under .hg to patch queue information (status, series and diff files)
File activeQueueFile = repo.getFileFromRepoDir("patches.queue");
// file is there only if it's not default queue ('patches') that is active
if (activeQueueFile.isFile()) {
ArrayList<String> contents = new ArrayList<String>();
new LineReader(activeQueueFile, log).read(new LineReader.SimpleLineCollector(), contents);
if (contents.isEmpty()) {
log.dump(getClass(), Warn, "File %s with active queue name is empty", activeQueueFile.getName());
activeQueue = PATCHES_DIR;
queueLocation = PATCHES_DIR + '/';
} else {
activeQueue = contents.get(0);
queueLocation = PATCHES_DIR + '-' + activeQueue + '/';
}
} else {
activeQueue = PATCHES_DIR;
queueLocation = PATCHES_DIR + '/';
}
final Path.Source patchLocation = new Path.Source() {
public Path path(CharSequence p) {
StringBuilder sb = new StringBuilder(64);
sb.append(".hg/");
sb.append(queueLocation);
sb.append(p);
return Path.create(sb);
}
};
final File fileStatus = repo.getFileFromRepoDir(queueLocation + "status");
final File fileSeries = repo.getFileFromRepoDir(queueLocation + "series");
if (fileStatus.isFile()) {
new LineReader(fileStatus, log).read(new LineReader.LineConsumer<List<PatchRecord>>() {
public boolean consume(String line, List<PatchRecord> result) throws IOException {
int sep = line.indexOf(':');
if (sep == -1) {
log.dump(MqManager.class, Warn, "Bad line in %s:%s", fileStatus.getPath(), line);
return true;
}
Nodeid nid = Nodeid.fromAscii(line.substring(0, sep));
String name = new String(line.substring(sep+1));
result.add(new PatchRecord(nid, name, patchLocation.path(name)));
return true;
}
}, applied = new LinkedList<PatchRecord>());
}
if (fileSeries.isFile()) {
final Map<String,PatchRecord> name2patch = new HashMap<String, PatchRecord>();
for (PatchRecord pr : applied) {
name2patch.put(pr.getName(), pr);
}
LinkedList<String> knownPatchNames = new LinkedList<String>();
new LineReader(fileSeries, log).read(new LineReader.SimpleLineCollector(), knownPatchNames);
// XXX read other queues?
allKnown = new ArrayList<PatchRecord>(knownPatchNames.size());
for (String name : knownPatchNames) {
PatchRecord pr = name2patch.get(name);
if (pr == null) {