annotate hgfastimport/__init__.py @ 62:76bd0ea8add3

Update to cope with API differences.
author Jelmer Vernooij <jelmer@samba.org>
date Thu, 10 Nov 2011 23:09:10 +0100
parents b027552d517b
children ae32828c68d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62
76bd0ea8add3 Update to cope with API differences.
Jelmer Vernooij <jelmer@samba.org>
parents: 50
diff changeset
1 from mercurial import encoding, util
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
2 from mercurial.i18n import _
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
3 from hgext.convert import convcmd, hg
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
4
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
5 from hgfastimport.hgimport import fastimport_source
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
6
14
f6f0fd01b34a Preliminary support for reading multiple input files.
Greg Ward <greg-hg@gerg.ca>
parents: 1
diff changeset
7 def fastimport(ui, repo, *sources, **opts):
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
8 """Convert a git fastimport dump into Mercurial changesets.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
9
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
10 Reads a series of SOURCE fastimport dumps and adds the resulting
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
11 changes to the current Mercurial repository.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
12 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
13 # Would be nice to just call hgext.convert.convcmd.convert() and let
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
14 # it take care of things. But syntax and semantics are just a
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
15 # little mismatched:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
16 # - fastimport takes multiple source paths (mainly because cvs2git
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
17 # produces 2 dump files)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
18 # - fastimport's dest is implicitly the current repo
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
19 #
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
20 # So for the time being, I have copied bits of convert() over here.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
21 # Boo, hiss.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
22
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
23 # assume fastimport metadata (usernames, commit messages) are
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
24 # encoded UTF-8
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
25 convcmd.orig_encoding = encoding.encoding
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
26 encoding.encoding = 'UTF-8'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
27
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
28 # sink is the current repo, src is the list of fastimport streams
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
29 destc = hg.mercurial_sink(ui, repo.root)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
30 srcc = fastimport_source(ui, repo, sources)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
31
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
32 # XXX figuring out sortmode copied straight from hgext/convert/convcmd.py
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
33 defaultsort = 'branchsort' # for efficiency and consistency
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
34 sortmodes = ('branchsort', 'datesort', 'sourcesort')
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
35 sortmode = [m for m in sortmodes if opts.get(m)]
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
36 if len(sortmode) > 1:
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
37 raise util.Abort(_('more than one sort mode specified'))
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
38 sortmode = sortmode and sortmode[0] or defaultsort
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
39
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
40 # not implemented: filemap, revmapfile
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
41 revmapfile = destc.revmapfile()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
42 c = convcmd.converter(ui, srcc, destc, revmapfile, opts)
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
43 c.convert(sortmode)
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
44
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
45 # XXX sort options copied straight from hgext/convert/__init__.py
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
46 cmdtable = {
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
47 "fastimport":
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
48 (fastimport,
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
49 [('', 'branchsort', None, _('try to sort changesets by branches')),
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
50 ('', 'datesort', None, _('try to sort changesets by date')),
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
51 ('', 'sourcesort', None, _('preserve source changesets order')),
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
52 ],
14
f6f0fd01b34a Preliminary support for reading multiple input files.
Greg Ward <greg-hg@gerg.ca>
parents: 1
diff changeset
53 'hg fastimport SOURCE ...')
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
54 }