comparison src/org/tmatesoft/hg/internal/ChangelogMonitor.java @ 610:5c68567b3645

Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 09 May 2013 21:06:48 +0200
parents
children 6526d8adbc0f
comparison
equal deleted inserted replaced
609:e4a71afd3c71 610:5c68567b3645
1 /*
2 * Copyright (c) 2013 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 org.tmatesoft.hg.core.Nodeid;
20 import org.tmatesoft.hg.core.SessionContext;
21 import org.tmatesoft.hg.repo.HgRepository;
22
23 /**
24 * Track changes to a repository based on recent changelog revision.
25 * TODO shall be merged with {@link RevlogChangeMonitor} and {@link FileChangeMonitor} into
26 * a single facility available from {@link SessionContext}
27 *
28 * @author Artem Tikhomirov
29 * @author TMate Software Ltd.
30 */
31 public class ChangelogMonitor {
32 private final HgRepository repo;
33 private int changelogRevCount = -1;
34 private Nodeid changelogLastRev = null;
35
36 public ChangelogMonitor(HgRepository hgRepo) {
37 repo = hgRepo;
38 }
39
40 // memorize the state of the repository's changelog
41 public void touch() {
42 changelogRevCount = repo.getChangelog().getRevisionCount();
43 changelogLastRev = safeGetRevision(changelogRevCount-1);
44 }
45
46 // if present state doesn't match the one we remember
47 public boolean isChanged() {
48 int rc = repo.getChangelog().getRevisionCount();
49 if (rc != changelogRevCount) {
50 return true;
51 }
52 Nodeid r = safeGetRevision(rc-1);
53 return !r.equals(changelogLastRev);
54 }
55
56 // handles empty repository case
57 private Nodeid safeGetRevision(int revIndex) {
58 if (revIndex >= 0) {
59 return repo.getChangelog().getRevision(revIndex);
60 }
61 return Nodeid.NULL;
62 }
63 }