diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -974,7 +974,7 @@ def scangitpatch(lr, firstline): fp.seek(pos) return gitpatches -def iterhunks(ui, fp, sourcefile=None): +def iterhunks(ui, fp): """Read a patch and yield the following events: - ("file", afile, bfile, firsthunk): select a new target file. - ("hunk", hunk): a new hunk is ready to be applied, follows a @@ -1006,7 +1006,7 @@ def iterhunks(ui, fp, sourcefile=None): current_hunk.fix_newline() yield 'hunk', current_hunk current_hunk = None - if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or + if (state == BFILE and ((not context and x[0] == '@') or ((context is not False) and x.startswith('***************')))): if context is None and x.startswith('***************'): context = True @@ -1080,7 +1080,7 @@ def iterhunks(ui, fp, sourcefile=None): raise PatchError(_("malformed patch %s %s") % (afile, current_hunk.desc)) -def applydiff(ui, fp, changed, strip=1, sourcefile=None, eolmode='strict'): +def applydiff(ui, fp, changed, strip=1, eolmode='strict'): """Reads a patch from fp and tries to apply it. The dict 'changed' is filled in with all of the filenames changed @@ -1094,13 +1094,10 @@ def applydiff(ui, fp, changed, strip=1, Callers probably want to call 'cmdutil.updatedir' after this to apply certain categories of changes not done by this function. """ - return _applydiff( - ui, fp, patchfile, copyfile, - changed, strip=strip, sourcefile=sourcefile, eolmode=eolmode) + return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip, + eolmode=eolmode) - -def _applydiff(ui, fp, patcher, copyfn, changed, strip=1, - sourcefile=None, eolmode='strict'): +def _applydiff(ui, fp, patcher, copyfn, changed, strip=1, eolmode='strict'): rejects = 0 err = 0 current_file = None @@ -1115,7 +1112,7 @@ def _applydiff(ui, fp, patcher, copyfn, current_file.write_rej() return len(current_file.rej) - for state, values in iterhunks(ui, fp, sourcefile): + for state, values in iterhunks(ui, fp): if state == 'hunk': if not current_file: continue @@ -1128,14 +1125,10 @@ def _applydiff(ui, fp, patcher, copyfn, rejects += closefile() afile, bfile, first_hunk = values try: - if sourcefile: - current_file = patcher(ui, sourcefile, opener, - eolmode=eolmode) - else: - current_file, missing = selectfile(afile, bfile, - first_hunk, strip) - current_file = patcher(ui, current_file, opener, - missing=missing, eolmode=eolmode) + current_file, missing = selectfile(afile, bfile, + first_hunk, strip) + current_file = patcher(ui, current_file, opener, + missing=missing, eolmode=eolmode) except PatchError, err: ui.warn(str(err) + '\n') current_file = None