Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/ChangelogMonitor.java @ 615:84104448a0bf
Test for repository locks
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Mon, 13 May 2013 22:48:29 +0200 | 
| parents | 5c68567b3645 | 
| children | 6526d8adbc0f | 
| rev | line source | 
|---|---|
| 
610
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
1 /* | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
2 * Copyright (c) 2013 TMate Software Ltd | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
3 * | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
4 * This program is free software; you can redistribute it and/or modify | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
5 * it under the terms of the GNU General Public License as published by | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
6 * the Free Software Foundation; version 2 of the License. | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
7 * | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
8 * This program is distributed in the hope that it will be useful, | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
11 * GNU General Public License for more details. | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
12 * | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
13 * For information on how to redistribute this software under | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
14 * the terms of a license other than GNU General Public License | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
15 * contact TMate Software at support@hg4j.com | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
16 */ | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
17 package org.tmatesoft.hg.internal; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
18 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
19 import org.tmatesoft.hg.core.Nodeid; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
20 import org.tmatesoft.hg.core.SessionContext; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
21 import org.tmatesoft.hg.repo.HgRepository; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
22 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
23 /** | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
24 * Track changes to a repository based on recent changelog revision. | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
25 * TODO shall be merged with {@link RevlogChangeMonitor} and {@link FileChangeMonitor} into | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
26 * a single facility available from {@link SessionContext} | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
27 * | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
28 * @author Artem Tikhomirov | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
29 * @author TMate Software Ltd. | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
30 */ | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
31 public class ChangelogMonitor { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
32 private final HgRepository repo; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
33 private int changelogRevCount = -1; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
34 private Nodeid changelogLastRev = null; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
35 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
36 public ChangelogMonitor(HgRepository hgRepo) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
37 repo = hgRepo; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
38 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
39 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
40 // memorize the state of the repository's changelog | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
41 public void touch() { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
42 changelogRevCount = repo.getChangelog().getRevisionCount(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
43 changelogLastRev = safeGetRevision(changelogRevCount-1); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
44 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
45 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
46 // if present state doesn't match the one we remember | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
47 public boolean isChanged() { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
48 int rc = repo.getChangelog().getRevisionCount(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
49 if (rc != changelogRevCount) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
50 return true; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
51 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
52 Nodeid r = safeGetRevision(rc-1); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
53 return !r.equals(changelogLastRev); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
54 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
55 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
56 // handles empty repository case | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
57 private Nodeid safeGetRevision(int revIndex) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
58 if (revIndex >= 0) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
59 return repo.getChangelog().getRevision(revIndex); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
60 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
61 return Nodeid.NULL; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
62 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
63 } | 
