[PATCH] csplit support in hg import
TK Soh
teekaysoh at yahoo.com
Tue Aug 30 21:41:21 CDT 2005
# HG changeset patch
# User TK Soh <teekaysoh at yahoo.com>
# Node ID ccc7e7f97bce7379353dd191f3c698bc654ad467
# Parent a33a7a543803c7383a6918b19797bf9fd6b83e8e
add csplit support to import
Use -c option to instruct import to detech and split up
Mercurial-exported changsets in patch files and apply separately.
diff -r a33a7a543803 -r ccc7e7f97bce mercurial/commands.py
--- a/mercurial/commands.py Sun Aug 28 06:45:27 2005
+++ b/mercurial/commands.py Wed Aug 31 02:37:22 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,35 @@
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 = []
+ nodes = []
+ f = None
+ node = None
+ for line in file(pf):
+ if line.startswith("# HG changeset patch"):
+ if f:
+ f.close()
+ flist.append(tfile)
+ nodes.append(node)
+
+ tfile = tempfile.mktemp()
+ f = open(tfile, 'w')
+ f.write(line)
+ elif f:
+ if line.startswith("# Node ID "):
+ node = line[10:]
+ node = node.rstrip()
+ f.write(line)
+
+ if f:
+ f.close()
+ flist.append(tfile)
+ nodes.append(node)
+
+ return flist, nodes
+
+ def do_import(pf):
message = []
user = None
hgpatch = False
@@ -1004,6 +1029,27 @@
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 = []
+ if opts['csplit']:
+ csets, nodes = csplit(pf)
+
+ if csets:
+ try:
+ for cs, node in zip(csets, nodes):
+ ui.status("[Node ID %s]\n" % node)
+ 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"""
@@ -1579,6 +1625,7 @@
"import|patch":
(import_,
[('p', 'strip', 1, 'path strip'),
+ ('c', 'csplit', None, 'split changsets in patch files'),
('f', 'force', None, 'skip check for outstanding changes'),
('b', 'base', "", 'base path')],
"hg import [-f] [-p NUM] [-b BASE] PATCH..."),
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Mercurial
mailing list