annotate hgfastimport/__init__.py @ 72:6b716ecb1cf3

Allow empty source argument
author Dennis Schridde <devurandom@gmx.net>
date Fri, 13 Dec 2013 22:38:47 -0500
parents ae32828c68d7
children a99e5c6c8e1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
1 from mercurial import encoding
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
56
9275d497b7ea Use relative imports.
Greg Ward <gward@intelerad.com>
parents: 50
diff changeset
5 from 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
72
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
23 if not sources:
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
24 sources = ("-")
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
25
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
26 # 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
27 # encoded UTF-8
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
28 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
29 encoding.encoding = 'UTF-8'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
30
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
31 # 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
32 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
33 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
34
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
35 # 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
36 defaultsort = 'branchsort' # for efficiency and consistency
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
37 sortmodes = ('branchsort', 'datesort', 'sourcesort')
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
38 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
39 if len(sortmode) > 1:
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
40 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
41 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
42
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
43 # not implemented: filemap, revmapfile
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
44 revmapfile = destc.revmapfile()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
45 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
46 c.convert(sortmode)
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
47
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
48 # 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
49 cmdtable = {
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
50 "fastimport":
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
51 (fastimport,
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
52 [('', '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
53 ('', '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
54 ('', 'sourcesort', None, _('preserve source changesets order')),
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
55 ],
14
f6f0fd01b34a Preliminary support for reading multiple input files.
Greg Ward <greg-hg@gerg.ca>
parents: 1
diff changeset
56 'hg fastimport SOURCE ...')
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
57 }