Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 10136:270367ec4d30
Merge with crew-stable
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 24 Dec 2009 00:01:13 +0100 |
parents | ef5b537433da 9a4034b630c4 |
children | c7355a0e1f39 |
comparison
equal
deleted
inserted
replaced
10134:821793e3049c | 10136:270367ec4d30 |
---|---|
292 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) | 292 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) |
293 | 293 |
294 self.hash = {} | 294 self.hash = {} |
295 self.dirty = 0 | 295 self.dirty = 0 |
296 self.offset = 0 | 296 self.offset = 0 |
297 self.skew = 0 | |
297 self.rej = [] | 298 self.rej = [] |
298 self.fileprinted = False | 299 self.fileprinted = False |
299 self.printfile(False) | 300 self.printfile(False) |
300 self.hunks = 0 | 301 self.hunks = 0 |
301 | 302 |
447 if h.starta == 0: | 448 if h.starta == 0: |
448 start = 0 | 449 start = 0 |
449 else: | 450 else: |
450 start = h.starta + self.offset - 1 | 451 start = h.starta + self.offset - 1 |
451 orig_start = start | 452 orig_start = start |
452 if diffhelpers.testhunk(old, self.lines, start) == 0: | 453 # if there's skew we want to emit the "(offset %d lines)" even |
454 # when the hunk cleanly applies at start + skew, so skip the | |
455 # fast case code | |
456 if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0: | |
453 if h.rmfile(): | 457 if h.rmfile(): |
454 self.unlink(self.fname) | 458 self.unlink(self.fname) |
455 else: | 459 else: |
456 self.lines[start : start + h.lena] = h.new() | 460 self.lines[start : start + h.lena] = h.new() |
457 self.offset += h.lenb - h.lena | 461 self.offset += h.lenb - h.lena |
463 if h.hunk[-1][0] != ' ': | 467 if h.hunk[-1][0] != ' ': |
464 # if the hunk tried to put something at the bottom of the file | 468 # if the hunk tried to put something at the bottom of the file |
465 # override the start line and use eof here | 469 # override the start line and use eof here |
466 search_start = len(self.lines) | 470 search_start = len(self.lines) |
467 else: | 471 else: |
468 search_start = orig_start | 472 search_start = orig_start + self.skew |
469 | 473 |
470 for fuzzlen in xrange(3): | 474 for fuzzlen in xrange(3): |
471 for toponly in [ True, False ]: | 475 for toponly in [ True, False ]: |
472 old = h.old(fuzzlen, toponly) | 476 old = h.old(fuzzlen, toponly) |
473 | 477 |
475 for l in cand: | 479 for l in cand: |
476 if diffhelpers.testhunk(old, self.lines, l) == 0: | 480 if diffhelpers.testhunk(old, self.lines, l) == 0: |
477 newlines = h.new(fuzzlen, toponly) | 481 newlines = h.new(fuzzlen, toponly) |
478 self.lines[l : l + len(old)] = newlines | 482 self.lines[l : l + len(old)] = newlines |
479 self.offset += len(newlines) - len(old) | 483 self.offset += len(newlines) - len(old) |
484 self.skew = l - orig_start | |
480 self.dirty = 1 | 485 self.dirty = 1 |
481 if fuzzlen: | 486 if fuzzlen: |
482 fuzzstr = "with fuzz %d " % fuzzlen | 487 fuzzstr = "with fuzz %d " % fuzzlen |
483 f = self.ui.warn | 488 f = self.ui.warn |
484 self.printfile(True) | 489 self.printfile(True) |