Mercurial > hg
comparison hgext/hbisect.py @ 2735:07026da25ed8
hbisect.py: don't rely on __del__ to write the current state.
This is yet another page of the "Thou shalt not do too much inside
__del__ methods" book, in the "demandload and __del__ don't go well
together" chapter.
The bisect extension is broken in 0.9.1:
$ hg bisect init
$ hg bisect bad
Fatal Python error: Interpreter not initialized (version mismatch?)
Aborted
(yes, I tripled checked my instalation to make sure the problem is not
there)
It's been broken since revision fe1689273f84 moved the import of the
binascii module into a demandload.
(In details: the first time that "hg bisect bad" (or good) is called,
there are still no revisions saved in .hg/bisect/*, so bisect.__init__
doesn't call hg.bin on anything. So, when we reach __del__, the
binascii module still hasn't been imported and we get that "nice"
message above.)
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 28 Jul 2006 21:20:41 -0300 |
parents | 1772852d7d14 |
children | 90a4181ca9ed |
comparison
equal
deleted
inserted
replaced
2734:0b7206a65325 | 2735:07026da25ed8 |
---|---|
48 if os.path.exists(os.path.join(self.path, self.bad_path)): | 48 if os.path.exists(os.path.join(self.path, self.bad_path)): |
49 r = self.opener(self.bad_path).read().splitlines() | 49 r = self.opener(self.bad_path).read().splitlines() |
50 if r: | 50 if r: |
51 self.badrev = hg.bin(r.pop(0)) | 51 self.badrev = hg.bin(r.pop(0)) |
52 | 52 |
53 def __del__(self): | 53 def write(self): |
54 if not os.path.isdir(self.path): | 54 if not os.path.isdir(self.path): |
55 return | 55 return |
56 f = self.opener(self.good_path, "w") | 56 f = self.opener(self.good_path, "w") |
57 f.write("\n".join([hg.hex(r) for r in self.goodrevs])) | 57 f.write("\n".join([hg.hex(r) for r in self.goodrevs])) |
58 if len(self.goodrevs) > 0: | 58 if len(self.goodrevs) > 0: |
286 ui.warn(_("bisect: Unknown sub-command\n")) | 286 ui.warn(_("bisect: Unknown sub-command\n")) |
287 return help_() | 287 return help_() |
288 if len(args) > bisectcmdtable[cmd][1]: | 288 if len(args) > bisectcmdtable[cmd][1]: |
289 ui.warn(_("bisect: Too many arguments\n")) | 289 ui.warn(_("bisect: Too many arguments\n")) |
290 return help_() | 290 return help_() |
291 return bisectcmdtable[cmd][0](*args) | 291 try: |
292 return bisectcmdtable[cmd][0](*args) | |
293 finally: | |
294 b.write() | |
292 | 295 |
293 cmdtable = { | 296 cmdtable = { |
294 "bisect": (bisect_run, [], _("hg bisect [help|init|reset|next|good|bad]")), | 297 "bisect": (bisect_run, [], _("hg bisect [help|init|reset|next|good|bad]")), |
295 #"bisect-test": (test, [], "hg bisect-test rev"), | 298 #"bisect-test": (test, [], "hg bisect-test rev"), |
296 } | 299 } |