Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 214:2d60aa9bde0a
catch TERM signal in command processor
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
catch TERM signal in command processor
This keeps kill from interrupting a transaction without cleanup.
manifest hash: c50091696a3396dfed5c3168bd9e0d94c457a04b
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCniLNywK+sNU5EO8RAvepAKCCnEX7vPheIyOu2IvV6dDahdFMWACeMih6
E2R3rA/MGACxG9HpSNH6lak=
=HR1s
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Wed, 01 Jun 2005 13:04:13 -0800 |
parents | d2172916ef6c |
children | 8ff4532376a4 |
comparison
equal
deleted
inserted
replaced
213:d2172916ef6c | 214:2d60aa9bde0a |
---|---|
1 import os, re, traceback, sys | 1 import os, re, traceback, sys, signal |
2 from mercurial import fancyopts, ui, hg | 2 from mercurial import fancyopts, ui, hg |
3 | 3 |
4 class UnknownCommand(Exception): pass | 4 class UnknownCommand(Exception): pass |
5 | 5 |
6 def filterfiles(list, files): | 6 def filterfiles(list, files): |
157 if re.match(e + "$", cmd): | 157 if re.match(e + "$", cmd): |
158 return table[e] | 158 return table[e] |
159 | 159 |
160 raise UnknownCommand(cmd) | 160 raise UnknownCommand(cmd) |
161 | 161 |
162 class SignalInterrupt(Exception): pass | |
163 | |
164 def catchterm(*args): | |
165 raise SignalInterrupt | |
166 | |
162 def dispatch(args): | 167 def dispatch(args): |
163 options = {} | 168 options = {} |
164 opts = [('v', 'verbose', None, 'verbose'), | 169 opts = [('v', 'verbose', None, 'verbose'), |
165 ('d', 'debug', None, 'debug'), | 170 ('d', 'debug', None, 'debug'), |
166 ('q', 'quiet', None, 'quiet'), | 171 ('q', 'quiet', None, 'quiet'), |
179 not options["noninteractive"]) | 184 not options["noninteractive"]) |
180 | 185 |
181 # deal with unfound commands later | 186 # deal with unfound commands later |
182 i = find(cmd) | 187 i = find(cmd) |
183 | 188 |
189 signal.signal(signal.SIGTERM, catchterm) | |
190 | |
184 cmdoptions = {} | 191 cmdoptions = {} |
185 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) | 192 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
186 | 193 |
187 if cmd not in norepo.split(): | 194 if cmd not in norepo.split(): |
188 repo = hg.repository(ui = u) | 195 repo = hg.repository(ui = u) |
190 else: | 197 else: |
191 d = lambda: i[0](u, *args, **cmdoptions) | 198 d = lambda: i[0](u, *args, **cmdoptions) |
192 | 199 |
193 try: | 200 try: |
194 d() | 201 d() |
202 except SignalInterrupt: | |
203 u.warn("killed!\n") | |
195 except KeyboardInterrupt: | 204 except KeyboardInterrupt: |
196 u.warn("interrupted!\n") | 205 u.warn("interrupted!\n") |
197 except TypeError, inst: | 206 except TypeError, inst: |
198 # was this an argument error? | 207 # was this an argument error? |
199 tb = traceback.extract_tb(sys.exc_info()[2]) | 208 tb = traceback.extract_tb(sys.exc_info()[2]) |