comparison hglib/client.py @ 46:ebcc5d7dd528

client: introduce merge handlers These can control the behaviour when Mercurial prompts what to do with regard to a specific file
author Idan Kamara <idankk86@gmail.com>
date Tue, 16 Aug 2011 23:58:24 +0300
parents 191855a9d813
children 94d2988e55b7
comparison
equal deleted inserted replaced
45:191855a9d813 46:ebcc5d7dd528
1 import subprocess, os, struct, cStringIO, collections, re 1 import subprocess, os, struct, cStringIO, collections, re
2 import hglib, error, util, templates 2 import hglib, error, util, templates, merge
3 3
4 from util import cmdbuilder 4 from util import cmdbuilder
5 5
6 class hgclient(object): 6 class hgclient(object):
7 inputfmt = '>I' 7 inputfmt = '>I'
440 out = self.rawcommand(args) 440 out = self.rawcommand(args)
441 out = out.split('\0')[:-1] 441 out = out.split('\0')[:-1]
442 442
443 return self._parserevs(out) 443 return self._parserevs(out)
444 444
445 def merge(self, rev=None, force=False, tool=None, cb=None): 445 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort):
446 """
447 merge working directory with another revision
448
449 cb can one of merge.handlers, or a function that gets a single argument
450 which are the contents of stdout. It should return one of the expected
451 choices (a single character).
452 """
446 # we can't really use --preview since merge doesn't support --template 453 # we can't really use --preview since merge doesn't support --template
447 args = cmdbuilder('merge', r=rev, f=force, t=tool) 454 args = cmdbuilder('merge', r=rev, f=force, t=tool)
448 455
449 self.rawcommand(args, prompt=cb) 456 prompt = None
457 if cb is merge.handlers.abort:
458 prompt = cb
459 elif cb is merge.handlers.noninteractive:
460 args.append('-y')
461 else:
462 prompt = lambda size, output: cb(output) + '\n'
463
464 self.rawcommand(args, prompt=prompt)
450 465
451 def move(self, source, dest, after=False, force=False, dryrun=False, 466 def move(self, source, dest, after=False, force=False, dryrun=False,
452 include=None, exclude=None): 467 include=None, exclude=None):
453 if not isinstance(source, list): 468 if not isinstance(source, list):
454 source = [source] 469 source = [source]