importing file with multiple changset (Re: tcsh_completion.sh)

TK Soh teekaysoh at yahoo.com
Tue Aug 30 08:32:35 CDT 2005


--- TK Soh <teekaysoh at yahoo.com> wrote:
> --- Thomas Arendsen Hein <thomas at intevation.de> wrote:
> 
> > * TK Soh <teekaysoh at yahoo.com> [20050830 14:25]:
> > > --- Thomas Arendsen Hein <thomas at intevation.de> wrote:
> > > > Patches applied to tah and crew.
> > > 
> > > BTW, a little OT here, how do you import multiple changesets in a single
> > file -
> > > something I noticed in your tree after my patches? My understanding is
> that
> > > import would simply compress all changsets in the file and commit them as
> a
> > > single changeset. Earlier someone has raise the topic, where I suggested
> > using
> > > csplit.
> > 
> > I configured mutt to open attached patches with vim, there I saved
> > your mixed patches manually in two files each.
> > 
> > I think hg import can be extended to allow automatic splitting if
> > there are the magic hg changeset lines, but I don't think anyone is
> > working on this yet.
> 
> After the earlier discussion, I did a quick hack to added scplit into
> import_(). However, I am not sure about some of the design aspect - "how to
> split" being one of them. If I assume a clean patch file generated with
> export,
> then life would be a lot easier. But I understand import can sometime act on
> email with embedded patches.
> 
> Any thought?

I adopted your idea on detecting the magic hg changeset lines. Here's the diff
on the work. Another thing is that I am not sure if tempfile is supported on
other platform, especially Win32. Please comment, eventhough it's pretty rough
at this moment. 

diff -r 63b5f68d8167 mercurial/commands.py
--- a/mercurial/commands.py	Sun Aug 28 06:10:49 2005
+++ b/mercurial/commands.py	Tue Aug 30 21:26:36 2005
@@ -7,7 +7,7 @@
 
 from demandload import demandload
 from node import *
-demandload(globals(), "os re sys signal shutil imp")
+demandload(globals(), "os re sys signal shutil imp tempfile")
 demandload(globals(), "fancyopts ui hg util lock revlog")
 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
 demandload(globals(), "errno socket version struct atexit sets")
@@ -956,10 +956,29 @@
     d = opts["base"]
     strip = opts["strip"]
 
-    for patch in patches:
-        ui.status("applying %s\n" % patch)
-        pf = os.path.join(d, patch)
-
+    def csplit(pf):
+        flist = []
+        f = None
+        for line in file(pf):
+            if line.startswith("# HG changeset patch"):
+                if f:
+                    f.close()
+                    flist.append(tfile)
+
+                tfile = tempfile.mktemp()
+                f = open(tfile, 'w')
+                f.write(line)
+                ispatch = False
+            elif f:
+                f.write(line)
+
+        if f:
+            f.close()
+            flist.append(tfile)
+        
+        return flist                
+
+    def do_import(pf):
         message = []
         user = None
         hgpatch = False
@@ -1004,6 +1023,24 @@
         if len(files) > 0:
             addremove(ui, repo, *files)
         repo.commit(files, message, user)
+
+    for patch in patches:
+        ui.status("applying %s\n" % patch)
+        pf = os.path.join(d, patch)
+        csets = csplit(pf)
+        if csets:
+            try:
+                for i in range(len(csets)):
+                    cs = csets[i]
+                    ui.status("[changset #%d: %s]\n" %(i+1, cs))
+                    do_import(cs)
+                    os.unlink(cs)
+            except:
+                for cs in csets:
+                    os.unlink(cs)
+                raise
+        else:
+            do_import(pf)
 
 def incoming(ui, repo, source="default"):
     """show new changesets found in source"""



		
__________________________________ 
Yahoo! Mail 
Stay connected, organized, and protected. Take the tour: 
http://tour.mail.yahoo.com/mailtour.html 



More information about the Mercurial mailing list