# HG changeset patch # User Bryan O'Sullivan # Date 1185924485 25200 # Node ID a675f6d5d0690b35d228796616d709b243475165 # Parent c0417a319e395a3ca34bd6b636b3fe1a2125663b patch: make internal code a bit friendlier to use diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -142,7 +142,7 @@ GP_PATCH = 1 << 0 # we have to run pat GP_FILTER = 1 << 1 # there's some copy/rename operation GP_BINARY = 1 << 2 # there's a binary patch -def readgitpatch(fp, firstline): +def readgitpatch(fp, firstline=None): """extract git-style metadata about patches from """ class gitpatch: "op is one of ADD, DELETE, RENAME, MODIFY or COPY" @@ -156,7 +156,8 @@ def readgitpatch(fp, firstline): self.binary = False def reader(fp, firstline): - yield firstline + if firstline is not None: + yield firstline for line in fp: yield line @@ -278,10 +279,13 @@ def externalpatch(patcher, args, patchna util.explain_exit(code)[0]) return fuzz -def internalpatch(patchname, ui, strip, cwd, files): - """use builtin patch to apply to the working directory. +def internalpatch(patchobj, ui, strip, cwd, files={}): + """use builtin patch to apply to the working directory. returns whether patch was applied with fuzz factor.""" - fp = file(patchname, 'rb') + try: + fp = file(patchobj, 'rb') + except TypeError: + fp = patchobj if cwd: curdir = os.getcwd() os.chdir(cwd)