Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
634:170b6ecc890e | 635:4ec2d44e2bf3 |
---|---|
44 fileHelper = new FileUtils(ctxSource.getSessionContext().getLog()); | 44 fileHelper = new FileUtils(ctxSource.getSessionContext().getLog()); |
45 } | 45 } |
46 | 46 |
47 @Override | 47 @Override |
48 public File prepare(File f) throws HgIOException { | 48 public File prepare(File f) throws HgIOException { |
49 if (!f.exists()) { | |
50 record(f, null); | |
51 try { | |
52 f.getParentFile().mkdirs(); | |
53 f.createNewFile(); | |
54 return f; | |
55 } catch (IOException ex) { | |
56 throw new HgIOException("Failed to create new file", ex, f); | |
57 } | |
58 } | |
59 if (known(f)) { | 49 if (known(f)) { |
60 return f; | 50 return f; |
51 } | |
52 if (!f.exists()) { | |
53 return recordNonExistent(f); | |
61 } | 54 } |
62 final File parentDir = f.getParentFile(); | 55 final File parentDir = f.getParentFile(); |
63 assert parentDir.canWrite(); | 56 assert parentDir.canWrite(); |
64 File copy = new File(parentDir, f.getName() + ".hg4j.copy"); | 57 File copy = new File(parentDir, f.getName() + ".hg4j.copy"); |
65 fileHelper.copy(f, copy); | 58 fileHelper.copy(f, copy); |
82 | 75 |
83 @Override | 76 @Override |
84 public File prepare(File origin, File backup) throws HgIOException { | 77 public File prepare(File origin, File backup) throws HgIOException { |
85 if (known(origin)) { | 78 if (known(origin)) { |
86 return origin; | 79 return origin; |
80 } | |
81 if (!origin.exists()) { | |
82 return recordNonExistent(origin); | |
87 } | 83 } |
88 fileHelper.copy(origin, backup); | 84 fileHelper.copy(origin, backup); |
89 final RollbackEntry e = record(origin, backup); | 85 final RollbackEntry e = record(origin, backup); |
90 e.keepBackup = true; | 86 e.keepBackup = true; |
91 return origin; | 87 return origin; |
137 success.add(e); | 133 success.add(e); |
138 it.remove(); | 134 it.remove(); |
139 } | 135 } |
140 } | 136 } |
141 | 137 |
138 private File recordNonExistent(File f) throws HgIOException { | |
139 record(f, null); | |
140 try { | |
141 f.getParentFile().mkdirs(); | |
142 f.createNewFile(); | |
143 return f; | |
144 } catch (IOException ex) { | |
145 throw new HgIOException("Failed to create new file", ex, f); | |
146 } | |
147 } | |
148 | |
142 private RollbackEntry record(File origin, File backup) { | 149 private RollbackEntry record(File origin, File backup) { |
143 final RollbackEntry e = new RollbackEntry(origin, backup); | 150 final RollbackEntry e = new RollbackEntry(origin, backup); |
144 entries.add(e); | 151 entries.add(e); |
145 return e; | 152 return e; |
146 } | 153 } |
147 | 154 |
148 private boolean known(File f) { | 155 private boolean known(File f) { |
149 for (RollbackEntry e : entries) { | 156 RollbackEntry e = lookup(f); |
150 if (e.origin.equals(f)) { | 157 return e != null; |
151 return true; | 158 } |
152 } | 159 |
160 private RollbackEntry find(File f) { | |
161 RollbackEntry e = lookup(f); | |
162 if (e != null) { | |
163 return e; | |
153 } | 164 } |
154 return false; | 165 assert false; |
166 return new RollbackEntry(f,f); | |
155 } | 167 } |
156 private RollbackEntry find(File f) { | 168 |
169 private RollbackEntry lookup(File f) { | |
157 for (RollbackEntry e : entries) { | 170 for (RollbackEntry e : entries) { |
158 if (e.origin.equals(f)) { | 171 if (e.origin.equals(f)) { |
159 return e; | 172 return e; |
160 } | 173 } |
161 } | 174 } |
162 assert false; | 175 return null; |
163 return new RollbackEntry(f,f); | |
164 } | 176 } |
165 | 177 |
166 private static class RollbackEntry { | 178 private static class RollbackEntry { |
167 public final File origin; | 179 public final File origin; |
168 public final File backup; // may be null to indicate file didn't exist | 180 public final File backup; // may be null to indicate file didn't exist |
169 public boolean success = false; | 181 public boolean success = false; |
170 public IOException failure = null; | 182 public IOException failure = null; |