annotate src/org/tmatesoft/hg/internal/ChangelogHelper.java @ 508:ca5202afea90

Support follow history option when walking file history tree
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 12 Dec 2012 20:52:10 +0100
parents 9c9c442b5f2e
children 6526d8adbc0f
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
154
ba2bf656f00f Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 140
diff changeset
19 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
20 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
21 import org.tmatesoft.hg.repo.HgInternals;
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 381
diff changeset
22 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
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.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
24 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
25
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 /**
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 * @author Artem Tikhomirov
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 * @author TMate Software Ltd.
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 */
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 public class ChangelogHelper {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 private final int leftBoundary;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 private final HgRepository repo;
381
6e37c7168585 IntMap is more effective than TreeMap<Integer,...>
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
34 private final IntMap<RawChangeset> cache = new IntMap<RawChangeset>(32);
140
1c1891ad1c73 Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
35 private String nextCommitAuthor;
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 /**
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @param hgRepo
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 * @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
40 * 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
41 */
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 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
43 repo = hgRepo;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 leftBoundary = leftBoundaryRevision;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46
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 * @return the repo
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 public HgRepository getRepo() {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 return repo;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
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 * 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
56 * @param file
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 247
diff changeset
57 * @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
58 */
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 247
diff changeset
59 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
60 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
61 if (!df.exists()) {
f052f40839ec Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 154
diff changeset
62 return null;
f052f40839ec Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 154
diff changeset
63 }
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
64 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
65 if (changelogRev >= leftBoundary) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 // 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
67 // 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
68 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
69 if (cs == null) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 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
71 cache.put(changelogRev, cs);
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 return 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 null;
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
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 public String getNextCommitUsername() {
140
1c1891ad1c73 Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
79 if (nextCommitAuthor == null) {
1c1891ad1c73 Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
80 nextCommitAuthor = new HgInternals(repo).getNextCommitUsername();
1c1891ad1c73 Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
81 }
1c1891ad1c73 Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
82 return nextCommitAuthor;
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }