##// END OF EJS Templates
mq: consistently use opts.get() to prevent potential KeyError
Christian Ebert -
r12281:d9cf0d1d default
parent child Browse files
Show More
@@ -771,7 +771,7 b' class queue(object):'
771 771 if opts.get('rev'):
772 772 if not self.applied:
773 773 raise util.Abort(_('no patches applied'))
774 revs = cmdutil.revrange(repo, opts['rev'])
774 revs = cmdutil.revrange(repo, opts.get('rev'))
775 775 if len(revs) > 1 and revs[0] > revs[1]:
776 776 revs.reverse()
777 777 revpatches = self._revpatches(repo, revs)
@@ -1831,9 +1831,9 b' def qimport(ui, repo, *filename, **opts)'
1831 1831 """
1832 1832 q = repo.mq
1833 1833 try:
1834 q.qimport(repo, filename, patchname=opts['name'],
1835 existing=opts['existing'], force=opts['force'], rev=opts['rev'],
1836 git=opts['git'])
1834 q.qimport(repo, filename, patchname=opts.get('name'),
1835 existing=opts.get('existing'), force=opts.get('force'),
1836 rev=opts.get('rev'), git=opts.get('git'))
1837 1837 finally:
1838 1838 q.save_dirty()
1839 1839
@@ -1876,7 +1876,7 b' def init(ui, repo, **opts):'
1876 1876
1877 1877 This command is deprecated. Without -c, it's implied by other relevant
1878 1878 commands. With -c, use :hg:`init --mq` instead."""
1879 return qinit(ui, repo, create=opts['create_repo'])
1879 return qinit(ui, repo, create=opts.get('create_repo'))
1880 1880
1881 1881 def clone(ui, source, dest=None, **opts):
1882 1882 '''clone main and patch repository at same time
@@ -1901,8 +1901,8 b' def clone(ui, source, dest=None, **opts)'
1901 1901 if dest is None:
1902 1902 dest = hg.defaultdest(source)
1903 1903 sr = hg.repository(hg.remoteui(ui, opts), ui.expandpath(source))
1904 if opts['patches']:
1905 patchespath = ui.expandpath(opts['patches'])
1904 if opts.get('patches'):
1905 patchespath = ui.expandpath(opts.get('patches'))
1906 1906 else:
1907 1907 patchespath = patchdir(sr)
1908 1908 try:
@@ -1925,20 +1925,20 b' def clone(ui, source, dest=None, **opts)'
1925 1925 pass
1926 1926 ui.note(_('cloning main repository\n'))
1927 1927 sr, dr = hg.clone(ui, sr.url(), dest,
1928 pull=opts['pull'],
1928 pull=opts.get('pull'),
1929 1929 rev=destrev,
1930 1930 update=False,
1931 stream=opts['uncompressed'])
1931 stream=opts.get('uncompressed'))
1932 1932 ui.note(_('cloning patch repository\n'))
1933 hg.clone(ui, opts['patches'] or patchdir(sr), patchdir(dr),
1934 pull=opts['pull'], update=not opts['noupdate'],
1935 stream=opts['uncompressed'])
1933 hg.clone(ui, opts.get('patches') or patchdir(sr), patchdir(dr),
1934 pull=opts.get('pull'), update=not opts.get('noupdate'),
1935 stream=opts.get('uncompressed'))
1936 1936 if dr.local():
1937 1937 if qbase:
1938 1938 ui.note(_('stripping applied patches from destination '
1939 1939 'repository\n'))
1940 1940 dr.mq.strip(dr, [qbase], update=False, backup=None)
1941 if not opts['noupdate']:
1941 if not opts.get('noupdate'):
1942 1942 ui.note(_('updating destination repository\n'))
1943 1943 hg.update(dr, dr.changelog.tip())
1944 1944
@@ -1954,7 +1954,7 b' def commit(ui, repo, *pats, **opts):'
1954 1954
1955 1955 def series(ui, repo, **opts):
1956 1956 """print the entire series file"""
1957 repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary'])
1957 repo.mq.qseries(repo, missing=opts.get('missing'), summary=opts.get('summary'))
1958 1958 return 0
1959 1959
1960 1960 def top(ui, repo, **opts):
@@ -2021,7 +2021,7 b' def new(ui, repo, patch, *args, **opts):'
2021 2021 """
2022 2022 msg = cmdutil.logmessage(opts)
2023 2023 def getmsg():
2024 return ui.edit(msg, opts['user'] or ui.username())
2024 return ui.edit(msg, opts.get('user') or ui.username())
2025 2025 q = repo.mq
2026 2026 opts['msg'] = msg
2027 2027 if opts.get('edit'):
@@ -2054,7 +2054,7 b' def refresh(ui, repo, *pats, **opts):'
2054 2054 """
2055 2055 q = repo.mq
2056 2056 message = cmdutil.logmessage(opts)
2057 if opts['edit']:
2057 if opts.get('edit'):
2058 2058 if not q.applied:
2059 2059 ui.write(_("no patches applied\n"))
2060 2060 return 1
@@ -2110,7 +2110,7 b' def fold(ui, repo, *files, **opts):'
2110 2110 q.check_localchanges(repo)
2111 2111
2112 2112 message = cmdutil.logmessage(opts)
2113 if opts['edit']:
2113 if opts.get('edit'):
2114 2114 if message:
2115 2115 raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
2116 2116
@@ -2144,7 +2144,7 b' def fold(ui, repo, *files, **opts):'
2144 2144 message.extend(msg)
2145 2145 message = '\n'.join(message)
2146 2146
2147 if opts['edit']:
2147 if opts.get('edit'):
2148 2148 message = ui.edit(message, user or ui.username())
2149 2149
2150 2150 diffopts = q.patchopts(q.diffopts(), *patches)
@@ -2157,9 +2157,9 b' def goto(ui, repo, patch, **opts):'
2157 2157 q = repo.mq
2158 2158 patch = q.lookup(patch)
2159 2159 if q.isapplied(patch):
2160 ret = q.pop(repo, patch, force=opts['force'])
2160 ret = q.pop(repo, patch, force=opts.get('force'))
2161 2161 else:
2162 ret = q.push(repo, patch, force=opts['force'])
2162 ret = q.push(repo, patch, force=opts.get('force'))
2163 2163 q.save_dirty()
2164 2164 return ret
2165 2165
@@ -2205,8 +2205,8 b' def guard(ui, repo, *args, **opts):'
2205 2205 applied = set(p.name for p in q.applied)
2206 2206 patch = None
2207 2207 args = list(args)
2208 if opts['list']:
2209 if args or opts['none']:
2208 if opts.get('list'):
2209 if args or opts.get('none'):
2210 2210 raise util.Abort(_('cannot mix -l/--list with options or arguments'))
2211 2211 for i in xrange(len(q.series)):
2212 2212 status(i)
@@ -2219,7 +2219,7 b' def guard(ui, repo, *args, **opts):'
2219 2219 patch = args.pop(0)
2220 2220 if patch is None:
2221 2221 raise util.Abort(_('no patch to work with'))
2222 if args or opts['none']:
2222 if args or opts.get('none'):
2223 2223 idx = q.find_series(patch)
2224 2224 if idx is None:
2225 2225 raise util.Abort(_('no patch named %s') % patch)
@@ -2276,9 +2276,9 b' def push(ui, repo, patch=None, **opts):'
2276 2276 q = repo.mq
2277 2277 mergeq = None
2278 2278
2279 if opts['merge']:
2280 if opts['name']:
2281 newpath = repo.join(opts['name'])
2279 if opts.get('merge'):
2280 if opts.get('name'):
2281 newpath = repo.join(opts.get('name'))
2282 2282 else:
2283 2283 newpath, i = lastsavename(q.path)
2284 2284 if not newpath:
@@ -2286,7 +2286,7 b' def push(ui, repo, patch=None, **opts):'
2286 2286 return 1
2287 2287 mergeq = queue(ui, repo.join(""), newpath)
2288 2288 ui.warn(_("merging with queue at: %s\n") % mergeq.path)
2289 ret = q.push(repo, patch, force=opts['force'], list=opts['list'],
2289 ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'),
2290 2290 mergeq=mergeq, all=opts.get('all'), move=opts.get('move'))
2291 2291 return ret
2292 2292
@@ -2298,14 +2298,14 b' def pop(ui, repo, patch=None, **opts):'
2298 2298 top of the stack.
2299 2299 """
2300 2300 localupdate = True
2301 if opts['name']:
2302 q = queue(ui, repo.join(""), repo.join(opts['name']))
2301 if opts.get('name'):
2302 q = queue(ui, repo.join(""), repo.join(opts.get('name')))
2303 2303 ui.warn(_('using patch queue: %s\n') % q.path)
2304 2304 localupdate = False
2305 2305 else:
2306 2306 q = repo.mq
2307 ret = q.pop(repo, patch, force=opts['force'], update=localupdate,
2308 all=opts['all'])
2307 ret = q.pop(repo, patch, force=opts.get('force'), update=localupdate,
2308 all=opts.get('all'))
2309 2309 q.save_dirty()
2310 2310 return ret
2311 2311
@@ -2379,8 +2379,8 b' def restore(ui, repo, rev, **opts):'
2379 2379 This command is deprecated, use rebase --mq instead."""
2380 2380 rev = repo.lookup(rev)
2381 2381 q = repo.mq
2382 q.restore(repo, rev, delete=opts['delete'],
2383 qupdate=opts['update'])
2382 q.restore(repo, rev, delete=opts.get('delete'),
2383 qupdate=opts.get('update'))
2384 2384 q.save_dirty()
2385 2385 return 0
2386 2386
@@ -2394,22 +2394,22 b' def save(ui, repo, **opts):'
2394 2394 if ret:
2395 2395 return ret
2396 2396 q.save_dirty()
2397 if opts['copy']:
2397 if opts.get('copy'):
2398 2398 path = q.path
2399 if opts['name']:
2400 newpath = os.path.join(q.basepath, opts['name'])
2399 if opts.get('name'):
2400 newpath = os.path.join(q.basepath, opts.get('name'))
2401 2401 if os.path.exists(newpath):
2402 2402 if not os.path.isdir(newpath):
2403 2403 raise util.Abort(_('destination %s exists and is not '
2404 2404 'a directory') % newpath)
2405 if not opts['force']:
2405 if not opts.get('force'):
2406 2406 raise util.Abort(_('destination %s exists, '
2407 2407 'use -f to force') % newpath)
2408 2408 else:
2409 2409 newpath = savename(path)
2410 2410 ui.warn(_("copy %s to %s\n") % (path, newpath))
2411 2411 util.copyfiles(path, newpath)
2412 if opts['empty']:
2412 if opts.get('empty'):
2413 2413 try:
2414 2414 os.unlink(q.join(q.status_path))
2415 2415 except:
@@ -2439,9 +2439,9 b' def strip(ui, repo, *revs, **opts):'
2439 2439 operation completes.
2440 2440 """
2441 2441 backup = 'all'
2442 if opts['backup']:
2442 if opts.get('backup'):
2443 2443 backup = 'strip'
2444 elif opts['nobackup']:
2444 elif opts.get('nobackup'):
2445 2445 backup = 'none'
2446 2446
2447 2447 cl = repo.changelog
@@ -2479,7 +2479,7 b' def strip(ui, repo, *revs, **opts):'
2479 2479 q.save_dirty()
2480 2480
2481 2481 repo.mq.strip(repo, list(rootnodes), backup=backup, update=update,
2482 force=opts['force'])
2482 force=opts.get('force'))
2483 2483 return 0
2484 2484
2485 2485 def select(ui, repo, *args, **opts):
@@ -2517,7 +2517,7 b' def select(ui, repo, *args, **opts):'
2517 2517
2518 2518 q = repo.mq
2519 2519 guards = q.active()
2520 if args or opts['none']:
2520 if args or opts.get('none'):
2521 2521 old_unapplied = q.unapplied(repo)
2522 2522 old_guarded = [i for i in xrange(len(q.applied)) if
2523 2523 not q.pushable(i)[0]]
@@ -2525,7 +2525,7 b' def select(ui, repo, *args, **opts):'
2525 2525 q.save_dirty()
2526 2526 if not args:
2527 2527 ui.status(_('guards deactivated\n'))
2528 if not opts['pop'] and not opts['reapply']:
2528 if not opts.get('pop') and not opts.get('reapply'):
2529 2529 unapplied = q.unapplied(repo)
2530 2530 guarded = [i for i in xrange(len(q.applied))
2531 2531 if not q.pushable(i)[0]]
@@ -2537,7 +2537,7 b' def select(ui, repo, *args, **opts):'
2537 2537 ui.status(_('number of guarded, applied patches has changed '
2538 2538 'from %d to %d\n') %
2539 2539 (len(old_guarded), len(guarded)))
2540 elif opts['series']:
2540 elif opts.get('series'):
2541 2541 guards = {}
2542 2542 noguards = 0
2543 2543 for gs in q.series_guards:
@@ -2564,9 +2564,9 b' def select(ui, repo, *args, **opts):'
2564 2564 ui.write(g, '\n')
2565 2565 else:
2566 2566 ui.write(_('no active guards\n'))
2567 reapply = opts['reapply'] and q.applied and q.appliedname(-1)
2567 reapply = opts.get('reapply') and q.applied and q.appliedname(-1)
2568 2568 popped = False
2569 if opts['pop'] or opts['reapply']:
2569 if opts.get('pop') or opts.get('reapply'):
2570 2570 for i in xrange(len(q.applied)):
2571 2571 pushable, reason = q.pushable(i)
2572 2572 if not pushable:
@@ -2601,9 +2601,9 b' def finish(ui, repo, *revrange, **opts):'
2601 2601 an upstream repository, or if you are about to push your changes
2602 2602 to upstream.
2603 2603 """
2604 if not opts['applied'] and not revrange:
2604 if not opts.get('applied') and not revrange:
2605 2605 raise util.Abort(_('no revisions specified'))
2606 elif opts['applied']:
2606 elif opts.get('applied'):
2607 2607 revrange = ('qbase::qtip',) + revrange
2608 2608
2609 2609 q = repo.mq
General Comments 0
You need to be logged in to leave comments. Login now