Mercurial > hg
changeset 5035:a675f6d5d069
patch: make internal code a bit friendlier to use
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 31 Jul 2007 16:28:05 -0700 |
parents | c0417a319e39 |
children | ca0d02222d6a |
files | mercurial/patch.py |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Tue Jul 31 16:28:05 2007 -0700 +++ b/mercurial/patch.py Tue Jul 31 16:28:05 2007 -0700 @@ -142,7 +142,7 @@ 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 <patchname>""" class gitpatch: "op is one of ADD, DELETE, RENAME, MODIFY or COPY" @@ -156,7 +156,8 @@ 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 @@ util.explain_exit(code)[0]) return fuzz -def internalpatch(patchname, ui, strip, cwd, files): - """use builtin patch to apply <patchname> to the working directory. +def internalpatch(patchobj, ui, strip, cwd, files={}): + """use builtin patch to apply <patchobj> 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)