Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/ChangelogHelper.java @ 380:9517df1ef7ec
Comments/javadoc
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 09 Feb 2012 18:57:14 +0100 |
parents | 2fadf8695f8a |
children | 6e37c7168585 |
rev | line source |
---|---|
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.util.TreeMap; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
247
diff
changeset
|
21 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
140
diff
changeset
|
22 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import org.tmatesoft.hg.repo.HgDataFile; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgInternals; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.repo.HgRepository; |
133
4a948ec83980
core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
26 import org.tmatesoft.hg.util.Path; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 /** |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * @author Artem Tikhomirov |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 * @author TMate Software Ltd. |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 */ |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public class ChangelogHelper { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 private final int leftBoundary; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 private final HgRepository repo; |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
247
diff
changeset
|
36 private final TreeMap<Integer, RawChangeset> cache = new TreeMap<Integer, RawChangeset>(); // FIXME use IntMap instead |
140
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
37 private String nextCommitAuthor; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 /** |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * @param hgRepo |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @param leftBoundaryRevision walker never visits revisions with local numbers less than specified, |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * IOW only revisions [leftBoundaryRevision..TIP] are considered. |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 */ |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 public ChangelogHelper(HgRepository hgRepo, int leftBoundaryRevision) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 repo = hgRepo; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 leftBoundary = leftBoundaryRevision; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 /** |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * @return the repo |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 */ |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 public HgRepository getRepo() { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 return repo; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 /** |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 * Walks changelog in reverse order |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 * @param file |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
247
diff
changeset
|
59 * @return changeset where specified file is mentioned among affected files, or <code>null</code> if none found up to leftBoundary |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 */ |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
247
diff
changeset
|
61 public RawChangeset findLatestChangeWith(Path file) throws HgInvalidControlFileException { |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 HgDataFile df = repo.getFileNode(file); |
247
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
63 if (!df.exists()) { |
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
64 return null; |
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
65 } |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
66 int changelogRev = df.getChangesetRevisionIndex(HgRepository.TIP); |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 if (changelogRev >= leftBoundary) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 // the method is likely to be invoked for different files, |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 // while changesets might be the same. Cache 'em not to read too much. |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
140
diff
changeset
|
70 RawChangeset cs = cache.get(changelogRev); |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 if (cs == null) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 cs = repo.getChangelog().range(changelogRev, changelogRev).get(0); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 cache.put(changelogRev, cs); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 return cs; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 return null; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 public String getNextCommitUsername() { |
140
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
81 if (nextCommitAuthor == null) { |
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
82 nextCommitAuthor = new HgInternals(repo).getNextCommitUsername(); |
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
83 } |
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
84 return nextCommitAuthor; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |