annotate src/org/tmatesoft/hg/repo/ext/MqManager.java @ 464:1a3c18d57a8e smartgit3

MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 21 Jun 2012 20:27:58 +0200
parents a0507a9f3da0
children 2078692eeb58
rev   line source
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012 TMate Software Ltd
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.repo.ext;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.BufferedReader;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.File;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.FileReader;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.IOException;
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
23 import java.util.ArrayList;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
24 import java.util.Collection;
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.Collections;
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
26 import java.util.HashMap;
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.LinkedList;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.List;
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
29 import java.util.Map;
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.core.HgInvalidControlFileException;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import org.tmatesoft.hg.core.HgInvalidFileException;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.core.Nodeid;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.repo.HgInternals;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import org.tmatesoft.hg.repo.HgRepository;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.util.LogFacility;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.util.Path;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 * Mercurial Queues Support.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 * Access to MqExtension functionality.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author Artem Tikhomirov
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author TMate Software Ltd.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public class MqManager {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 private final HgRepository repo;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 private List<PatchRecord> applied = Collections.emptyList();
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 private List<PatchRecord> allKnown = Collections.emptyList();
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
51 private List<String> queueNames = Collections.emptyList();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
52 private String activeQueue = "patches";
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public MqManager(HgRepository hgRepo) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 repo = hgRepo;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 * Updates manager with up-to-date state of the mercurial queues.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 public void refresh() throws HgInvalidControlFileException {
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
62 applied = allKnown = Collections.emptyList();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
63 queueNames = Collections.emptyList();
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 File repoDir = HgInternals.getRepositoryDir(repo);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 final LogFacility log = HgInternals.getContext(repo).getLog();
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 final File fileStatus = new File(repoDir, "patches/status");
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 final File fileSeries = new File(repoDir, "patches/series");
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 try {
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
69 File queues = new File(repoDir, "patches.queues");
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
70 if (queues.isFile()) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
71 LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
72 lr.read(new SimpleLineCollector(), queueNames = new LinkedList<String>());
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
73 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
74 File activeQueueFile = new File(repoDir, "patches.queue");
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
75 ArrayList<String> contents = new ArrayList<String>();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
76 if (activeQueueFile.isFile()) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
77 new LineReader(activeQueueFile, log).read(new SimpleLineCollector(), contents);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
78 if (contents.isEmpty()) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
79 log.warn(getClass(), "File %s with active queue name is empty", activeQueueFile.getName());
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
80 activeQueue = "patches";
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
81 } else {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
82 activeQueue = contents.get(0);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
83 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
84 } else {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
85 activeQueue = "patches";
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
86 }
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 if (fileStatus.isFile()) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 new LineReader(fileStatus, log).read(new LineConsumer<List<PatchRecord>>() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 public boolean consume(String line, List<PatchRecord> result) throws IOException {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 int sep = line.indexOf(':');
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 if (sep == -1) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 log.warn(MqManager.class, "Bad line in %s:%s", fileStatus.getPath(), line);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 return true;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 Nodeid nid = Nodeid.fromAscii(line.substring(0, sep));
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 String name = new String(line.substring(sep+1));
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 result.add(new PatchRecord(nid, name, Path.create(".hg/patches/" + name)));
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 return true;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }, applied = new LinkedList<PatchRecord>());
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 if (fileSeries.isFile()) {
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
104 final Map<String,PatchRecord> name2patch = new HashMap<String, PatchRecord>();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
105 for (PatchRecord pr : applied) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
106 name2patch.put(pr.getName(), pr);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
107 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
108 LinkedList<String> knownPatchNames = new LinkedList<String>();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
109 new LineReader(fileSeries, log).read(new SimpleLineCollector(), knownPatchNames);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
110 // XXX read other queues?
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
111 allKnown = new ArrayList<PatchRecord>(knownPatchNames.size());
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
112 for (String name : knownPatchNames) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
113 PatchRecord pr = name2patch.get(name);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
114 if (pr == null) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
115 pr = new PatchRecord(null, name, Path.create(".hg/patches/" + name));
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
117 allKnown.add(pr);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
118 }
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 } catch (HgInvalidFileException ex) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 HgInvalidControlFileException th = new HgInvalidControlFileException(ex.getMessage(), ex.getCause(), ex.getFile());
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 th.setStackTrace(ex.getStackTrace());
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 throw th;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
126
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
127 static class SimpleLineCollector implements LineConsumer<Collection<String>> {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
128
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
129 public boolean consume(String line, Collection<String> result) throws IOException {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
130 result.add(line);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
131 return true;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
132 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
133 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
134
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
135 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
136 * Number of patches not yet applied
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
137 * @return positive value when there are
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
138 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
139 public int getQueueSize() {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
140 return getAllKnownPatches().size() - getAppliedPatches().size();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
141 }
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 * Subset of the patches from the queue that were already applied to the repository
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
145 * <p>Analog of 'hg qapplied'
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 * <p>Clients shall call {@link #refresh()} prior to first use
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 * @return collection of records in no particular order, may be empty if none applied
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 public List<PatchRecord> getAppliedPatches() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 return Collections.unmodifiableList(applied);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 * All of the patches that MQ knows about for this repository
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 * <p>Clients shall call {@link #refresh()} prior to first use
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 * @return collection of records in no particular order, may be empty if there are no patches in the queue
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 public List<PatchRecord> getAllKnownPatches() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 return Collections.unmodifiableList(allKnown);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
164 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
165 * Name of the patch queue <code>hg qqueue --active</code> which is active now.
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
166 * @return patch queue name
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
167 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
168 public String getActiveQueueName() {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
169 return activeQueue;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
170 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
171
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
172 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
173 * Patch queues known in the repository, <code>hg qqueue -l</code> analog.
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
174 * There's at least one patch queue (default one names 'patches'). Only one patch queue at a time is active.
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
175 *
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
176 * @return names of patch queues
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
177 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
178 public List<String> getQueueNames() {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
179 return Collections.unmodifiableList(queueNames);
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
180 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
181
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 public class PatchRecord {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 private final Nodeid nodeid;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 private final String name;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 private final Path location;
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
186
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
187 // hashCode/equals might be useful if cons becomes public
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 PatchRecord(Nodeid revision, String name, Path diffLocation) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 nodeid = revision;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 this.name = name;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 this.location = diffLocation;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 * Identifies changeset of the patch that has been applied to the repository
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 * @return changeset revision or <code>null</code> if this patch is not yet applied
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 public Nodeid getRevision() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 return nodeid;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 * Identifies patch, either based on a user-supplied name (<code>hg qnew <i>patch-name</i></code>) or
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 * an automatically generated name (like <code><i>revisionIndex</i>.diff</code> for imported changesets).
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 * Clients shall not rely on this naming scheme, though.
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 *
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 * @return never <code>null</code>
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 public String getName() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 return name;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 /**
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 * Location of diff file with the patch, relative to repository root
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 * @return path to the patch, never <code>null</code>
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 */
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 public Path getPatchLocation() {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 return location;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 // TODO refine API and extract into separate classes
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 interface LineConsumer<T> {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 // boolean begin(File f, T paramObj) throws IOException;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 boolean consume(String line, T paramObj) throws IOException;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 // boolean end(File f, T paramObj) throws IOException;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 class LineReader {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 private final File file;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 private final LogFacility log;
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
236 private boolean trimLines = true;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
237 private boolean skipEmpty = true;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
238 private String ignoreThatStars = null;
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 LineReader(File f, LogFacility logFacility) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 file = f;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 log = logFacility;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 }
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
244
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
245 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
246 * default: <code>true</code>
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
247 * <code>false</code> to return line as is
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
248 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
249 LineReader trimLines(boolean trim) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
250 trimLines = trim;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
251 return this;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
252 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
253
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
254 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
255 * default: <code>true</code>
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
256 * <code>false</code> to pass empty lines to consumer
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
257 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
258 LineReader skipEmpty(boolean skip) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
259 skipEmpty = skip;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
260 return this;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
261 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
262
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
263 /**
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
264 * default: doesn't skip any line.
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
265 * set e.g. to "#" or "//" to skip lines that start with such prefix
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
266 */
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
267 LineReader ignoreLineComments(String lineStart) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
268 ignoreThatStars = lineStart;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
269 return this;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
270 }
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
272 <T> void read(LineConsumer<T> consumer, T paramObj) throws HgInvalidFileException {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273 BufferedReader statusFileReader = null;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 try {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275 // consumer.begin(file, paramObj);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276 statusFileReader = new BufferedReader(new FileReader(file));
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 String line;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278 boolean ok = true;
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
279 while (ok && (line = statusFileReader.readLine()) != null) {
464
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
280 if (trimLines) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
281 line = line.trim();
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
282 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
283 if (ignoreThatStars != null && line.startsWith(ignoreThatStars)) {
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
284 continue;
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
285 }
1a3c18d57a8e MqManager evolution: same PatchRecord instances, list patch queues, detect active queue
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 463
diff changeset
286 if (!skipEmpty || line.length() > 0) {
463
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
287 ok = consumer.consume(line, paramObj);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290 } catch (IOException ex) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 throw new HgInvalidFileException(ex.getMessage(), ex, file);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292 } finally {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 try {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
294 statusFileReader.close();
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
295 } catch (IOException ex) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 log.warn(MqManager.class, ex, null);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
297 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
298 // try {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299 // consumer.end(file, paramObj);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
300 // } catch (IOException ex) {
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 // log.warn(MqManager.class, ex, null);
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
302 // }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
303 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
304 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
305 }
a0507a9f3da0 Initial support for MqExtension
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
306 }