comparison src/org/tmatesoft/hg/repo/ext/MqManager.java @ 501:d2f6ab541330

Change the way extensions are accessed (with ExtensionsManager now), add preliminary Rebase extension support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 29 Oct 2012 19:04:13 +0100
parents ba36f66c32b4
children 507602cb4fb3
comparison
equal deleted inserted replaced
500:465316bf97e8 501:d2f6ab541330
28 import java.util.Map; 28 import java.util.Map;
29 29
30 import org.tmatesoft.hg.core.Nodeid; 30 import org.tmatesoft.hg.core.Nodeid;
31 import org.tmatesoft.hg.internal.Internals; 31 import org.tmatesoft.hg.internal.Internals;
32 import org.tmatesoft.hg.internal.LineReader; 32 import org.tmatesoft.hg.internal.LineReader;
33 import org.tmatesoft.hg.repo.HgInternals;
34 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 33 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
35 import org.tmatesoft.hg.repo.HgInvalidFileException; 34 import org.tmatesoft.hg.repo.HgInvalidFileException;
36 import org.tmatesoft.hg.repo.HgRepository;
37 import org.tmatesoft.hg.util.LogFacility; 35 import org.tmatesoft.hg.util.LogFacility;
38 import org.tmatesoft.hg.util.Path; 36 import org.tmatesoft.hg.util.Path;
39 37
40 /** 38 /**
41 * Mercurial Queues Support. 39 * Mercurial Queues Support.
42 * Access to MqExtension functionality. 40 * Access to MqExtension functionality.
43 * 41 *
42 * FIXME check we don't hold any mq files for too long, close them, use
43 * the same lock mechanism as mq does (if any). Check if MQ uses Mercurial's store lock
44 *
45 * @since 1.1
44 * @author Artem Tikhomirov 46 * @author Artem Tikhomirov
45 * @author TMate Software Ltd. 47 * @author TMate Software Ltd.
46 */ 48 */
47 public class MqManager { 49 public class MqManager {
48 50
49 private static final String PATCHES_DIR = "patches"; 51 private static final String PATCHES_DIR = "patches";
50 52
51 private final HgRepository repo; 53 private final Internals repo;
52 private List<PatchRecord> applied = Collections.emptyList(); 54 private List<PatchRecord> applied = Collections.emptyList();
53 private List<PatchRecord> allKnown = Collections.emptyList(); 55 private List<PatchRecord> allKnown = Collections.emptyList();
54 private List<String> queueNames = Collections.emptyList(); 56 private List<String> queueNames = Collections.emptyList();
55 private String activeQueue = PATCHES_DIR; 57 private String activeQueue = PATCHES_DIR;
56 58
57 public MqManager(HgRepository hgRepo) { 59 /*package-local*/ MqManager(Internals internalRepo) {
58 repo = hgRepo; 60 repo = internalRepo;
59 } 61 }
60 62
61 /** 63 /**
62 * Updates manager with up-to-date state of the mercurial queues. 64 * Updates manager with up-to-date state of the mercurial queues.
63 */ 65 * @return <code>this</code> for convenience
64 public void refresh() throws HgInvalidControlFileException { 66 */
67 public MqManager refresh() throws HgInvalidControlFileException {
65 applied = allKnown = Collections.emptyList(); 68 applied = allKnown = Collections.emptyList();
66 queueNames = Collections.emptyList(); 69 queueNames = Collections.emptyList();
67 Internals repoImpl = HgInternals.getImplementationRepo(repo);
68 final LogFacility log = repo.getSessionContext().getLog(); 70 final LogFacility log = repo.getSessionContext().getLog();
69 try { 71 try {
70 File queues = repoImpl.getFileFromRepoDir("patches.queues"); 72 File queues = repo.getFileFromRepoDir("patches.queues");
71 if (queues.isFile()) { 73 if (queues.isFile()) {
72 LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true); 74 LineReader lr = new LineReader(queues, log).trimLines(true).skipEmpty(true);
73 lr.read(new LineReader.SimpleLineCollector(), queueNames = new LinkedList<String>()); 75 lr.read(new LineReader.SimpleLineCollector(), queueNames = new LinkedList<String>());
74 } 76 }
75 final String queueLocation; // path under .hg to patch queue information (status, series and diff files) 77 final String queueLocation; // path under .hg to patch queue information (status, series and diff files)
76 File activeQueueFile = repoImpl.getFileFromRepoDir("patches.queue"); 78 File activeQueueFile = repo.getFileFromRepoDir("patches.queue");
77 // file is there only if it's not default queue ('patches') that is active 79 // file is there only if it's not default queue ('patches') that is active
78 if (activeQueueFile.isFile()) { 80 if (activeQueueFile.isFile()) {
79 ArrayList<String> contents = new ArrayList<String>(); 81 ArrayList<String> contents = new ArrayList<String>();
80 new LineReader(activeQueueFile, log).read(new LineReader.SimpleLineCollector(), contents); 82 new LineReader(activeQueueFile, log).read(new LineReader.SimpleLineCollector(), contents);
81 if (contents.isEmpty()) { 83 if (contents.isEmpty()) {
98 sb.append(queueLocation); 100 sb.append(queueLocation);
99 sb.append(p); 101 sb.append(p);
100 return Path.create(sb); 102 return Path.create(sb);
101 } 103 }
102 }; 104 };
103 final File fileStatus = repoImpl.getFileFromRepoDir(queueLocation + "status"); 105 final File fileStatus = repo.getFileFromRepoDir(queueLocation + "status");
104 final File fileSeries = repoImpl.getFileFromRepoDir(queueLocation + "series"); 106 final File fileSeries = repo.getFileFromRepoDir(queueLocation + "series");
105 if (fileStatus.isFile()) { 107 if (fileStatus.isFile()) {
106 new LineReader(fileStatus, log).read(new LineReader.LineConsumer<List<PatchRecord>>() { 108 new LineReader(fileStatus, log).read(new LineReader.LineConsumer<List<PatchRecord>>() {
107 109
108 public boolean consume(String line, List<PatchRecord> result) throws IOException { 110 public boolean consume(String line, List<PatchRecord> result) throws IOException {
109 int sep = line.indexOf(':'); 111 int sep = line.indexOf(':');
138 } catch (HgInvalidFileException ex) { 140 } catch (HgInvalidFileException ex) {
139 HgInvalidControlFileException th = new HgInvalidControlFileException(ex.getMessage(), ex.getCause(), ex.getFile()); 141 HgInvalidControlFileException th = new HgInvalidControlFileException(ex.getMessage(), ex.getCause(), ex.getFile());
140 th.setStackTrace(ex.getStackTrace()); 142 th.setStackTrace(ex.getStackTrace());
141 throw th; 143 throw th;
142 } 144 }
145 return this;
143 } 146 }
144 147
145 /** 148 /**
146 * Number of patches not yet applied 149 * Number of patches not yet applied
147 * @return positive value when there are 150 * @return positive value when there are