comparison hgfastimport/__init__.py @ 47:7ff36dc9f0b1

Massive rework to use infrastructure provided by convert extension. fastimport no longer stages changes in the repository's working copy; instead, it now works like any other convert source: the imported history is kept in memory (except for file contents) and then processed by the 'convert' extension.
author Greg Ward <greg-hg@gerg.ca>
date Sat, 16 May 2009 12:57:22 -0400
parents 08e2157aaa9a
children b027552d517b
comparison
equal deleted inserted replaced
46:93c2b1e832bd 47:7ff36dc9f0b1
1 from mercurial import commands 1 from mercurial import encoding
2 from hgext.convert import convcmd, hg
2 3
3 from fastimport import parser 4 from fastimport import parser
4 import hgechoprocessor 5 from hgfastimport.hgimport import fastimport_source
5 import hgimport
6 6
7 def fastimport(ui, repo, *sources, **opts): 7 def fastimport(ui, repo, *sources, **opts):
8 proc = hgimport.HgImportProcessor(ui, repo, **opts) 8 """Convert a git fastimport dump into Mercurial changesets.
9 #proc = hgechoprocessor.HgEchoProcessor(ui, repo, **opts) 9
10 proc.setup() 10 Reads a series of SOURCE fastimport dumps and adds the resulting
11 try: 11 changes to the current Mercurial repository.
12 for source in sources: 12 """
13 ui.write("Reading source: %s\n" % source) 13 # Would be nice to just call hgext.convert.convcmd.convert() and let
14 f = open(source) 14 # it take care of things. But syntax and semantics are just a
15 p = parser.ImportParser(f) 15 # little mismatched:
16 proc.process(p.iter_commands) 16 # - fastimport takes multiple source paths (mainly because cvs2git
17 f.close() 17 # produces 2 dump files)
18 finally: 18 # - fastimport's dest is implicitly the current repo
19 proc.teardown() 19 #
20 # So for the time being, I have copied bits of convert() over here.
21 # Boo, hiss.
22
23 # assume fastimport metadata (usernames, commit messages) are
24 # encoded UTF-8
25 convcmd.orig_encoding = encoding.encoding
26 encoding.encoding = 'UTF-8'
27
28 # sink is the current repo, src is the list of fastimport streams
29 destc = hg.mercurial_sink(ui, repo.root)
30 srcc = fastimport_source(ui, repo, sources)
31
32 # TEMP hack to keep old behaviour and minimize test churn
33 # (this should be an option to fastimport)
34 opts['datesort'] = True
35
36 # not implemented: filemap, revmapfile
37 revmapfile = destc.revmapfile()
38 c = convcmd.converter(ui, srcc, destc, revmapfile, opts)
39 c.convert()
20 40
21 cmdtable = { 41 cmdtable = {
22 "fastimport": 42 "fastimport":
23 (fastimport, 43 (fastimport,
24 [], 44 [],