Mercurial > hg
comparison contrib/simplemerge @ 33903:ed6f64173121
contrib: make simplemerge script pass context-like objects
`simplemerge()` will soon require context-like objects to work. Create a simple
context-like object that wraps the requested files and can be passed to the new
API.
Differential Revision: https://phab.mercurial-scm.org/D378
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Thu, 24 Aug 2017 21:30:37 -0700 |
parents | aed91971d88c |
children | fa6309c5761d |
comparison
equal
deleted
inserted
replaced
33902:f39ba8237ed6 | 33903:ed6f64173121 |
---|---|
47 '%s' % desc)) | 47 '%s' % desc)) |
48 opts_len = max([len(opt[0]) for opt in out_opts]) | 48 opts_len = max([len(opt[0]) for opt in out_opts]) |
49 for first, second in out_opts: | 49 for first, second in out_opts: |
50 sys.stdout.write(' %-*s %s\n' % (opts_len, first, second)) | 50 sys.stdout.write(' %-*s %s\n' % (opts_len, first, second)) |
51 | 51 |
52 class filebackedctx(object): | |
53 """simplemerge requires context-like objects""" | |
54 def __init__(self, path): | |
55 self._path = path | |
56 | |
57 def decodeddata(self): | |
58 with open(self._path, "rb") as f: | |
59 return f.read() | |
60 | |
61 def flags(self): | |
62 return '' | |
63 | |
64 def path(self): | |
65 return self._path | |
66 | |
67 def write(self, data, flags): | |
68 assert not flags | |
69 with open(self._path, "w") as f: | |
70 f.write(data) | |
71 | |
52 try: | 72 try: |
53 for fp in (sys.stdin, sys.stdout, sys.stderr): | 73 for fp in (sys.stdin, sys.stdout, sys.stderr): |
54 util.setbinary(fp) | 74 util.setbinary(fp) |
55 | 75 |
56 opts = {} | 76 opts = {} |
61 if opts['help']: | 81 if opts['help']: |
62 showhelp() | 82 showhelp() |
63 sys.exit(0) | 83 sys.exit(0) |
64 if len(args) != 3: | 84 if len(args) != 3: |
65 raise ParseError(_('wrong number of arguments')) | 85 raise ParseError(_('wrong number of arguments')) |
66 sys.exit(simplemerge.simplemerge(uimod.ui.load(), *args, **opts)) | 86 local, base, other = args |
87 sys.exit(simplemerge.simplemerge(uimod.ui.load(), | |
88 local, | |
89 base, | |
90 other, | |
91 filebackedctx(local), | |
92 filebackedctx(base), | |
93 filebackedctx(other), | |
94 filtereddata=True, | |
95 **opts)) | |
67 except ParseError as e: | 96 except ParseError as e: |
68 sys.stdout.write("%s: %s\n" % (sys.argv[0], e)) | 97 sys.stdout.write("%s: %s\n" % (sys.argv[0], e)) |
69 showhelp() | 98 showhelp() |
70 sys.exit(1) | 99 sys.exit(1) |
71 except error.Abort as e: | 100 except error.Abort as e: |