comparison src/org/tmatesoft/hg/core/HgCheckoutCommand.java @ 580:bd5926e24aa3

Respect unix flags for checkout/revert
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 19 Apr 2013 20:30:34 +0200
parents becd2a1310a2
children 0890628ed51e
comparison
equal deleted inserted replaced
579:36e36b926747 580:bd5926e24aa3
133 final CheckoutWorker worker = new CheckoutWorker(internalRepo); 133 final CheckoutWorker worker = new CheckoutWorker(internalRepo);
134 HgManifest.Inspector insp = new HgManifest.Inspector() { 134 HgManifest.Inspector insp = new HgManifest.Inspector() {
135 135
136 public boolean next(Nodeid nid, Path fname, Flags flags) { 136 public boolean next(Nodeid nid, Path fname, Flags flags) {
137 if (worker.next(nid, fname, flags)) { 137 if (worker.next(nid, fname, flags)) {
138 // new dirstate based on manifest 138 // Mercurial seems to write "n 0 -1 unset fname" on `hg --clean co -rev <earlier rev>`
139 dirstateBuilder.recordNormal(fname, flags, worker.getLastWrittenFileSize()); 139 // and the reason for 'force lookup' I suspect is a slight chance of simultaneous modification
140 // of the file by user that doesn't alter its size the very second dirstate is being written
141 // (or the file is being updated and the update brought in changes that didn't alter the file size -
142 // with size and timestamp set, later `hg status` won't notice these changes)
143
144 // However, as long as we use this class to write clean copies of the files, we can put all the fields
145 // right away.
146 int mtime = worker.getLastFileModificationTime();
147 // Manifest flags are chars (despite octal values `hg manifest --debug` displays),
148 // while dirstate keeps actual unix flags.
149 int fmode = worker.getLastFileMode();
150 dirstateBuilder.recordNormal(fname, fmode, mtime, worker.getLastFileSize());
140 return true; 151 return true;
141 } 152 }
142 return false; 153 return false;
143 } 154 }
144 155
183 194
184 static class CheckoutWorker { 195 static class CheckoutWorker {
185 private final Internals hgRepo; 196 private final Internals hgRepo;
186 private HgException failure; 197 private HgException failure;
187 private int lastWrittenFileSize; 198 private int lastWrittenFileSize;
199 private int lastFileMode;
200 private int lastFileModificationTime;
188 201
189 CheckoutWorker(Internals implRepo) { 202 CheckoutWorker(Internals implRepo) {
190 hgRepo = implRepo; 203 hgRepo = implRepo;
191 } 204 }
192 205
194 WorkingDirFileWriter workingDirWriter = null; 207 WorkingDirFileWriter workingDirWriter = null;
195 try { 208 try {
196 HgDataFile df = hgRepo.getRepo().getFileNode(fname); 209 HgDataFile df = hgRepo.getRepo().getFileNode(fname);
197 int fileRevIndex = df.getRevisionIndex(nid); 210 int fileRevIndex = df.getRevisionIndex(nid);
198 // check out files based on manifest 211 // check out files based on manifest
199 // FIXME links!
200 workingDirWriter = new WorkingDirFileWriter(hgRepo); 212 workingDirWriter = new WorkingDirFileWriter(hgRepo);
201 workingDirWriter.processFile(df, fileRevIndex); 213 workingDirWriter.processFile(df, fileRevIndex, flags);
202 lastWrittenFileSize = workingDirWriter.bytesWritten(); 214 lastWrittenFileSize = workingDirWriter.bytesWritten();
215 lastFileMode = workingDirWriter.fmode();
216 lastFileModificationTime = workingDirWriter.mtime();
203 return true; 217 return true;
204 } catch (IOException ex) { 218 } catch (IOException ex) {
205 failure = new HgIOException("Failed to write down file revision", ex, workingDirWriter.getDestinationFile()); 219 failure = new HgIOException("Failed to write down file revision", ex, workingDirWriter.getDestinationFile());
206 } catch (HgRuntimeException ex) { 220 } catch (HgRuntimeException ex) {
207 failure = new HgLibraryFailureException(ex); 221 failure = new HgLibraryFailureException(ex);
208 } 222 }
209 return false; 223 return false;
210 } 224 }
211 225
212 public int getLastWrittenFileSize() { 226 public int getLastFileMode() {
227 return lastFileMode;
228 }
229
230 public int getLastFileModificationTime() {
231 return lastFileModificationTime;
232 }
233
234 public int getLastFileSize() {
213 return lastWrittenFileSize; 235 return lastWrittenFileSize;
214 } 236 }
215 237
216 public void checkFailed() throws HgException { 238 public void checkFailed() throws HgException {
217 if (failure != null) { 239 if (failure != null) {