Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgBookmarks.java @ 615:84104448a0bf
Test for repository locks
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Mon, 13 May 2013 22:48:29 +0200 | 
| parents | f41dd9a3b8af | 
| children | 507602cb4fb3 | 
| rev | line source | 
|---|---|
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
1 /* | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
2 * Copyright (c) 2012-2013 TMate Software Ltd | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
3 * | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
4 * This program is free software; you can redistribute it and/or modify | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
5 * it under the terms of the GNU General Public License as published by | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
6 * the Free Software Foundation; version 2 of the License. | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
7 * | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
8 * This program is distributed in the hope that it will be useful, | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
11 * GNU General Public License for more details. | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
12 * | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
13 * For information on how to redistribute this software under | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
14 * the terms of a license other than GNU General Public License | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
15 * contact TMate Software at support@hg4j.com | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
16 */ | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
17 package org.tmatesoft.hg.repo; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
18 | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
20 | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
21 import java.io.File; | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
22 import java.io.FileWriter; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
23 import java.io.IOException; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
24 import java.util.ArrayList; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
25 import java.util.Collection; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
26 import java.util.Collections; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
27 import java.util.LinkedHashMap; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
28 import java.util.Map; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
29 | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
30 import org.tmatesoft.hg.core.HgIOException; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
31 import org.tmatesoft.hg.core.HgRepositoryLockException; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
32 import org.tmatesoft.hg.core.Nodeid; | 
| 
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: 
605 
diff
changeset
 | 
33 import org.tmatesoft.hg.internal.FileChangeMonitor; | 
| 
490
 
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
484 
diff
changeset
 | 
