Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 9683:5c8651e2f5e0
patch: don't use mutable object as default argument
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sat, 31 Oct 2009 18:02:13 +0100 |
parents | bd70f645cfb0 |
children | 618af2034ca6 |
comparison
equal
deleted
inserted
replaced
9682:bd70f645cfb0 | 9683:5c8651e2f5e0 |
---|---|
1003 | 1003 |
1004 if rejects: | 1004 if rejects: |
1005 return -1 | 1005 return -1 |
1006 return err | 1006 return err |
1007 | 1007 |
1008 def diffopts(ui, opts={}, untrusted=False): | 1008 def diffopts(ui, opts=None, untrusted=False): |
1009 def get(key, name=None, getter=ui.configbool): | 1009 def get(key, name=None, getter=ui.configbool): |
1010 return (opts.get(key) or | 1010 return ((opts and opts.get(key)) or |
1011 getter('diff', name or key, None, untrusted=untrusted)) | 1011 getter('diff', name or key, None, untrusted=untrusted)) |
1012 return mdiff.diffopts( | 1012 return mdiff.diffopts( |
1013 text=opts.get('text'), | 1013 text=opts and opts.get('text'), |
1014 git=get('git'), | 1014 git=get('git'), |
1015 nodates=get('nodates'), | 1015 nodates=get('nodates'), |
1016 showfunc=get('show_function', 'showfunc'), | 1016 showfunc=get('show_function', 'showfunc'), |
1017 ignorews=get('ignore_all_space', 'ignorews'), | 1017 ignorews=get('ignore_all_space', 'ignorews'), |
1018 ignorewsamount=get('ignore_space_change', 'ignorewsamount'), | 1018 ignorewsamount=get('ignore_space_change', 'ignorewsamount'), |
1094 if code: | 1094 if code: |
1095 raise PatchError(_("patch command failed: %s") % | 1095 raise PatchError(_("patch command failed: %s") % |
1096 util.explain_exit(code)[0]) | 1096 util.explain_exit(code)[0]) |
1097 return fuzz | 1097 return fuzz |
1098 | 1098 |
1099 def internalpatch(patchobj, ui, strip, cwd, files={}, eolmode='strict'): | 1099 def internalpatch(patchobj, ui, strip, cwd, files=None, eolmode='strict'): |
1100 """use builtin patch to apply <patchobj> to the working directory. | 1100 """use builtin patch to apply <patchobj> to the working directory. |
1101 returns whether patch was applied with fuzz factor.""" | 1101 returns whether patch was applied with fuzz factor.""" |
1102 | 1102 |
1103 if files is None: | |
1104 files = {} | |
1103 if eolmode is None: | 1105 if eolmode is None: |
1104 eolmode = ui.config('patch', 'eol', 'strict') | 1106 eolmode = ui.config('patch', 'eol', 'strict') |
1105 try: | 1107 try: |
1106 eol = {'strict': None, 'crlf': '\r\n', 'lf': '\n'}[eolmode.lower()] | 1108 eol = {'strict': None, 'crlf': '\r\n', 'lf': '\n'}[eolmode.lower()] |
1107 except KeyError: | 1109 except KeyError: |
1121 os.chdir(curdir) | 1123 os.chdir(curdir) |
1122 if ret < 0: | 1124 if ret < 0: |
1123 raise PatchError | 1125 raise PatchError |
1124 return ret > 0 | 1126 return ret > 0 |
1125 | 1127 |
1126 def patch(patchname, ui, strip=1, cwd=None, files={}, eolmode='strict'): | 1128 def patch(patchname, ui, strip=1, cwd=None, files=None, eolmode='strict'): |
1127 """Apply <patchname> to the working directory. | 1129 """Apply <patchname> to the working directory. |
1128 | 1130 |
1129 'eolmode' specifies how end of lines should be handled. It can be: | 1131 'eolmode' specifies how end of lines should be handled. It can be: |
1130 - 'strict': inputs are read in binary mode, EOLs are preserved | 1132 - 'strict': inputs are read in binary mode, EOLs are preserved |
1131 - 'crlf': EOLs are ignored when patching and reset to CRLF | 1133 - 'crlf': EOLs are ignored when patching and reset to CRLF |
1135 | 1137 |
1136 Returns whether patch was applied with fuzz factor. | 1138 Returns whether patch was applied with fuzz factor. |
1137 """ | 1139 """ |
1138 patcher = ui.config('ui', 'patch') | 1140 patcher = ui.config('ui', 'patch') |
1139 args = [] | 1141 args = [] |
1142 if files is None: | |
1143 files = {} | |
1140 try: | 1144 try: |
1141 if patcher: | 1145 if patcher: |
1142 return externalpatch(patcher, args, patchname, ui, strip, cwd, | 1146 return externalpatch(patcher, args, patchname, ui, strip, cwd, |
1143 files) | 1147 files) |
1144 else: | 1148 else: |