Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGb86fc43e4b73: simplemerge: write merge result to the localctx, if passed
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| raise error.Abort(msg) | raise error.Abort(msg) | ||||
| return text | return text | ||||
| def simplemerge(ui, localfile, basefile, otherfile, | def simplemerge(ui, localfile, basefile, otherfile, | ||||
| localctx=None, basectx=None, otherctx=None, repo=None, **opts): | localctx=None, basectx=None, otherctx=None, repo=None, **opts): | ||||
| """Performs the simplemerge algorithm. | """Performs the simplemerge algorithm. | ||||
| {local|base|other}ctx are optional. If passed, they (local/base/other) will | {local|base|other}ctx are optional. If passed, they (local/base/other) will | ||||
| be read from. You should pass explicit labels in this mode since the default | be read from and the merge result written to (local). You should pass | ||||
| is to use the file paths.""" | explicit labels in this mode since the default is to use the file paths.""" | ||||
| def readfile(filename): | def readfile(filename): | ||||
| f = open(filename, "rb") | f = open(filename, "rb") | ||||
| text = f.read() | text = f.read() | ||||
| f.close() | f.close() | ||||
| return _verifytext(text, filename, ui, opts) | return _verifytext(text, filename, ui, opts) | ||||
| def readctx(ctx): | def readctx(ctx): | ||||
| if not ctx: | if not ctx: | ||||
| return None | return None | ||||
| if not repo: | if not repo: | ||||
| raise error.ProgrammingError('simplemerge: repo must be passed if ' | raise error.ProgrammingError('simplemerge: repo must be passed if ' | ||||
| 'using contexts') | 'using contexts') | ||||
| # `wwritedata` is used to get the post-filter data from `ctx` (i.e., | # `wwritedata` is used to get the post-filter data from `ctx` (i.e., | ||||
| # what would have been in the working copy). Since merges were run in | # what would have been in the working copy). Since merges were run in | ||||
| # the working copy, and thus used post-filter data, we do the same to | # the working copy, and thus used post-filter data, we do the same to | ||||
| # maintain behavior. | # maintain behavior. | ||||
| return repo.wwritedata(ctx.path(), | return repo.wwritedata(ctx.path(), | ||||
| _verifytext(ctx.data(), ctx.path(), ui, opts)) | _verifytext(ctx.data(), ctx.path(), ui, opts)) | ||||
| class ctxwriter(object): | |||||
| def __init__(self, ctx): | |||||
| self.ctx = ctx | |||||
| self.text = "" | |||||
| def write(self, text): | |||||
| self.text += text | |||||
| def close(self): | |||||
| self.ctx.write(self.text, self.ctx.flags()) | |||||
| mode = opts.get('mode','merge') | mode = opts.get('mode','merge') | ||||
| if mode == 'union': | if mode == 'union': | ||||
| name_a = None | name_a = None | ||||
| name_b = None | name_b = None | ||||
| name_base = None | name_base = None | ||||
| else: | else: | ||||
| name_a = localfile | name_a = localfile | ||||
| name_b = otherfile | name_b = otherfile | ||||
| try: | try: | ||||
| localtext = readctx(localctx) if localctx else readfile(localfile) | localtext = readctx(localctx) if localctx else readfile(localfile) | ||||
| basetext = readctx(basectx) if basectx else readfile(basefile) | basetext = readctx(basectx) if basectx else readfile(basefile) | ||||
| othertext = readctx(otherctx) if otherctx else readfile(otherfile) | othertext = readctx(otherctx) if otherctx else readfile(otherfile) | ||||
| except error.Abort: | except error.Abort: | ||||
| return 1 | return 1 | ||||
| if opts.get('print'): | |||||
| out = ui.fout | |||||
| elif localctx: | |||||
| out = ctxwriter(localctx) | |||||
| else: | |||||
| localfile = os.path.realpath(localfile) | localfile = os.path.realpath(localfile) | ||||
| if not opts.get('print'): | |||||
| opener = vfsmod.vfs(os.path.dirname(localfile)) | opener = vfsmod.vfs(os.path.dirname(localfile)) | ||||
| out = opener(os.path.basename(localfile), "w", atomictemp=True) | out = opener(os.path.basename(localfile), "w", atomictemp=True) | ||||
| else: | |||||
| out = ui.fout | |||||
| m3 = Merge3Text(basetext, localtext, othertext) | m3 = Merge3Text(basetext, localtext, othertext) | ||||
| extrakwargs = { | extrakwargs = { | ||||
| "localorother": opts.get("localorother", None), | "localorother": opts.get("localorother", None), | ||||
| 'minimize': True, | 'minimize': True, | ||||
| } | } | ||||
| if mode == 'union': | if mode == 'union': | ||||
| extrakwargs['start_marker'] = None | extrakwargs['start_marker'] = None | ||||