comparison src/org/tmatesoft/hg/repo/HgBookmarks.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 507602cb4fb3
children
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
50 50
51 HgBookmarks(Internals internals) { 51 HgBookmarks(Internals internals) {
52 repo = internals; 52 repo = internals;
53 } 53 }
54 54
55 /*package-local*/ void read() throws HgInvalidControlFileException { 55 /*package-local*/ void read() throws HgRuntimeException {
56 readBookmarks(); 56 readBookmarks();
57 readActiveBookmark(); 57 readActiveBookmark();
58 } 58 }
59 59
60 private void readBookmarks() throws HgInvalidControlFileException { 60 private void readBookmarks() throws HgRuntimeException {
61 final LogFacility log = repo.getLog(); 61 final LogFacility log = repo.getLog();
62 File all = repo.getRepositoryFile(HgRepositoryFiles.Bookmarks); 62 File all = repo.getRepositoryFile(HgRepositoryFiles.Bookmarks);
63 LinkedHashMap<String, Nodeid> bm = new LinkedHashMap<String, Nodeid>(); 63 try {
64 if (all.canRead() && all.isFile()) { 64 LinkedHashMap<String, Nodeid> bm = new LinkedHashMap<String, Nodeid>();
65 LineReader lr1 = new LineReader(all, log); 65 if (all.canRead() && all.isFile()) {
66 ArrayList<String> c = new ArrayList<String>(); 66 LineReader lr1 = new LineReader(all, log);
67 lr1.read(new LineReader.SimpleLineCollector(), c); 67 ArrayList<String> c = new ArrayList<String>();
68 for (String s : c) { 68 lr1.read(new LineReader.SimpleLineCollector(), c);
69 int x = s.indexOf(' '); 69 for (String s : c) {
70 try { 70 int x = s.indexOf(' ');
71 if (x > 0) { 71 try {
72 Nodeid nid = Nodeid.fromAscii(s.substring(0, x)); 72 if (x > 0) {
73 String name = new String(s.substring(x+1)); 73 Nodeid nid = Nodeid.fromAscii(s.substring(0, x));
74 if (repo.getRepo().getChangelog().isKnown(nid)) { 74 String name = new String(s.substring(x+1));
75 // copy name part not to drag complete line 75 if (repo.getRepo().getChangelog().isKnown(nid)) {
76 bm.put(name, nid); 76 // copy name part not to drag complete line
77 bm.put(name, nid);
78 } else {
79 log.dump(getClass(), LogFacility.Severity.Info, "Bookmark %s points to non-existent revision %s, ignored.", name, nid);
80 }
77 } else { 81 } else {
78 log.dump(getClass(), LogFacility.Severity.Info, "Bookmark %s points to non-existent revision %s, ignored.", name, nid); 82 log.dump(getClass(), LogFacility.Severity.Warn, "Can't parse bookmark entry: %s", s);
79 } 83 }
80 } else { 84 } catch (IllegalArgumentException ex) {
81 log.dump(getClass(), LogFacility.Severity.Warn, "Can't parse bookmark entry: %s", s); 85 log.dump(getClass(), LogFacility.Severity.Warn, ex, String.format("Can't parse bookmark entry: %s", s));
82 } 86 }
83 } catch (IllegalArgumentException ex) {
84 log.dump(getClass(), LogFacility.Severity.Warn, ex, String.format("Can't parse bookmark entry: %s", s));
85 } 87 }
86 } 88 bookmarks = bm;
87 bookmarks = bm; 89 } else {
88 } else { 90 bookmarks = Collections.emptyMap();
89 bookmarks = Collections.emptyMap(); 91 }
90 } 92 if (bmFileTracker == null) {
91 if (bmFileTracker == null) { 93 bmFileTracker = new FileChangeMonitor(all);
92 bmFileTracker = new FileChangeMonitor(all); 94 }
93 } 95 bmFileTracker.touch(this);
94 bmFileTracker.touch(this); 96 } catch (HgInvalidControlFileException ex) {
95 } 97 // do not translate HgInvalidControlFileException into another HgInvalidControlFileException
96 98 // but only HgInvalidFileException
99 throw ex;
100 } catch (HgIOException ex) {
101 throw new HgInvalidControlFileException(ex, true);
102 }
103 }
104
97 private void readActiveBookmark() throws HgInvalidControlFileException { 105 private void readActiveBookmark() throws HgInvalidControlFileException {
98 activeBookmark = null; 106 activeBookmark = null;
99 File active = repo.getRepositoryFile(HgRepositoryFiles.BookmarksCurrent); 107 File active = repo.getRepositoryFile(HgRepositoryFiles.BookmarksCurrent);
100 if (active.canRead() && active.isFile()) { 108 try {
101 LineReader lr2 = new LineReader(active, repo.getLog()); 109 if (active.canRead() && active.isFile()) {
102 ArrayList<String> c = new ArrayList<String>(2); 110 LineReader lr2 = new LineReader(active, repo.getLog());
103 lr2.read(new LineReader.SimpleLineCollector(), c); 111 ArrayList<String> c = new ArrayList<String>(2);
104 if (c.size() > 0) { 112 lr2.read(new LineReader.SimpleLineCollector(), c);
105 activeBookmark = c.get(0); 113 if (c.size() > 0) {
106 } 114 activeBookmark = c.get(0);
107 } 115 }
108 if (activeTracker == null) { 116 }
109 activeTracker = new FileChangeMonitor(active); 117 if (activeTracker == null) {
110 } 118 activeTracker = new FileChangeMonitor(active);
111 activeTracker.touch(this); 119 }
112 } 120 activeTracker.touch(this);
113 121 } catch (HgIOException ex) {
114 /*package-local*/void reloadIfChanged() throws HgInvalidControlFileException { 122 throw new HgInvalidControlFileException(ex, true);
123 }
124 }
125
126 /*package-local*/void reloadIfChanged() throws HgRuntimeException {
115 assert activeTracker != null; 127 assert activeTracker != null;
116 assert bmFileTracker != null; 128 assert bmFileTracker != null;
117 if (bmFileTracker.changed(this)) { 129 if (bmFileTracker.changed(this)) {
118 readBookmarks(); 130 readBookmarks();
119 } 131 }