comparison src/org/tmatesoft/hg/core/HgCatCommand.java @ 690:b286222158be

Fix file.isCopy() use for status and cat commands
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 01 Aug 2013 21:45:47 +0200
parents 98ff1fb49abe
children
comparison
equal deleted inserted replaced
689:5050ee565bd1 690:b286222158be
29 import org.tmatesoft.hg.repo.HgRuntimeException; 29 import org.tmatesoft.hg.repo.HgRuntimeException;
30 import org.tmatesoft.hg.util.Adaptable; 30 import org.tmatesoft.hg.util.Adaptable;
31 import org.tmatesoft.hg.util.ByteChannel; 31 import org.tmatesoft.hg.util.ByteChannel;
32 import org.tmatesoft.hg.util.CancelSupport; 32 import org.tmatesoft.hg.util.CancelSupport;
33 import org.tmatesoft.hg.util.CancelledException; 33 import org.tmatesoft.hg.util.CancelledException;
34 import org.tmatesoft.hg.util.Outcome;
34 import org.tmatesoft.hg.util.Path; 35 import org.tmatesoft.hg.util.Path;
35 36
36 /** 37 /**
37 * Command to obtain content of a file, 'hg cat' counterpart. 38 * Command to obtain content of a file, 'hg cat' counterpart.
38 * 39 *
169 // TODO may benefit from repo.getStoragePath to print revlog location in addition to human-friendly file path 170 // TODO may benefit from repo.getStoragePath to print revlog location in addition to human-friendly file path
170 throw new HgPathNotFoundException(String.format("File %s not found in the repository", file), file); 171 throw new HgPathNotFoundException(String.format("File %s not found in the repository", file), file);
171 } 172 }
172 int revToExtract; 173 int revToExtract;
173 if (cset != null) { 174 if (cset != null) {
174 int csetRev = repo.getChangelog().getRevisionIndex(cset); 175 // TODO HgChangesetFileSneaker is handy, but bit too much here, shall extract follow rename code into separate utility
175 Nodeid toExtract = null; 176 HgChangesetFileSneaker fsneaker = new HgChangesetFileSneaker(repo);
176 do { 177 fsneaker.changeset(cset).followRenames(true);
177 // TODO post-1.0 perhaps, HgChangesetFileSneaker may come handy? 178 Outcome o = fsneaker.check(file);
178 toExtract = repo.getManifest().getFileRevision(csetRev, file); 179 if (!o.isOk()) {
179 if (toExtract == null) { 180 if (o.getException() instanceof HgRuntimeException) {
180 if (dataFile.isCopy()) { 181 throw new HgLibraryFailureException(o.getMessage(), (HgRuntimeException) o.getException());
181 file = dataFile.getCopySourceName();
182 dataFile = repo.getFileNode(file);
183 } else {
184 break;
185 }
186 } 182 }
187 } while (toExtract == null); 183 throw new HgBadArgumentException(o.getMessage(), o.getException()).setFileName(file).setRevision(cset);
188 if (toExtract == null) { 184 }
189 String m = String.format("File %s nor its origins were known at repository's %s revision", file, cset.shortNotation()); 185 if (!fsneaker.exists()) {
190 throw new HgPathNotFoundException(m, file).setRevision(cset); 186 throw new HgPathNotFoundException(o.getMessage(), file).setRevision(cset);
187 }
188 Nodeid toExtract = fsneaker.revision();
189 if (fsneaker.hasAnotherName()) {
190 dataFile = repo.getFileNode(fsneaker.filename());
191 } 191 }
192 revToExtract = dataFile.getRevisionIndex(toExtract); 192 revToExtract = dataFile.getRevisionIndex(toExtract);
193 } else if (revision != null) { 193 } else if (revision != null) {
194 revToExtract = dataFile.getRevisionIndex(revision); 194 revToExtract = dataFile.getRevisionIndex(revision);
195 } else { 195 } else {