mercurial/patch.py
changeset 5581 8a8c341bd292
parent 5547 777996744942
child 5649 a583117b536a
child 5669 a0eb8a418442
equal deleted inserted replaced
5549:f2f42262adbd 5581:8a8c341bd292
   883     context = None
   883     context = None
   884     lr = linereader(fp)
   884     lr = linereader(fp)
   885     dopatch = True
   885     dopatch = True
   886     gitworkdone = False
   886     gitworkdone = False
   887 
   887 
       
   888     def getpatchfile(afile, bfile, hunk):
       
   889          try:
       
   890              if sourcefile:
       
   891                  targetfile = patchfile(ui, sourcefile)
       
   892              else:
       
   893                  targetfile = selectfile(afile, bfile, hunk,
       
   894                                          strip, reverse)
       
   895                  targetfile = patchfile(ui, targetfile)
       
   896              return targetfile
       
   897          except PatchError, err:
       
   898              ui.warn(str(err) + '\n')
       
   899              return None
       
   900 
   888     while True:
   901     while True:
   889         newfile = False
   902         newfile = False
   890         x = lr.readline()
   903         x = lr.readline()
   891         if not x:
   904         if not x:
   892             break
   905             break
   910                 ui.debug(err)
   923                 ui.debug(err)
   911                 current_hunk = None
   924                 current_hunk = None
   912                 continue
   925                 continue
   913             hunknum += 1
   926             hunknum += 1
   914             if not current_file:
   927             if not current_file:
   915                 if sourcefile:
   928                 current_file = getpatchfile(afile, bfile, current_hunk)
   916                     current_file = patchfile(ui, sourcefile)
   929                 if not current_file:
   917                 else:
   930                     current_file, current_hunk = None, None
   918                     current_file = selectfile(afile, bfile, current_hunk,
   931                     rejects += 1
   919                                               strip, reverse)
   932                     continue
   920                     current_file = patchfile(ui, current_file)
       
   921         elif state == BFILE and x.startswith('GIT binary patch'):
   933         elif state == BFILE and x.startswith('GIT binary patch'):
   922             current_hunk = binhunk(changed[bfile[2:]][1])
   934             current_hunk = binhunk(changed[bfile[2:]][1])
       
   935             hunknum += 1
   923             if not current_file:
   936             if not current_file:
   924                 if sourcefile:
   937                 current_file = getpatchfile(afile, bfile, current_hunk)
   925                     current_file = patchfile(ui, sourcefile)
   938                 if not current_file:
   926                 else:
   939                     current_file, current_hunk = None, None
   927                     current_file = selectfile(afile, bfile, current_hunk,
   940                     rejects += 1
   928                                               strip, reverse)
   941                     continue
   929                     current_file = patchfile(ui, current_file)
       
   930             hunknum += 1
       
   931             current_hunk.extract(fp)
   942             current_hunk.extract(fp)
   932         elif x.startswith('diff --git'):
   943         elif x.startswith('diff --git'):
   933             # check for git diff, scanning the whole patch file if needed
   944             # check for git diff, scanning the whole patch file if needed
   934             m = gitre.match(x)
   945             m = gitre.match(x)
   935             if m:
   946             if m: