Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/KeywordFilter.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | 528b6780a8bd |
children | 909306e412e2 |
comparison
equal
deleted
inserted
replaced
422:5d1cc7366d04 | 423:9c9c442b5f2e |
---|---|
19 import java.nio.ByteBuffer; | 19 import java.nio.ByteBuffer; |
20 import java.util.ArrayList; | 20 import java.util.ArrayList; |
21 import java.util.Date; | 21 import java.util.Date; |
22 import java.util.TreeMap; | 22 import java.util.TreeMap; |
23 | 23 |
24 import org.tmatesoft.hg.core.HgException; | |
25 import org.tmatesoft.hg.core.HgInvalidControlFileException; | |
26 import org.tmatesoft.hg.core.Nodeid; | 24 import org.tmatesoft.hg.core.Nodeid; |
27 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 25 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
28 import org.tmatesoft.hg.repo.HgInternals; | 26 import org.tmatesoft.hg.repo.HgInternals; |
29 import org.tmatesoft.hg.repo.HgRepository; | 27 import org.tmatesoft.hg.repo.HgRepository; |
28 import org.tmatesoft.hg.repo.HgRuntimeException; | |
30 import org.tmatesoft.hg.util.Pair; | 29 import org.tmatesoft.hg.util.Pair; |
31 import org.tmatesoft.hg.util.Path; | 30 import org.tmatesoft.hg.util.Path; |
32 | 31 |
33 /** | 32 /** |
34 * | 33 * |
261 try { | 260 try { |
262 // TODO post-1.0 Either add cset's nodeid into Changeset class or use own inspector | 261 // TODO post-1.0 Either add cset's nodeid into Changeset class or use own inspector |
263 // when accessing changelog, see below, #getChangeset | 262 // when accessing changelog, see below, #getChangeset |
264 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP); | 263 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP); |
265 return repo.getChangelog().getRevision(csetRev).shortNotation(); | 264 return repo.getChangelog().getRevision(csetRev).shortNotation(); |
266 } catch (HgException ex) { | 265 } catch (HgRuntimeException ex) { |
267 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); | 266 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); |
268 return Nodeid.NULL.shortNotation(); // XXX perhaps, might return anything better? Not sure how hg approaches this. | 267 return Nodeid.NULL.shortNotation(); // XXX perhaps, might return anything better? Not sure how hg approaches this. |
269 } | 268 } |
270 } | 269 } |
271 | 270 |
272 private String username() { | 271 private String username() { |
273 try { | 272 try { |
274 return getChangeset().user(); | 273 return getChangeset().user(); |
275 } catch (HgException ex) { | 274 } catch (HgRuntimeException ex) { |
276 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); | 275 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); |
277 return ""; | 276 return ""; |
278 } | 277 } |
279 } | 278 } |
280 | 279 |
281 private String date() { | 280 private String date() { |
282 Date d; | 281 Date d; |
283 try { | 282 try { |
284 d = getChangeset().date(); | 283 d = getChangeset().date(); |
285 } catch (HgException ex) { | 284 } catch (HgRuntimeException ex) { |
286 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); | 285 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); |
287 d = new Date(0l); | 286 d = new Date(0l); |
288 } | 287 } |
289 return String.format("%tY/%<tm/%<td %<tH:%<tM:%<tS", d); | 288 return String.format("%tY/%<tm/%<td %<tH:%<tM:%<tS", d); |
290 } | 289 } |
291 | 290 |
292 private RawChangeset getChangeset() throws HgInvalidControlFileException { | 291 private RawChangeset getChangeset() throws HgRuntimeException { |
293 if (latestFileCset == null) { | 292 if (latestFileCset == null) { |
294 // TODO post-1.0 Use of TIP is likely incorrect in cases when working copy is not based | 293 // TODO post-1.0 Use of TIP is likely incorrect in cases when working copy is not based |
295 // on latest revision. Perhaps, a constant like HgRepository.DIRSTATE_PARENT may come handy | 294 // on latest revision. Perhaps, a constant like HgRepository.DIRSTATE_PARENT may come handy |
296 // Besides, it's reasonable to pass own inspector instead of implicit use of RawCsetCollector | 295 // Besides, it's reasonable to pass own inspector instead of implicit use of RawCsetCollector |
297 // to get changeset nodeid/index right away. Also check ChangelogHelper if may be of any use | 296 // to get changeset nodeid/index right away. Also check ChangelogHelper if may be of any use |
313 if (!"ignore".equalsIgnoreCase(e.second())) { | 312 if (!"ignore".equalsIgnoreCase(e.second())) { |
314 patterns.add(e.first()); | 313 patterns.add(e.first()); |
315 } | 314 } |
316 } | 315 } |
317 matcher = new PathGlobMatcher(patterns.toArray(new String[patterns.size()])); | 316 matcher = new PathGlobMatcher(patterns.toArray(new String[patterns.size()])); |
318 // TODO read and respect keyword patterns from [keywordmaps] | 317 // TODO post-1.0 read and respect keyword patterns from [keywordmaps] |
319 } | 318 } |
320 | 319 |
321 public Filter create(Path path, Options opts) { | 320 public Filter create(Path path, Options opts) { |
322 if (matcher.accept(path)) { | 321 if (matcher.accept(path)) { |
323 return new KeywordFilter(repo, path, opts.getDirection() == Filter.Direction.FromRepo); | 322 return new KeywordFilter(repo, path, opts.getDirection() == Filter.Direction.FromRepo); |