Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgTags.java @ 535:d9c07e1432c4
Issue 42: tolerate lines in .hgtags that do not conform to its format specification
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 05 Feb 2013 15:54:37 +0100 |
parents | b3c16d1aede0 |
children | 5c68567b3645 |
comparison
equal
deleted
inserted
replaced
534:243202f1bda5 | 535:d9c07e1432c4 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011-2012 TMate Software Ltd | 2 * Copyright (c) 2011-2013 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; | |
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; | 20 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
20 | 21 |
21 import java.io.BufferedReader; | 22 import java.io.BufferedReader; |
22 import java.io.File; | 23 import java.io.File; |
23 import java.io.FileReader; | 24 import java.io.FileReader; |
29 import java.util.LinkedList; | 30 import java.util.LinkedList; |
30 import java.util.List; | 31 import java.util.List; |
31 import java.util.Map; | 32 import java.util.Map; |
32 import java.util.TreeMap; | 33 import java.util.TreeMap; |
33 | 34 |
35 import org.tmatesoft.hg.core.HgBadNodeidFormatException; | |
34 import org.tmatesoft.hg.core.Nodeid; | 36 import org.tmatesoft.hg.core.Nodeid; |
35 | 37 |
36 /** | 38 /** |
37 * @see http://mercurial.selenic.com/wiki/TagDesign | 39 * @see http://mercurial.selenic.com/wiki/TagDesign |
38 * | 40 * |
106 while ((line = reader.readLine()) != null) { | 108 while ((line = reader.readLine()) != null) { |
107 line = line.trim(); | 109 line = line.trim(); |
108 if (line.length() == 0) { | 110 if (line.length() == 0) { |
109 continue; | 111 continue; |
110 } | 112 } |
111 if (line.length() < 40+2 /*nodeid, space and at least single-char tagname*/) { | 113 final int spacePos = line.indexOf(' '); |
114 if (line.length() < 40+2 /*nodeid, space and at least single-char tagname*/ || spacePos != 40) { | |
112 repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); | 115 repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); |
113 continue; | 116 continue; |
114 } | 117 } |
115 int spacePos = line.indexOf(' '); | 118 try { |
116 if (spacePos != -1) { | |
117 assert spacePos == 40; | 119 assert spacePos == 40; |
118 final byte[] nodeidBytes = line.substring(0, spacePos).getBytes(); | 120 final byte[] nodeidBytes = line.substring(0, spacePos).getBytes(); |
119 Nodeid nid = Nodeid.fromAscii(nodeidBytes, 0, nodeidBytes.length); | 121 Nodeid nid = Nodeid.fromAscii(nodeidBytes, 0, nodeidBytes.length); |
120 String tagName = line.substring(spacePos+1); | 122 String tagName = line.substring(spacePos+1); |
121 List<Nodeid> nids = name2nid.get(tagName); | 123 List<Nodeid> nids = name2nid.get(tagName); |
149 nid2name.put(nid, revTags); | 151 nid2name.put(nid, revTags); |
150 } else if (!revTags.contains(tagName)) { | 152 } else if (!revTags.contains(tagName)) { |
151 // !contains because we don't care about order of the tags per revision | 153 // !contains because we don't care about order of the tags per revision |
152 revTags.add(tagName); | 154 revTags.add(tagName); |
153 } | 155 } |
154 | 156 } catch (HgBadNodeidFormatException ex) { |
155 } else { | 157 repo.getSessionContext().getLog().dump(getClass(), Error, "Bad revision '%s' in line '%s':%s", line.substring(0, spacePos), line, ex.getMessage()); |
156 repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); | |
157 } | 158 } |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 public List<String> tags(Nodeid nid) { | 162 public List<String> tags(Nodeid nid) { |