Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ChangelogHelper.java @ 128:44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 20:13:41 +0100 |
parents | |
children | 645829962785 |
comparison
equal
deleted
inserted
replaced
127:2e395db595e2 | 128:44b97930570c |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.util.TreeMap; | |
20 | |
21 import org.tmatesoft.hg.core.Path; | |
22 import org.tmatesoft.hg.repo.Changeset; | |
23 import org.tmatesoft.hg.repo.HgDataFile; | |
24 import org.tmatesoft.hg.repo.HgInternals; | |
25 import org.tmatesoft.hg.repo.HgRepository; | |
26 | |
27 /** | |
28 * | |
29 * @author Artem Tikhomirov | |
30 * @author TMate Software Ltd. | |
31 */ | |
32 public class ChangelogHelper { | |
33 private final int leftBoundary; | |
34 private final HgRepository repo; | |
35 private final TreeMap<Integer, Changeset> cache = new TreeMap<Integer, Changeset>(); | |
36 | |
37 /** | |
38 * @param hgRepo | |
39 * @param leftBoundaryRevision walker never visits revisions with local numbers less than specified, | |
40 * IOW only revisions [leftBoundaryRevision..TIP] are considered. | |
41 */ | |
42 public ChangelogHelper(HgRepository hgRepo, int leftBoundaryRevision) { | |
43 repo = hgRepo; | |
44 leftBoundary = leftBoundaryRevision; | |
45 } | |
46 | |
47 /** | |
48 * @return the repo | |
49 */ | |
50 public HgRepository getRepo() { | |
51 return repo; | |
52 } | |
53 | |
54 /** | |
55 * Walks changelog in reverse order | |
56 * @param file | |
57 * @return changeset where specified file is mentioned among affected files, or | |
58 * <code>null</code> if none found up to leftBoundary | |
59 */ | |
60 public Changeset findLatestChangeWith(Path file) { | |
61 HgDataFile df = repo.getFileNode(file); | |
62 int changelogRev = df.getChangesetLocalRevision(HgRepository.TIP); | |
63 if (changelogRev >= leftBoundary) { | |
64 // the method is likely to be invoked for different files, | |
65 // while changesets might be the same. Cache 'em not to read too much. | |
66 Changeset cs = cache.get(changelogRev); | |
67 if (cs == null) { | |
68 cs = repo.getChangelog().range(changelogRev, changelogRev).get(0); | |
69 cache.put(changelogRev, cs); | |
70 } | |
71 return cs; | |
72 } | |
73 return null; | |
74 } | |
75 | |
76 public String getNextCommitUsername() { | |
77 return new HgInternals(repo).getNextCommitUsername(); | |
78 } | |
79 } |