Mercurial > jhg
diff src/org/tmatesoft/hg/internal/COWTransaction.java @ 635:4ec2d44e2bf3
Compound test scenario for checkout, add, remove, revert and commit
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 06 Jun 2013 18:42:38 +0200 |
parents | 99ad1e3a4e4d |
children | 12a4f60ea972 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/COWTransaction.java Thu Jun 06 14:21:11 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/COWTransaction.java Thu Jun 06 18:42:38 2013 +0200 @@ -46,19 +46,12 @@ @Override public File prepare(File f) throws HgIOException { - if (!f.exists()) { - record(f, null); - try { - f.getParentFile().mkdirs(); - f.createNewFile(); - return f; - } catch (IOException ex) { - throw new HgIOException("Failed to create new file", ex, f); - } - } if (known(f)) { return f; } + if (!f.exists()) { + return recordNonExistent(f); + } final File parentDir = f.getParentFile(); assert parentDir.canWrite(); File copy = new File(parentDir, f.getName() + ".hg4j.copy"); @@ -85,6 +78,9 @@ if (known(origin)) { return origin; } + if (!origin.exists()) { + return recordNonExistent(origin); + } fileHelper.copy(origin, backup); final RollbackEntry e = record(origin, backup); e.keepBackup = true; @@ -139,6 +135,17 @@ } } + private File recordNonExistent(File f) throws HgIOException { + record(f, null); + try { + f.getParentFile().mkdirs(); + f.createNewFile(); + return f; + } catch (IOException ex) { + throw new HgIOException("Failed to create new file", ex, f); + } + } + private RollbackEntry record(File origin, File backup) { final RollbackEntry e = new RollbackEntry(origin, backup); entries.add(e); @@ -146,23 +153,28 @@ } private boolean known(File f) { - for (RollbackEntry e : entries) { - if (e.origin.equals(f)) { - return true; - } + RollbackEntry e = lookup(f); + return e != null; + } + + private RollbackEntry find(File f) { + RollbackEntry e = lookup(f); + if (e != null) { + return e; } - return false; + assert false; + return new RollbackEntry(f,f); } - private RollbackEntry find(File f) { + + private RollbackEntry lookup(File f) { for (RollbackEntry e : entries) { if (e.origin.equals(f)) { return e; } } - assert false; - return new RollbackEntry(f,f); + return null; } - + private static class RollbackEntry { public final File origin; public final File backup; // may be null to indicate file didn't exist