Show More
@@ -237,9 +237,7 b' class patchfile:' | |||
|
237 | 237 | self.missing = missing |
|
238 | 238 | if not missing: |
|
239 | 239 | try: |
|
240 |
|
|
|
241 | self.lines = fp.readlines() | |
|
242 | fp.close() | |
|
240 | self.lines = self.readlines(fname) | |
|
243 | 241 | self.exists = True |
|
244 | 242 | except IOError: |
|
245 | 243 | pass |
@@ -254,6 +252,23 b' class patchfile:' | |||
|
254 | 252 | self.printfile(False) |
|
255 | 253 | self.hunks = 0 |
|
256 | 254 | |
|
255 | def readlines(self, fname): | |
|
256 | fp = self.opener(fname, 'r') | |
|
257 | try: | |
|
258 | return fp.readlines() | |
|
259 | finally: | |
|
260 | fp.close() | |
|
261 | ||
|
262 | def writelines(self, fname, lines): | |
|
263 | fp = self.opener(fname, 'w') | |
|
264 | try: | |
|
265 | fp.writelines(lines) | |
|
266 | finally: | |
|
267 | fp.close() | |
|
268 | ||
|
269 | def unlink(self, fname): | |
|
270 | os.unlink(fname) | |
|
271 | ||
|
257 | 272 | def printfile(self, warn): |
|
258 | 273 | if self.fileprinted: |
|
259 | 274 | return |
@@ -304,25 +319,24 b' class patchfile:' | |||
|
304 | 319 | self.ui.warn( |
|
305 | 320 | _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % |
|
306 | 321 | (len(self.rej), self.hunks, fname)) |
|
307 | base = os.path.basename(self.fname) | |
|
308 | fp = self.opener(fname, 'w') | |
|
309 | fp.write("--- %s\n+++ %s\n" % (base, base)) | |
|
310 | for x in self.rej: | |
|
311 |
for |
|
|
312 |
f |
|
|
313 |
|
|
|
314 | fp.write("\n\ No newline at end of file\n") | |
|
315 | fp.close() | |
|
322 | ||
|
323 | def rejlines(): | |
|
324 | base = os.path.basename(self.fname) | |
|
325 | yield "--- %s\n+++ %s\n" % (base, base) | |
|
326 | for x in self.rej: | |
|
327 | for l in x.hunk: | |
|
328 | yield l | |
|
329 | if l[-1] != '\n': | |
|
330 | yield "\n\ No newline at end of file\n" | |
|
331 | ||
|
332 | self.writelines(fname, rejlines()) | |
|
316 | 333 | |
|
317 | 334 | def write(self, dest=None): |
|
318 | 335 | if not self.dirty: |
|
319 | 336 | return |
|
320 | 337 | if not dest: |
|
321 | 338 | dest = self.fname |
|
322 |
|
|
|
323 | for l in self.lines: | |
|
324 | fp.write(l) | |
|
325 | fp.close() | |
|
339 | self.writelines(dest, self.lines) | |
|
326 | 340 | |
|
327 | 341 | def close(self): |
|
328 | 342 | self.write() |
@@ -349,7 +363,7 b' class patchfile:' | |||
|
349 | 363 | |
|
350 | 364 | if isinstance(h, binhunk): |
|
351 | 365 | if h.rmfile(): |
|
352 |
|
|
|
366 | self.unlink(self.fname) | |
|
353 | 367 | else: |
|
354 | 368 | self.lines[:] = h.new() |
|
355 | 369 | self.offset += len(h.new()) |
@@ -366,7 +380,7 b' class patchfile:' | |||
|
366 | 380 | orig_start = start |
|
367 | 381 | if diffhelpers.testhunk(old, self.lines, start) == 0: |
|
368 | 382 | if h.rmfile(): |
|
369 |
|
|
|
383 | self.unlink(self.fname) | |
|
370 | 384 | else: |
|
371 | 385 | self.lines[start : start + h.lena] = h.new() |
|
372 | 386 | self.offset += h.lenb - h.lena |
General Comments 0
You need to be logged in to leave comments.
Login now