Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/RevlogStreamWriter.java @ 539:9edfd5a223b8
Commit: handle empty repository case
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 13 Feb 2013 18:44:58 +0100 |
parents | dd4f6311af52 |
children | 7f5998a9619d |
comparison
equal
deleted
inserted
replaced
538:dd4f6311af52 | 539:9edfd5a223b8 |
---|---|
92 revlogHeader.length(content.length, compressedLen); | 92 revlogHeader.length(content.length, compressedLen); |
93 revlogHeader.nodeid(revisionNodeidBytes); | 93 revlogHeader.nodeid(revisionNodeidBytes); |
94 revlogHeader.linkRevision(linkRevision); | 94 revlogHeader.linkRevision(linkRevision); |
95 revlogHeader.parents(p1, p2); | 95 revlogHeader.parents(p1, p2); |
96 revlogHeader.baseRevision(writeComplete ? lastEntryIndex+1 : lastEntryBase); | 96 revlogHeader.baseRevision(writeComplete ? lastEntryIndex+1 : lastEntryBase); |
97 revlogHeader.offset(revlogStream.newEntryOffset()); | 97 long lastEntryOffset = revlogStream.newEntryOffset(); |
98 revlogHeader.offset(lastEntryOffset); | |
98 // | 99 // |
99 revlogHeader.serialize(indexFile); | 100 revlogHeader.serialize(indexFile); |
100 | 101 |
101 if (isInlineData) { | 102 if (isInlineData) { |
102 dataFile = indexFile; | 103 dataFile = indexFile; |
112 } else { | 113 } else { |
113 dataFile.writeByte((byte) 'u'); | 114 dataFile.writeByte((byte) 'u'); |
114 dataSource.serialize(dataFile); | 115 dataSource.serialize(dataFile); |
115 } | 116 } |
116 | 117 |
118 | |
117 lastEntryContent = content; | 119 lastEntryContent = content; |
118 lastEntryBase = revlogHeader.baseRevision(); | 120 lastEntryBase = revlogHeader.baseRevision(); |
119 lastEntryIndex++; | 121 lastEntryIndex++; |
120 lastEntryRevision = Nodeid.fromBinary(revisionNodeidBytes, 0); | 122 lastEntryRevision = Nodeid.fromBinary(revisionNodeidBytes, 0); |
121 revisionCache.put(lastEntryIndex, lastEntryRevision); | 123 revisionCache.put(lastEntryIndex, lastEntryRevision); |
124 | |
125 revlogStream.revisionAdded(lastEntryIndex, lastEntryRevision, lastEntryBase, lastEntryOffset); | |
122 } catch (IOException ex) { | 126 } catch (IOException ex) { |
123 String m = String.format("Failed to write revision %d", lastEntryIndex+1, null); | 127 String m = String.format("Failed to write revision %d", lastEntryIndex+1, null); |
124 HgInvalidControlFileException t = new HgInvalidControlFileException(m, ex, null); | 128 HgInvalidControlFileException t = new HgInvalidControlFileException(m, ex, null); |
125 if (activeFile == dataFile) { | 129 if (activeFile == dataFile) { |
126 throw revlogStream.initWithDataFile(t); | 130 throw revlogStream.initWithDataFile(t); |
147 } | 151 } |
148 return n; | 152 return n; |
149 } | 153 } |
150 | 154 |
151 private void populateLastEntry() throws HgInvalidControlFileException { | 155 private void populateLastEntry() throws HgInvalidControlFileException { |
152 if (lastEntryIndex != NO_REVISION && lastEntryContent == null) { | 156 if (lastEntryContent != null) { |
157 return; | |
158 } | |
159 if (lastEntryIndex != NO_REVISION) { | |
153 assert lastEntryIndex >= 0; | 160 assert lastEntryIndex >= 0; |
154 final IOException[] failure = new IOException[1]; | 161 final IOException[] failure = new IOException[1]; |
155 revlogStream.iterate(lastEntryIndex, lastEntryIndex, true, new RevlogStream.Inspector() { | 162 revlogStream.iterate(lastEntryIndex, lastEntryIndex, true, new RevlogStream.Inspector() { |
156 | 163 |
157 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { | 164 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
166 }); | 173 }); |
167 if (failure[0] != null) { | 174 if (failure[0] != null) { |
168 String m = String.format("Failed to get content of most recent revision %d", lastEntryIndex); | 175 String m = String.format("Failed to get content of most recent revision %d", lastEntryIndex); |
169 throw revlogStream.initWithDataFile(new HgInvalidControlFileException(m, failure[0], null)); | 176 throw revlogStream.initWithDataFile(new HgInvalidControlFileException(m, failure[0], null)); |
170 } | 177 } |
178 } else { | |
179 lastEntryContent = new byte[0]; | |
171 } | 180 } |
172 } | 181 } |
173 | 182 |
174 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) { | 183 public static boolean preferCompleteOverPatch(int patchLength, int fullContentLength) { |
175 return !decideWorthEffort(patchLength, fullContentLength); | 184 return !decideWorthEffort(patchLength, fullContentLength); |
265 // assume 12 bytes left are zeros | 274 // assume 12 bytes left are zeros |
266 out.write(header.array(), 0, header.capacity()); | 275 out.write(header.array(), 0, header.capacity()); |
267 | 276 |
268 // regardless whether it's inline or separate data, | 277 // regardless whether it's inline or separate data, |
269 // offset field always represent cumulative compressedLength | 278 // offset field always represent cumulative compressedLength |
270 // (while offset in the index file with inline==true differs by n*sizeof(header), where n is entry's position in the file) | 279 // (while physical offset in the index file with inline==true differs by n*sizeof(header), where n is entry's position in the file) |
271 offset += compressedLength; | 280 offset += compressedLength; |
272 } | 281 } |
273 | 282 |
274 public int serializeLength() { | 283 public int serializeLength() { |
275 return header.capacity(); | 284 return header.capacity(); |