comparison hg4j/src/main/java/org/tmatesoft/hg/internal/ChangelogHelper.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
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.repo.HgChangelog.RawChangeset;
22 import org.tmatesoft.hg.repo.HgDataFile;
23 import org.tmatesoft.hg.repo.HgInternals;
24 import org.tmatesoft.hg.repo.HgRepository;
25 import org.tmatesoft.hg.util.Path;
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, RawChangeset> cache = new TreeMap<Integer, RawChangeset>();
36 private String nextCommitAuthor;
37
38 /**
39 * @param hgRepo
40 * @param leftBoundaryRevision walker never visits revisions with local numbers less than specified,
41 * IOW only revisions [leftBoundaryRevision..TIP] are considered.
42 */
43 public ChangelogHelper(HgRepository hgRepo, int leftBoundaryRevision) {
44 repo = hgRepo;
45 leftBoundary = leftBoundaryRevision;
46 }
47
48 /**
49 * @return the repo
50 */
51 public HgRepository getRepo() {
52 return repo;
53 }
54
55 /**
56 * Walks changelog in reverse order
57 * @param file
58 * @return changeset where specified file is mentioned among affected files, or
59 * <code>null</code> if none found up to leftBoundary
60 */
61 public RawChangeset findLatestChangeWith(Path file) {
62 HgDataFile df = repo.getFileNode(file);
63 int changelogRev = df.getChangesetLocalRevision(HgRepository.TIP);
64 if (changelogRev >= leftBoundary) {
65 // the method is likely to be invoked for different files,
66 // while changesets might be the same. Cache 'em not to read too much.
67 RawChangeset cs = cache.get(changelogRev);
68 if (cs == null) {
69 cs = repo.getChangelog().range(changelogRev, changelogRev).get(0);
70 cache.put(changelogRev, cs);
71 }
72 return cs;
73 }
74 return null;
75 }
76
77 public String getNextCommitUsername() {
78 if (nextCommitAuthor == null) {
79 nextCommitAuthor = new HgInternals(repo).getNextCommitUsername();
80 }
81 return nextCommitAuthor;
82 }
83 }