annotate hgfastimport/__init__.py @ 73:a99e5c6c8e1c

Fix compatibility with 4.6+ Update to work with hg 4.5+ Switch to modern @command decorator API Adds compatiblility with hg 4.2 Clean up formatting and add description Update to work with hg 3.4+ Update to work with hg 3.2+ This breaks compatibility with <3.2. Merged from patches from github:danielj7/hg-fastimport
author Daniel Johnson <daniel@daniel-johnson.org>
date Sun, 12 Aug 2018 07:54:35 -0400
parents 6b716ecb1cf3
children a4f13dc5e3f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
1 ''' import Git fast-import streams '''
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
2 from __future__ import absolute_import
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
3
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
4 from mercurial import (
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
5 cmdutil,
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
6 encoding,
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
7 util,
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
8 )
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
9
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
10 from mercurial.i18n import _
73
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
11
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
12 from hgext.convert import (
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
13 convcmd,
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
14 hg,
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
15 )
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
16
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
17 from .hgimport import fastimport_source
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
18
73
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
19 cmdtable = {}
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
20 try:
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
21 from mercurial import registrar
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
22 command = registrar.command(cmdtable)
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
23 except (ImportError, AttributeError):
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
24 command = cmdutil.command(cmdtable)
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
25
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
26 testedwith = '4.7'
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
27
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
28 @command("fastimport",
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
29 [('', 'branchsort', None, _('try to sort changesets by branches')),
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
30 ('', 'datesort', None, _('try to sort changesets by date')),
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
31 ('', 'sourcesort', None, _('preserve source changesets order'))],
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
32 _('hg fastimport SOURCE ...'),
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
33 norepo=False)
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
34
14
f6f0fd01b34a Preliminary support for reading multiple input files.
Greg Ward <greg-hg@gerg.ca>
parents: 1
diff changeset
35 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
36 """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
37
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
38 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
39 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
40 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
41 # 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
42 # 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
43 # little mismatched:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
44 # - 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
45 # produces 2 dump files)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
46 # - 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
47 #
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
48 # 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
49 # Boo, hiss.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
50
72
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
51 if not sources:
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
52 sources = ("-")
6b716ecb1cf3 Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents: 66
diff changeset
53
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
54 # 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
55 # encoded UTF-8
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
56 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
57 encoding.encoding = 'UTF-8'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
58
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
59 # sink is the current repo, src is the list of fastimport streams
73
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
60 destc = hg.mercurial_sink(ui, 'hg', repo.root)
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
61 srcc = fastimport_source(ui, 'fastimport', repo, sources)
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
62
50
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
63 # 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
64 defaultsort = 'branchsort' # for efficiency and consistency
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
65 sortmodes = ('branchsort', 'datesort', 'sourcesort')
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
66 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
67 if len(sortmode) > 1:
b027552d517b Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents: 47
diff changeset
68 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
69 sortmode = sortmode and sortmode[0] or defaultsort
73
a99e5c6c8e1c Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents: 72
diff changeset
70
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
71 # not implemented: filemap, revmapfile
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
72 revmapfile = destc.revmapfile()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
73 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
74 c.convert(sortmode)