[PATCH] csplit support in hg import

TK Soh teekaysoh at yahoo.com
Wed Aug 31 18:58:44 CDT 2005


--- Bryan O'Sullivan <bos at serpentine.com> wrote:
> On Wed, 2005-08-31 at 08:37 -0700, TK Soh wrote:
> > +    for patch in patches:
> > +        ui.status("applying %s\n" % patch)
> > +        pf = os.path.join(d, patch)
> > +        splits = []
> > +        if opts['csplit']:
> > +            splits = splitpatch(pf)
> > +        if splits:
> > +            if len(splits) > 1:
> > +                ui.status("found %d Hg patches in %s\n" % (len(splits),
> pf))
> > +            try:
> > +                for spl in splits:
> > +                    do_import(spl)
> > +                    os.unlink(spl)
> > +            except:
> > +                for spl in splits:
> > +                    os.unlink(spl)
> > +                raise
> > +        else:
> > +            do_import(pf)
> 
> You're not cleaning up the temporary file if only one patch is
> generated.
> The inner try/except block should get hoisted up la level of scope, and
> get turned into try/finally.  You only need to clean up the temp files
> in one place.

It doesn't? It seemed to be okay when I just tried. Hmmm... Anyway, thanks for
the tip on using try/finally for cleaning up - nice feature indeed. All patches
can be found in the attached file.

# HG changeset patch
# User TK Soh <teekaysoh at yahoo.com>
# Node ID e0804332315a4de5555ad3a9bcd53a8a5a430c9b
# Parent  7f50b1afd7c8eefc8f2a2f230bfa38eb28f245ab
import: improved cleaning up of temp-files

diff -r 7f50b1afd7c8 -r e0804332315a mercurial/commands.py
--- a/mercurial/commands.py	Wed Aug 31 23:23:51 2005
+++ b/mercurial/commands.py	Wed Aug 31 23:52:51 2005
@@ -1031,11 +1031,9 @@
             try:
                 for spl in splits:
                     do_import(spl)
-                    os.unlink(spl)
-            except:
+            finally:
                 for spl in splits:
                     os.unlink(spl)
-                raise
         else:
             do_import(pf)
 


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hg-import.patch
Type: application/octet-stream
Size: 4927 bytes
Desc: 402038908-hg-import.patch
Url : http://www.selenic.com/pipermail/mercurial/attachments/20050831/34cbcc11/hg-import.obj


More information about the Mercurial mailing list