Mercurial > jhg
comparison src/org/tmatesoft/hg/core/LogCommand.java @ 129:645829962785
core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 20:32:29 +0100 |
parents | b92a638764be |
children |
comparison
equal
deleted
inserted
replaced
128:44b97930570c | 129:645829962785 |
---|---|
24 import java.util.LinkedList; | 24 import java.util.LinkedList; |
25 import java.util.List; | 25 import java.util.List; |
26 import java.util.Set; | 26 import java.util.Set; |
27 import java.util.TreeSet; | 27 import java.util.TreeSet; |
28 | 28 |
29 import org.tmatesoft.hg.repo.Changeset; | 29 import org.tmatesoft.hg.repo.HgChangelog.Changeset; |
30 import org.tmatesoft.hg.repo.HgChangelog; | |
30 import org.tmatesoft.hg.repo.HgDataFile; | 31 import org.tmatesoft.hg.repo.HgDataFile; |
31 import org.tmatesoft.hg.repo.HgRepository; | 32 import org.tmatesoft.hg.repo.HgRepository; |
32 import org.tmatesoft.hg.repo.HgStatusCollector; | 33 import org.tmatesoft.hg.repo.HgStatusCollector; |
33 import org.tmatesoft.hg.util.PathPool; | 34 import org.tmatesoft.hg.util.PathPool; |
34 | 35 |
40 * Not thread-safe (each thread has to use own {@link LogCommand} instance). | 41 * Not thread-safe (each thread has to use own {@link LogCommand} instance). |
41 * | 42 * |
42 * @author Artem Tikhomirov | 43 * @author Artem Tikhomirov |
43 * @author TMate Software Ltd. | 44 * @author TMate Software Ltd. |
44 */ | 45 */ |
45 public class LogCommand implements Changeset.Inspector { | 46 public class LogCommand implements HgChangelog.Inspector { |
46 | 47 |
47 private final HgRepository repo; | 48 private final HgRepository repo; |
48 private Set<String> users; | 49 private Set<String> users; |
49 private Set<String> branches; | 50 private Set<String> branches; |
50 private int limit = 0, count = 0; | 51 private int limit = 0, count = 0; |
51 private int startRev = 0, endRev = TIP; | 52 private int startRev = 0, endRev = TIP; |
52 private Handler delegate; | 53 private Handler delegate; |
53 private Calendar date; | 54 private Calendar date; |
54 private Path file; | 55 private Path file; |
55 private boolean followHistory; // makes sense only when file != null | 56 private boolean followHistory; // makes sense only when file != null |
56 private Cset changeset; | 57 private HgChangeset changeset; |
57 | 58 |
58 public LogCommand(HgRepository hgRepo) { | 59 public LogCommand(HgRepository hgRepo) { |
59 repo = hgRepo; | 60 repo = hgRepo; |
60 } | 61 } |
61 | 62 |
145 } | 146 } |
146 | 147 |
147 /** | 148 /** |
148 * Similar to {@link #execute(org.tmatesoft.hg.repo.Changeset.Inspector)}, collects and return result as a list. | 149 * Similar to {@link #execute(org.tmatesoft.hg.repo.Changeset.Inspector)}, collects and return result as a list. |
149 */ | 150 */ |
150 public List<Cset> execute() { | 151 public List<HgChangeset> execute() { |
151 CollectHandler collector = new CollectHandler(); | 152 CollectHandler collector = new CollectHandler(); |
152 execute(collector); | 153 execute(collector); |
153 return collector.getChanges(); | 154 return collector.getChanges(); |
154 } | 155 } |
155 | 156 |
167 throw new ConcurrentModificationException(); | 168 throw new ConcurrentModificationException(); |
168 } | 169 } |
169 try { | 170 try { |
170 delegate = handler; | 171 delegate = handler; |
171 count = 0; | 172 count = 0; |
172 changeset = new Cset(new HgStatusCollector(repo), new PathPool(repo.getPathHelper())); | 173 changeset = new HgChangeset(new HgStatusCollector(repo), new PathPool(repo.getPathHelper())); |
173 if (file == null) { | 174 if (file == null) { |
174 repo.getChangelog().range(startRev, endRev, this); | 175 repo.getChangelog().range(startRev, endRev, this); |
175 } else { | 176 } else { |
176 HgDataFile fileNode = repo.getFileNode(file); | 177 HgDataFile fileNode = repo.getFileNode(file); |
177 fileNode.history(startRev, endRev, this); | 178 fileNode.history(startRev, endRev, this); |
230 delegate.next(changeset); | 231 delegate.next(changeset); |
231 } | 232 } |
232 | 233 |
233 public interface Handler { | 234 public interface Handler { |
234 /** | 235 /** |
235 * @param changeset not necessarily a distinct instance each time, {@link Cset#clone() clone()} if need a copy. | 236 * @param changeset not necessarily a distinct instance each time, {@link HgChangeset#clone() clone()} if need a copy. |
236 */ | 237 */ |
237 void next(Cset changeset); | 238 void next(HgChangeset changeset); |
238 } | 239 } |
239 | 240 |
240 /** | 241 /** |
241 * When {@link LogCommand} is executed against file, handler passed to {@link LogCommand#execute(Handler)} may optionally | 242 * When {@link LogCommand} is executed against file, handler passed to {@link LogCommand#execute(Handler)} may optionally |
242 * implement this interface to get information about file renames. Method {@link #copy(FileRevision, FileRevision)} would | 243 * implement this interface to get information about file renames. Method {@link #copy(FileRevision, FileRevision)} would |
243 * get invoked prior any changeset of the original file (if file history being followed) is reported via {@link #next(Cset)}. | 244 * get invoked prior any changeset of the original file (if file history being followed) is reported via {@link #next(HgChangeset)}. |
244 * | 245 * |
245 * For {@link LogCommand#file(Path, boolean)} with renamed file path and follow argument set to false, | 246 * For {@link LogCommand#file(Path, boolean)} with renamed file path and follow argument set to false, |
246 * {@link #copy(FileRevision, FileRevision)} would be invoked for the first copy/rename in the history of the file, but not | 247 * {@link #copy(FileRevision, FileRevision)} would be invoked for the first copy/rename in the history of the file, but not |
247 * followed by any changesets. | 248 * followed by any changesets. |
248 * | 249 * |
253 // XXX perhaps, should distinguish copy from rename? And what about merged revisions and following them? | 254 // XXX perhaps, should distinguish copy from rename? And what about merged revisions and following them? |
254 void copy(FileRevision from, FileRevision to); | 255 void copy(FileRevision from, FileRevision to); |
255 } | 256 } |
256 | 257 |
257 public static class CollectHandler implements Handler { | 258 public static class CollectHandler implements Handler { |
258 private final List<Cset> result = new LinkedList<Cset>(); | 259 private final List<HgChangeset> result = new LinkedList<HgChangeset>(); |
259 | 260 |
260 public List<Cset> getChanges() { | 261 public List<HgChangeset> getChanges() { |
261 return Collections.unmodifiableList(result); | 262 return Collections.unmodifiableList(result); |
262 } | 263 } |
263 | 264 |
264 public void next(Cset changeset) { | 265 public void next(HgChangeset changeset) { |
265 result.add(changeset.clone()); | 266 result.add(changeset.clone()); |
266 } | 267 } |
267 } | 268 } |
268 | 269 |
269 public static final class FileRevision { | 270 public static final class FileRevision { |