34 import org.tmatesoft.hg.internal.Internals; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
35 import org.tmatesoft.hg.internal.LineReader; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
36 import org.tmatesoft.hg.util.LogFacility; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
37 | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
38 /** | 
| 
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: 
605 
diff
changeset
 | 
39 * Access to bookmarks state | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
40 * | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
41 * @see http://mercurial.selenic.com/wiki/Bookmarks | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
42 * @author Artem Tikhomirov | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
43 * @author TMate Software Ltd. | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
44 */ | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
45 public final class HgBookmarks { | 
| 
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: 
605 
diff
changeset
 | 
46 private final Internals repo; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
47 private Map<String, Nodeid> bookmarks = Collections.emptyMap(); | 
| 
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: 
605 
diff
changeset
 | 
48 private String activeBookmark; | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
49 private FileChangeMonitor activeTracker, bmFileTracker; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
50 | 
| 
490
 
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
484 
diff
changeset
 | 
51 HgBookmarks(Internals internals) { | 
| 
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: 
605 
diff
changeset
 | 
52 repo = internals; | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
53 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
54 | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
55 /*package-local*/ void read() throws HgInvalidControlFileException { | 
| 
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: 
605 
diff
changeset
 | 
56 readBookmarks(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
57 readActiveBookmark(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
58 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
59 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
60 private void readBookmarks() throws HgInvalidControlFileException { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
61 final LogFacility log = repo.getLog(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
62 File all = repo.getRepositoryFile(HgRepositoryFiles.Bookmarks); | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
63 LinkedHashMap<String, Nodeid> bm = new LinkedHashMap<String, Nodeid>(); | 
| 
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: 
605 
diff
changeset
 | 
64 if (all.canRead() && all.isFile()) { | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
65 LineReader lr1 = new LineReader(all, log); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
66 ArrayList<String> c = new ArrayList<String>(); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
67 lr1.read(new LineReader.SimpleLineCollector(), c); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
68 for (String s : c) { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
69 int x = s.indexOf(' '); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
70 try { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
71 if (x > 0) { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
72 Nodeid nid = Nodeid.fromAscii(s.substring(0, x)); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
73 String name = new String(s.substring(x+1)); | 
| 
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: 
605 
diff
changeset
 | 
74 if (repo.getRepo().getChangelog().isKnown(nid)) { | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
75 // copy name part not to drag complete line | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
76 bm.put(name, nid); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
77 } else { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
78 log.dump(getClass(), LogFacility.Severity.Info, "Bookmark %s points to non-existent revision %s, ignored.", name, nid); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
79 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
80 } else { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
81 log.dump(getClass(), LogFacility.Severity.Warn, "Can't parse bookmark entry: %s", s); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
82 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
83 } catch (IllegalArgumentException ex) { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
84 log.dump(getClass(), LogFacility.Severity.Warn, ex, String.format("Can't parse bookmark entry: %s", s)); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
85 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
86 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
87 bookmarks = bm; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
88 } else { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
89 bookmarks = Collections.emptyMap(); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
90 } | 
| 
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: 
605 
diff
changeset
 | 
91 if (bmFileTracker == 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: 
605 
diff
changeset
 | 
92 bmFileTracker = new FileChangeMonitor(all); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
93 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
94 bmFileTracker.touch(this); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
95 } | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
96 | 
| 
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: 
605 
diff
changeset
 | 
97 private void readActiveBookmark() throws HgInvalidControlFileException { | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
98 activeBookmark = null; | 
| 
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: 
605 
diff
changeset
 | 
99 File active = repo.getRepositoryFile(HgRepositoryFiles.BookmarksCurrent); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
100 if (active.canRead() && active.isFile()) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
101 LineReader lr2 = new LineReader(active, repo.getLog()); | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
102 ArrayList<String> c = new ArrayList<String>(2); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
103 lr2.read(new LineReader.SimpleLineCollector(), c); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
104 if (c.size() > 0) { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
105 activeBookmark = c.get(0); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
106 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
107 } | 
| 
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: 
605 
diff
changeset
 | 
108 if (activeTracker == 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: 
605 
diff
changeset
 | 
109 activeTracker = new FileChangeMonitor(active); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
110 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
111 activeTracker.touch(this); | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
112 } | 
| 
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: 
605 
diff
changeset
 | 
113 | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
114 /*package-local*/void reloadIfChanged() throws HgInvalidControlFileException { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
115 assert activeTracker != 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: 
605 
diff
changeset
 | 
116 assert bmFileTracker != 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: 
605 
diff
changeset
 | 
117 if (bmFileTracker.changed(this)) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
118 readBookmarks(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
119 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
120 if (activeTracker.changed(this)) { | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
121 readActiveBookmark(); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
122 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
123 } | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
124 | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
125 | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
126 /** | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
127 * Tell name of the active bookmark | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
128 * @return <code>null</code> if none active | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
129 */ | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
130 public String getActiveBookmarkName() { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
131 return activeBookmark; | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
132 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
133 | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
134 /** | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
135 * Retrieve revision associated with the named bookmark. | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
136 * | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
137 * @param bookmarkName name of the bookmark | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
138 * @return revision or <code>null</code> if bookmark is not known | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
139 */ | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
140 public Nodeid getRevision(String bookmarkName) { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
141 return bookmarks.get(bookmarkName); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
142 } | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
143 | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
144 /** | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
145 * Retrieve all bookmarks known in the repository | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
146 * @return collection with names, never <code>null</code> | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
147 */ | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
148 public Collection<String> getAllBookmarks() { | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
149 // bookmarks are initialized with atomic assignment, | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
150 // hence can use view (not a synchronized copy) here | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
151 return Collections.unmodifiableSet(bookmarks.keySet()); | 
| 
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
152 } | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
153 | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
154 /** | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
155 * Update currently bookmark with new commit. | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
156 * Note, child has to be descendant of a p1 or p2 | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
157 * | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
158 * @param p1 first parent, or <code>null</code> | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
159 * @param p2 second parent, or <code>null</code> | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
160 * @param child new commit, descendant of one of the parents, not <code>null</code> | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
161 * @throws HgIOException if failed to write updated bookmark information | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
162 * @throws HgRepositoryLockException if failed to lock repository for modifications | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
163 */ | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
164 public void updateActive(Nodeid p1, Nodeid p2, Nodeid child) throws HgIOException, HgRepositoryLockException { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
165 if (activeBookmark == null) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
166 return; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
167 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
168 Nodeid activeRev = getRevision(activeBookmark); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
169 if (!activeRev.equals(p1) && !activeRev.equals(p2)) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
170 // from the wiki: | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
171 // "active bookmarks are automatically updated when committing to the changeset they are pointing to" | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
172 // FIXME: test ci 1, hg bookmark active, ci 2, hg bookmark -f -r 0 active, ci 3, check active still points to r0 | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
173 return; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
174 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
175 if (child.equals(activeRev)) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
176 return; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
177 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
178 LinkedHashMap<String, Nodeid> copy = new LinkedHashMap<String, Nodeid>(bookmarks); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
179 copy.put(activeBookmark, child); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
180 bookmarks = copy; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
181 write(); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
182 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
183 | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
184 private void write() throws HgIOException, HgRepositoryLockException { | 
| 
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: 
605 
diff
changeset
 | 
185 File bookmarksFile = repo.getRepositoryFile(HgRepositoryFiles.Bookmarks); | 
| 
 
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
605 
diff
changeset
 | 
186 HgRepositoryLock workingDirLock = repo.getRepo().getWorkingDirLock(); | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
187 FileWriter fileWriter = null; | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
188 workingDirLock.acquire(); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
189 try { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
190 fileWriter = new FileWriter(bookmarksFile); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
191 for (String bm : bookmarks.keySet()) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
192 Nodeid nid = bookmarks.get(bm); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
193 fileWriter.write(String.format("%s %s\n", nid.toString(), bm)); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
194 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
195 fileWriter.flush(); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
196 } catch (IOException ex) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
197 throw new HgIOException("Failed to serialize bookmarks", ex, bookmarksFile); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
198 } finally { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
199 try { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
200 if (fileWriter != null) { | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
201 fileWriter.close(); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
202 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
203 } catch (IOException ex) { | 
| 
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: 
605 
diff
changeset
 | 
204 repo.getLog().dump(getClass(), Error, ex, null); | 
| 
605
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
205 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
206 workingDirLock.release(); | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
207 } | 
| 
 
c56edf42be64
Commit: update active bookmark with new revision
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
501 
diff
changeset
 | 
208 } | 
| 
484
 
ae4d6604debd
Bookmarks support added
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
209 } | 
