[PATCH] Trivial - transaction destructor fix

Matt Mackall mpm at selenic.com
Sat Jul 2 16:17:02 CDT 2005


On Sat, Jul 02, 2005 at 09:49:18AM -0700, K Thananchayan wrote:
> > I think we want:
> > 
> > diff -r b9fee419a1bd mercurial/transaction.py
> > --- a/mercurial/transaction.py  Fri Jul  1 16:54:52
> > 2005
> > +++ b/mercurial/transaction.py  Fri Jul  1 09:59:03
> > 2005
> > @@ -31,9 +31,11 @@
> >          self.file = open(self.journal, "w")
> > 
> >      def __del__(self):
> > -        if self.entries: self.abort()
> > -        try: os.unlink(self.journal)
> > -        except: pass
> > +        if self.journal:
> > +            if self.entries: self.abort()
> > +            self.file.close()
> > +            try: os.unlink(self.journal)
> > +            except: pass
> > 
> >      def add(self, file, offset):
> >          if file in self.map: return
> > 
> > -- 
> > Mathematics is the supreme nostalgia of our time.
> > 
> 
> On the other hand, this version still raise exception
> if journal file already exists when tranaction is
> opened (object does not have attribute journal yet).

Are you sure?

class transaction:
    def __init__(self, opener, journal, after = None):
        self.journal = None

> This may also raise exception during destruction if 
> transaction is successfully closed already as file is
> not open.

Good spotting. That just means we need to add this to close():

diff -r cb7cd12e00f1 mercurial/transaction.py
--- a/mercurial/transaction.py  Sat Jul  2 20:45:53 2005
+++ b/mercurial/transaction.py  Sat Jul  2 14:15:14 2005
@@ -52,6 +52,7 @@
             util.rename(self.journal, self.after)
         else:
             os.unlink(self.journal)
+        self.journal = None

     def abort(self):
         if not self.entries: return

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial mailing list