Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 16127:14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 16 Feb 2012 15:58:51 -0600 |
parents | 0c4bec9596d8 |
children | 1970e6f61009 |
comparison
equal
deleted
inserted
replaced
16126:0c4bec9596d8 | 16127:14dc2bbba6d2 |
---|---|
22 internals = {} | 22 internals = {} |
23 | 23 |
24 def internaltool(name, trymerge, onfailure=None): | 24 def internaltool(name, trymerge, onfailure=None): |
25 '''return a decorator for populating internal merge tool table''' | 25 '''return a decorator for populating internal merge tool table''' |
26 def decorator(func): | 26 def decorator(func): |
27 internals[name] = func | 27 fullname = 'internal:' + name |
28 func.__doc__ = "``%s``\n" % fullname + func.__doc__.strip() | |
29 internals[fullname] = func | |
28 func.trymerge = trymerge | 30 func.trymerge = trymerge |
29 func.onfailure = onfailure | 31 func.onfailure = onfailure |
30 return func | 32 return func |
31 return decorator | 33 return decorator |
32 | 34 |
129 if style: | 131 if style: |
130 newdata = data.replace(style, tostyle) | 132 newdata = data.replace(style, tostyle) |
131 if newdata != data: | 133 if newdata != data: |
132 util.writefile(file, newdata) | 134 util.writefile(file, newdata) |
133 | 135 |
134 @internaltool('internal:prompt', False) | 136 @internaltool('prompt', False) |
135 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): | 137 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): |
136 """``internal:prompt`` | 138 """Asks the user which of the local or the other version to keep as |
137 Asks the user which of the local or the other version to keep as | |
138 the merged version.""" | 139 the merged version.""" |
139 ui = repo.ui | 140 ui = repo.ui |
140 fd = fcd.path() | 141 fd = fcd.path() |
141 | 142 |
142 if ui.promptchoice(_(" no tool found to merge %s\n" | 143 if ui.promptchoice(_(" no tool found to merge %s\n" |
144 (_("&Local"), _("&Other")), 0): | 145 (_("&Local"), _("&Other")), 0): |
145 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf) | 146 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf) |
146 else: | 147 else: |
147 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) | 148 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) |
148 | 149 |
149 @internaltool('internal:local', False) | 150 @internaltool('local', False) |
150 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): | 151 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): |
151 """``internal:local`` | 152 """Uses the local version of files as the merged version.""" |
152 Uses the local version of files as the merged version.""" | |
153 return 0 | 153 return 0 |
154 | 154 |
155 @internaltool('internal:other', False) | 155 @internaltool('other', False) |
156 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): | 156 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): |
157 """``internal:other`` | 157 """Uses the other version of files as the merged version.""" |
158 Uses the other version of files as the merged version.""" | |
159 repo.wwrite(fcd.path(), fco.data(), fco.flags()) | 158 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
160 return 0 | 159 return 0 |
161 | 160 |
162 @internaltool('internal:fail', False) | 161 @internaltool('fail', False) |
163 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): | 162 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): |
164 """``internal:fail`` | 163 """ |
165 Rather than attempting to merge files that were modified on both | 164 Rather than attempting to merge files that were modified on both |
166 branches, it marks them as unresolved. The resolve command must be | 165 branches, it marks them as unresolved. The resolve command must be |
167 used to resolve these conflicts.""" | 166 used to resolve these conflicts.""" |
168 return 1 | 167 return 1 |
169 | 168 |
192 return 0 | 191 return 0 |
193 if premerge != 'keep': | 192 if premerge != 'keep': |
194 util.copyfile(back, a) # restore from backup and try again | 193 util.copyfile(back, a) # restore from backup and try again |
195 return 1 # continue merging | 194 return 1 # continue merging |
196 | 195 |
197 @internaltool('internal:merge', True, | 196 @internaltool('merge', True, |
198 _("merging %s incomplete! " | 197 _("merging %s incomplete! " |
199 "(edit conflicts, then use 'hg resolve --mark')\n")) | 198 "(edit conflicts, then use 'hg resolve --mark')\n")) |
200 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): | 199 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
201 """``internal:merge`` | 200 """ |
202 Uses the internal non-interactive simple merge algorithm for merging | 201 Uses the internal non-interactive simple merge algorithm for merging |
203 files. It will fail if there are any conflicts and leave markers in | 202 files. It will fail if there are any conflicts and leave markers in |
204 the partially merged file.""" | 203 the partially merged file.""" |
205 r = _premerge(repo, toolconf, files) | 204 r = _premerge(repo, toolconf, files) |
206 if r: | 205 if r: |
210 | 209 |
211 r = simplemerge.simplemerge(ui, a, b, c, label=['local', 'other']) | 210 r = simplemerge.simplemerge(ui, a, b, c, label=['local', 'other']) |
212 return True, r | 211 return True, r |
213 return False, 0 | 212 return False, 0 |
214 | 213 |
215 @internaltool('internal:dump', True) | 214 @internaltool('dump', True) |
216 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files): | 215 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
217 """``internal:dump`` | 216 """ |
218 Creates three versions of the files to merge, containing the | 217 Creates three versions of the files to merge, containing the |
219 contents of local, other and base. These files can then be used to | 218 contents of local, other and base. These files can then be used to |
220 perform a merge manually. If the file to be merged is named | 219 perform a merge manually. If the file to be merged is named |
221 ``a.txt``, these files will accordingly be named ``a.txt.local``, | 220 ``a.txt``, these files will accordingly be named ``a.txt.local``, |
222 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the | 221 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the |