Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/HgBookmarks.java @ 611:7fc7fba4df30
Tests for tailored sections in HgRepoConfig
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 09 May 2013 21:52:01 +0200 |
parents | 5c68567b3645 |
children | f41dd9a3b8af |
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; |
605
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
33 import org.tmatesoft.hg.internal.Experimental; |
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
|
34 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
|
35 import org.tmatesoft.hg.internal.Internals; |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.internal.LineReader; |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import org.tmatesoft.hg.util.LogFacility; |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 /** |
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
|
40 * Access to bookmarks state |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * |
605
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
42 * @see http://mercurial.selenic.com/wiki/Bookmarks |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author Artem Tikhomirov |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 * @author TMate Software Ltd. |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 */ |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 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
|
47 private final Internals repo; |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 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
|
49 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
|
50 private FileChangeMonitor activeTracker, bmFileTracker; |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
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
|
52 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
|
53 repo = internals; |
484
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 |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 /*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
|
57 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
|
58 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
|
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 |
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 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
|
62 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
|
63 File all = repo.getRepositoryFile(HgRepositoryFiles.Bookmarks); |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 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
|
65 if (all.canRead() && all.isFile()) { |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 LineReader lr1 = new LineReader(all, log); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 ArrayList<String> c = new ArrayList<String>(); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 lr1.read(new LineReader.SimpleLineCollector(), c); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 for (String s : c) { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 int x = s.indexOf(' '); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 try { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 if (x > 0) { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 Nodeid nid = Nodeid.fromAscii(s.substring(0, x)); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 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
|
75 if (repo.getRepo().getChangelog().isKnown(nid)) { |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 // copy name part not to drag complete line |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 bm.put(name, nid); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } else { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 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
|
80 } |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } else { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 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
|
83 } |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } catch (IllegalArgumentException ex) { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 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
|
86 } |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 bookmarks = bm; |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } else { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 bookmarks = Collections.emptyMap(); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
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
|
92 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
|
93 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
|
94 } |
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 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
|
96 } |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 |
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
|
98 private void readActiveBookmark() throws HgInvalidControlFileException { |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 LineReader lr2 = new LineReader(active, repo.getLog()); |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 ArrayList<String> c = new ArrayList<String>(2); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 lr2.read(new LineReader.SimpleLineCollector(), c); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 if (c.size() > 0) { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 activeBookmark = c.get(0); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 } |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |
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
|
109 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
|
110 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
|
111 } |
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
|
112 activeTracker.touch(this); |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 } |
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
|
114 |
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 /*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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 } |
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 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
|
122 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
|
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 } |
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
|
125 |
484
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 /** |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 * Tell name of the active bookmark |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 * @return <code>null</code> if none active |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 */ |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 public String getActiveBookmarkName() { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 return activeBookmark; |
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 /** |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 * Retrieve revision associated with the named bookmark. |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 * |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 * @param bookmarkName name of the bookmark |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 * @return revision or <code>null</code> if bookmark is not known |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 */ |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 public Nodeid getRevision(String bookmarkName) { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 return bookmarks.get(bookmarkName); |
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 /** |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 * Retrieve all bookmarks known in the repository |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 * @return collection with names, never <code>null</code> |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 */ |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 public Collection<String> getAllBookmarks() { |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 // bookmarks are initialized with atomic assignment, |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 // hence can use view (not a synchronized copy) here |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 return Collections.unmodifiableSet(bookmarks.keySet()); |
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 } |
605
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 /** |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
156 * Update currently bookmark with new commit. |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
157 * 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
|
158 * |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
159 * @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
|
160 * @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
|
161 * @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
|
162 * @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
|
163 * @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
|
164 */ |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
165 @Experimental(reason="Provisional API") |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
166 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
|
167 if (activeBookmark == null) { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
168 return; |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
169 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
170 Nodeid activeRev = getRevision(activeBookmark); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
171 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
|
172 // from the wiki: |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
173 // "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
|
174 // 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
|
175 return; |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
176 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
177 if (child.equals(activeRev)) { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
178 return; |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
179 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
180 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
|
181 copy.put(activeBookmark, child); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
182 bookmarks = copy; |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
183 write(); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
184 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
185 |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
186 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
|
187 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
|
188 HgRepositoryLock workingDirLock = repo.getRepo().getWorkingDirLock(); |
605
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
189 FileWriter fileWriter = null; |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
190 workingDirLock.acquire(); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
191 try { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
192 fileWriter = new FileWriter(bookmarksFile); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
193 for (String bm : bookmarks.keySet()) { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
194 Nodeid nid = bookmarks.get(bm); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
195 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
|
196 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
197 fileWriter.flush(); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
198 } catch (IOException ex) { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
199 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
|
200 } finally { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
201 try { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
202 if (fileWriter != null) { |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
203 fileWriter.close(); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
204 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
205 } 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
|
206 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
|
207 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
208 workingDirLock.release(); |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
209 } |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
210 } |
484
ae4d6604debd
Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 } |