Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/StatusCommand.java @ 93:d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 27 Jan 2011 21:15:21 +0100 |
parents | 6f1b88693d48 |
children | af1f3b78b918 |
comparison
equal
deleted
inserted
replaced
92:bf304cb14247 | 93:d55d4eedfc57 |
---|---|
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
21 import static org.tmatesoft.hg.repo.HgRepository.WORKING_COPY; | 21 import static org.tmatesoft.hg.repo.HgRepository.WORKING_COPY; |
22 | 22 |
23 import java.util.ConcurrentModificationException; | |
24 | |
25 import org.tmatesoft.hg.core.LogCommand.FileRevision; | |
23 import org.tmatesoft.hg.core.Path.Matcher; | 26 import org.tmatesoft.hg.core.Path.Matcher; |
24 import org.tmatesoft.hg.repo.HgRepository; | 27 import org.tmatesoft.hg.repo.HgRepository; |
28 import org.tmatesoft.hg.repo.HgStatusInspector; | |
25 import org.tmatesoft.hg.repo.StatusCollector; | 29 import org.tmatesoft.hg.repo.StatusCollector; |
26 import org.tmatesoft.hg.repo.WorkingCopyStatusCollector; | 30 import org.tmatesoft.hg.repo.WorkingCopyStatusCollector; |
27 | 31 |
28 /** | 32 /** |
29 * | 33 * |
31 * @author TMate Software Ltd. | 35 * @author TMate Software Ltd. |
32 */ | 36 */ |
33 public class StatusCommand { | 37 public class StatusCommand { |
34 private final HgRepository repo; | 38 private final HgRepository repo; |
35 | 39 |
36 private boolean needModified; | |
37 private boolean needAdded; | |
38 private boolean needRemoved; | |
39 private boolean needUnknown; | |
40 private boolean needMissing; | |
41 private boolean needClean; | |
42 private boolean needIgnored; | |
43 private Matcher matcher; | |
44 private int startRevision = TIP; | 40 private int startRevision = TIP; |
45 private int endRevision = WORKING_COPY; | 41 private int endRevision = WORKING_COPY; |
46 private boolean visitSubRepo = true; | 42 private boolean visitSubRepo = true; |
43 | |
44 private HgStatusInspector visitor; | |
45 private final Mediator mediator = new Mediator(); | |
47 | 46 |
48 public StatusCommand(HgRepository hgRepo) { | 47 public StatusCommand(HgRepository hgRepo) { |
49 repo = hgRepo; | 48 repo = hgRepo; |
50 defaults(); | 49 defaults(); |
51 } | 50 } |
52 | 51 |
53 public StatusCommand defaults() { | 52 public StatusCommand defaults() { |
54 needModified = needAdded = needRemoved = needUnknown = needMissing = true; | 53 final Mediator m = mediator; |
55 needClean = needIgnored = false; | 54 m.needModified = m.needAdded = m.needRemoved = m.needUnknown = m.needMissing = true; |
55 m.needClean = m.needIgnored = false; | |
56 return this; | 56 return this; |
57 } | 57 } |
58 public StatusCommand all() { | 58 public StatusCommand all() { |
59 needModified = needAdded = needRemoved = needUnknown = needMissing = true; | 59 final Mediator m = mediator; |
60 needClean = needIgnored = true; | 60 m.needModified = m.needAdded = m.needRemoved = m.needUnknown = m.needMissing = true; |
61 m.needClean = m.needIgnored = true; | |
61 return this; | 62 return this; |
62 } | 63 } |
63 | 64 |
64 | 65 |
65 public StatusCommand modified(boolean include) { | 66 public StatusCommand modified(boolean include) { |
66 needModified = include; | 67 mediator.needModified = include; |
67 return this; | 68 return this; |
68 } | 69 } |
69 public StatusCommand added(boolean include) { | 70 public StatusCommand added(boolean include) { |
70 needAdded = include; | 71 mediator.needAdded = include; |
71 return this; | 72 return this; |
72 } | 73 } |
73 public StatusCommand removed(boolean include) { | 74 public StatusCommand removed(boolean include) { |
74 needRemoved = include; | 75 mediator.needRemoved = include; |
75 return this; | 76 return this; |
76 } | 77 } |
77 public StatusCommand deleted(boolean include) { | 78 public StatusCommand deleted(boolean include) { |
78 needMissing = include; | 79 mediator.needMissing = include; |
79 return this; | 80 return this; |
80 } | 81 } |
81 public StatusCommand unknown(boolean include) { | 82 public StatusCommand unknown(boolean include) { |
82 needUnknown = include; | 83 mediator.needUnknown = include; |
83 return this; | 84 return this; |
84 } | 85 } |
85 public StatusCommand clean(boolean include) { | 86 public StatusCommand clean(boolean include) { |
86 needClean = include; | 87 mediator.needClean = include; |
87 return this; | 88 return this; |
88 } | 89 } |
89 public StatusCommand ignored(boolean include) { | 90 public StatusCommand ignored(boolean include) { |
90 needIgnored = include; | 91 mediator.needIgnored = include; |
91 return this; | 92 return this; |
92 } | 93 } |
93 | 94 |
94 /** | 95 /** |
95 * if set, either base:revision or base:workingdir | 96 * if set, either base:revision or base:workingdir |
122 // XXX negative values, except for predefined constants, shall throw IAE. | 123 // XXX negative values, except for predefined constants, shall throw IAE. |
123 endRevision = revision; | 124 endRevision = revision; |
124 return this; | 125 return this; |
125 } | 126 } |
126 | 127 |
128 // pass null to reset | |
127 public StatusCommand match(Path.Matcher pathMatcher) { | 129 public StatusCommand match(Path.Matcher pathMatcher) { |
128 matcher = pathMatcher; | 130 mediator.matcher = pathMatcher; |
129 return this; | 131 throw HgRepository.notImplemented(); |
130 } | 132 } |
131 | 133 |
132 public StatusCommand subrepo(boolean visit) { | 134 public StatusCommand subrepo(boolean visit) { |
133 visitSubRepo = visit; | 135 visitSubRepo = visit; |
134 throw HgRepository.notImplemented(); | 136 throw HgRepository.notImplemented(); |
135 } | 137 } |
136 | 138 |
137 public void execute(StatusCollector.Inspector inspector) { | 139 /** |
140 * Perform status operation according to parameters set. | |
141 * | |
142 * @param handler callback to get status information | |
143 * @throws IllegalArgumentException if handler is <code>null</code> | |
144 * @throws ConcurrentModificationException if this command already runs (i.e. being used from another thread) | |
145 */ | |
146 public void execute(final HgStatusInspector handler) { | |
147 if (handler == null) { | |
148 throw new IllegalArgumentException(); | |
149 } | |
150 if (visitor != null) { | |
151 throw new ConcurrentModificationException(); | |
152 } | |
153 visitor = handler; | |
138 StatusCollector sc = new StatusCollector(repo); // TODO from CommandContext | 154 StatusCollector sc = new StatusCollector(repo); // TODO from CommandContext |
139 // StatusCollector.Record r = new StatusCollector.Record(); // XXX use own inspector not to collect entries that | 155 // PathPool pathHelper = new PathPool(repo.getPathHelper()); // TODO from CommandContext |
140 // are not interesting or do not match name | 156 try { |
141 if (endRevision == WORKING_COPY) { | 157 // XXX if I need a rough estimation (for ProgressMonitor) of number of work units, |
142 WorkingCopyStatusCollector wcsc = new WorkingCopyStatusCollector(repo); | 158 // I may use number of files in either rev1 or rev2 manifest edition |
143 wcsc.setBaseRevisionCollector(sc); | 159 mediator.start(); |
144 wcsc.walk(startRevision, inspector); | 160 if (endRevision == WORKING_COPY) { |
145 } else { | 161 WorkingCopyStatusCollector wcsc = new WorkingCopyStatusCollector(repo); |
146 if (startRevision == TIP) { | 162 wcsc.setBaseRevisionCollector(sc); |
147 sc.change(endRevision, inspector); | 163 wcsc.walk(startRevision, mediator); |
148 } else { | 164 } else { |
149 sc.walk(startRevision, endRevision, inspector); | 165 if (startRevision == TIP) { |
150 } | 166 sc.change(endRevision, mediator); |
151 } | 167 } else { |
152 // PathPool pathHelper = new PathPool(repo.getPathHelper()); // TODO from CommandContext | 168 sc.walk(startRevision, endRevision, mediator); |
169 } | |
170 } | |
171 } finally { | |
172 mediator.done(); | |
173 visitor = null; | |
174 } | |
175 } | |
176 | |
177 private class Mediator implements HgStatusInspector { | |
178 boolean needModified; | |
179 boolean needAdded; | |
180 boolean needRemoved; | |
181 boolean needUnknown; | |
182 boolean needMissing; | |
183 boolean needClean; | |
184 boolean needIgnored; | |
185 boolean needCopies = false; // FIXME decide if I need such an argument in StatusComment | |
186 Matcher matcher; | |
187 | |
188 Mediator() { | |
189 } | |
190 | |
191 public void start() { | |
192 | |
193 } | |
194 public void done() { | |
195 } | |
196 | |
197 public void modified(Path fname) { | |
198 if (needModified) { | |
199 if (matcher == null || matcher.accept(fname)) { | |
200 visitor.modified(fname); | |
201 } | |
202 } | |
203 } | |
204 public void added(Path fname) { | |
205 if (needAdded) { | |
206 if (matcher == null || matcher.accept(fname)) { | |
207 visitor.added(fname); | |
208 } | |
209 } | |
210 } | |
211 public void removed(Path fname) { | |
212 if (needRemoved) { | |
213 if (matcher == null || matcher.accept(fname)) { | |
214 visitor.removed(fname); | |
215 } | |
216 } | |
217 } | |
218 public void copied(Path fnameOrigin, Path fnameAdded) { | |
219 if (needCopies) { | |
220 if (matcher == null || matcher.accept(fnameAdded)) { | |
221 visitor.copied(fnameOrigin, fnameAdded); | |
222 } | |
223 } | |
224 } | |
225 public void missing(Path fname) { | |
226 if (needMissing) { | |
227 if (matcher == null || matcher.accept(fname)) { | |
228 visitor.missing(fname); | |
229 } | |
230 } | |
231 } | |
232 public void unknown(Path fname) { | |
233 if (needUnknown) { | |
234 if (matcher == null || matcher.accept(fname)) { | |
235 visitor.unknown(fname); | |
236 } | |
237 } | |
238 } | |
239 public void clean(Path fname) { | |
240 if (needClean) { | |
241 if (matcher == null || matcher.accept(fname)) { | |
242 visitor.clean(fname); | |
243 } | |
244 } | |
245 } | |
246 public void ignored(Path fname) { | |
247 if (needIgnored) { | |
248 if (matcher == null || matcher.accept(fname)) { | |
249 visitor.ignored(fname); | |
250 } | |
251 } | |
252 } | |
153 } | 253 } |
154 } | 254 } |