##// END OF EJS Templates
imerge: gussy up dispatcher to support subcommand opts....
Brendan Cully -
r5111:12930b97 default
parent child Browse files
Show More
@@ -7,7 +7,7 b' imerge - interactive merge'
7
7
8 from mercurial.i18n import _
8 from mercurial.i18n import _
9 from mercurial.node import *
9 from mercurial.node import *
10 from mercurial import commands, cmdutil, hg, merge, util
10 from mercurial import commands, cmdutil, fancyopts, hg, merge, util
11 import os, tarfile
11 import os, tarfile
12
12
13 class InvalidStateFileException(Exception): pass
13 class InvalidStateFileException(Exception): pass
@@ -135,27 +135,6 b' class Imerge(object):'
135 if p1.node() != dp[0] or p2.node() != dp[1]:
135 if p1.node() != dp[0] or p2.node() != dp[1]:
136 raise util.Abort('imerge state does not match working directory')
136 raise util.Abort('imerge state does not match working directory')
137
137
138 def status(self):
139 p1, p2 = self.wctx.parents()
140 self.ui.write('merging %s and %s\n' % \
141 (short(p1.node()), short(p2.node())))
142
143 if self.resolved:
144 self.ui.write('resolved:\n')
145 for fn in self.resolved:
146 self.ui.write(' %s\n' % fn)
147 remaining = [f for f in self.conflicts if f not in self.resolved]
148 if remaining:
149 self.ui.write('remaining:\n')
150 for fn in remaining:
151 (fd, fo) = self.conflicts[fn]
152 if fn == fo:
153 self.ui.write(' %s\n' % (fn,))
154 else:
155 self.ui.write(' %s (%s)\n' % (fn, fd))
156 else:
157 self.ui.write('all conflicts resolved\n')
158
159 def next(self):
138 def next(self):
160 remaining = self.remaining()
139 remaining = self.remaining()
161 return remaining and remaining[0]
140 return remaining and remaining[0]
@@ -202,7 +181,7 b' def load(im, source):'
202
181
203 rc = im.unpickle(source)
182 rc = im.unpickle(source)
204 if not rc:
183 if not rc:
205 im.status()
184 status(im)
206 return rc
185 return rc
207
186
208 def merge_(im, filename=None):
187 def merge_(im, filename=None):
@@ -236,8 +215,39 b' def resolve(im, *files):'
236 def save(im, dest):
215 def save(im, dest):
237 return im.pickle(dest)
216 return im.pickle(dest)
238
217
239 def status(im):
218 def status(im, **opts):
240 im.status()
219 if not opts.get('resolved') and not opts.get('unresolved'):
220 opts['resolved'] = True
221 opts['unresolved'] = True
222
223 if im.ui.verbose:
224 p1, p2 = [short(p.node()) for p in im.wctx.parents()]
225 im.ui.note(_('merging %s and %s\n') % (p1, p2))
226
227 conflicts = im.conflicts.keys()
228 conflicts.sort()
229 remaining = dict.fromkeys(im.remaining())
230 st = []
231 for fn in conflicts:
232 if opts.get('no_status'):
233 mode = ''
234 elif fn in remaining:
235 mode = 'U '
236 else:
237 mode = 'R '
238 if ((opts.get('resolved') and fn not in remaining)
239 or (opts.get('unresolved') and fn in remaining)):
240 st.append((mode, fn))
241 st.sort()
242 for (mode, fn) in st:
243 if im.ui.verbose:
244 fo, fd = im.conflicts[fn]
245 if fd != fn:
246 fn = '%s (%s)' % (fn, fd)
247 im.ui.write('%s%s\n' % (mode, fn))
248 if opts.get('unresolved') and not remaining:
249 im.ui.write(_('all conflicts resolved\n'))
250
241 return 0
251 return 0
242
252
243 def unresolve(im, *files):
253 def unresolve(im, *files):
@@ -246,13 +256,16 b' def unresolve(im, *files):'
246 return im.unresolve(files)
256 return im.unresolve(files)
247
257
248 subcmdtable = {
258 subcmdtable = {
249 'load': load,
259 'load': (load, []),
250 'merge': merge_,
260 'merge': (merge_, []),
251 'next': next,
261 'next': (next, []),
252 'resolve': resolve,
262 'resolve': (resolve, []),
253 'save': save,
263 'save': (save, []),
254 'status': status,
264 'status': (status,
255 'unresolve': unresolve
265 [('n', 'no-status', None, _('hide status prefix')),
266 ('', 'resolved', None, _('only show resolved conflicts')),
267 ('', 'unresolved', None, _('only show unresolved conflicts'))]),
268 'unresolve': (unresolve, [])
256 }
269 }
257
270
258 def dispatch(im, args, opts):
271 def dispatch(im, args, opts):
@@ -263,7 +276,7 b' def dispatch(im, args, opts):'
263 candidates.append(choice)
276 candidates.append(choice)
264 return candidates
277 return candidates
265
278
266 c, args = args[0], args[1:]
279 c, args = args[0], list(args[1:])
267 cmd = complete(c, subcmdtable.keys())
280 cmd = complete(c, subcmdtable.keys())
268 if not cmd:
281 if not cmd:
269 raise cmdutil.UnknownCommand('imerge ' + c)
282 raise cmdutil.UnknownCommand('imerge ' + c)
@@ -272,11 +285,15 b' def dispatch(im, args, opts):'
272 raise cmdutil.AmbiguousCommand('imerge ' + c, cmd)
285 raise cmdutil.AmbiguousCommand('imerge ' + c, cmd)
273 cmd = cmd[0]
286 cmd = cmd[0]
274
287
275 func = subcmdtable[cmd]
288 func, optlist = subcmdtable[cmd]
289 opts = {}
276 try:
290 try:
277 return func(im, *args)
291 args = fancyopts.fancyopts(args, optlist, opts)
292 return func(im, *args, **opts)
293 except fancyopts.getopt.GetoptError, inst:
294 raise cmdutil.ParseError('imerge', '%s: %s' % (cmd, inst))
278 except TypeError:
295 except TypeError:
279 raise cmdutil.ParseError('imerge', '%s: invalid arguments' % cmd)
296 raise cmdutil.ParseError('imerge', _('%s: invalid arguments') % cmd)
280
297
281 def imerge(ui, repo, *args, **opts):
298 def imerge(ui, repo, *args, **opts):
282 '''interactive merge
299 '''interactive merge
@@ -27,8 +27,8 b' hg imerge'
27 cat foo2
27 cat foo2
28 cat bar
28 cat bar
29
29
30 echo % status
30 echo % status -v
31 hg imerge st
31 hg -v imerge st
32
32
33 echo % next
33 echo % next
34 hg imerge next
34 hg imerge next
@@ -4,17 +4,14 b' 1 files updated, 0 files merged, 1 files'
4 % start imerge
4 % start imerge
5 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
6 (branch merge, don't forget to commit)
6 (branch merge, don't forget to commit)
7 merging e6da46716401 and 30d266f502e7
7 U foo
8 remaining:
9 foo (foo2)
10 foo
8 foo
11 bar
9 bar
12 bar
10 bar
13 bar
11 bar
14 % status
12 % status -v
15 merging e6da46716401 and 30d266f502e7
13 merging e6da46716401 and 30d266f502e7
16 remaining:
14 U foo (foo2)
17 foo (foo2)
18 % next
15 % next
19 foo
16 foo
20 % merge next
17 % merge next
@@ -30,9 +27,7 b' 2 files updated, 0 files merged, 1 files'
30 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
27 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
31 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
32 (branch merge, don't forget to commit)
29 (branch merge, don't forget to commit)
33 merging e6da46716401 and 30d266f502e7
30 R foo
34 resolved:
35 foo
36 all conflicts resolved
31 all conflicts resolved
37 foo
32 foo
38 changeset: 3:fa9a6defdcaf
33 changeset: 3:fa9a6defdcaf
General Comments 0
You need to be logged in to leave comments. Login now