Mercurial > hg > hg-fastimport
annotate hgext3rd/fastimport/__init__.py @ 79:59a9e4d0aa72
Move hgfastimport directory to hgext3rd/fastimport
This will allow hgrc to enable this extension like so:
[extensions]
fastimport =
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 18 Jan 2021 23:04:05 +0000 |
| parents | hgfastimport/__init__.py@a4f13dc5e3f7 |
| children | dc1d11466aa6 |
| 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 ( |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
5 commands, |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
6 encoding, |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
7 error, |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
8 pycompat, |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
9 ) |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
10 |
|
50
b027552d517b
Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents:
47
diff
changeset
|
11 from mercurial.i18n import _ |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
12 |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
13 from hgext.convert import ( |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
14 convcmd, |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
15 hg, |
|
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 |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
18 from .hgimport import fastimport_source |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
19 |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
20 testedwith = b'5.6.1' |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
21 minimumhgversion = b'4.1' |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
22 |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
23 cmdtable = {} |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
24 try: |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
25 from mercurial import registrar |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
26 command = registrar.command(cmdtable) |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
27 except (ImportError, AttributeError): |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
28 from mercurial import cmdutil |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
29 command = cmdutil.command(cmdtable) |
|
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
30 |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
31 @command(b'fastimport', |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
32 [(b'', b'branchsort', None, _(b'try to sort changesets by branches')), |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
33 (b'', b'datesort', None, _(b'try to sort changesets by date')), |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
34 (b'', b'sourcesort', None, _(b'preserve source changesets order'))], |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
35 _(b'hg fastimport SOURCE ...'), |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
36 norepo=False) |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
37 |
|
14
f6f0fd01b34a
Preliminary support for reading multiple input files.
Greg Ward <greg-hg@gerg.ca>
parents:
1
diff
changeset
|
38 def fastimport(ui, repo, *sources, **opts): |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
39 '''Convert a git fastimport dump into Mercurial changesets. |
|
47
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 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
|
42 changes to the current Mercurial repository. |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
43 ''' |
|
47
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
44 # 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
|
45 # 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
|
46 # little mismatched: |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
47 # - 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
|
48 # produces 2 dump files) |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
49 # - 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
|
50 # |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
51 # 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
|
52 # Boo, hiss. |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
53 |
|
72
6b716ecb1cf3
Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents:
66
diff
changeset
|
54 if not sources: |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
55 sources = (b'-') |
|
72
6b716ecb1cf3
Allow empty source argument
Dennis Schridde <devurandom@gmx.net>
parents:
66
diff
changeset
|
56 |
|
47
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
57 # 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
|
58 # encoded UTF-8 |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
59 convcmd.orig_encoding = encoding.encoding |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
60 encoding.encoding = b'UTF-8' |
|
47
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
61 |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
62 # sink is the current repo, src is the list of fastimport streams |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
63 destc = hg.mercurial_sink(ui, b'hg', repo.root) |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
64 srcc = fastimport_source(ui, b'fastimport', repo, sources) |
|
47
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
65 |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
66 opts = pycompat.byteskwargs(opts) |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
67 defaultsort = b'branchsort' # for efficiency and consistency |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
68 sortmodes = (b'branchsort', b'datesort', b'sourcesort') |
|
50
b027552d517b
Do sort options just like hgext.convert.
Greg Ward <greg-hg@gerg.ca>
parents:
47
diff
changeset
|
69 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
|
70 if len(sortmode) > 1: |
|
74
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
71 raise error.Abort(_(b'more than one sort mode specified')) |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
72 if sortmode: |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
73 sortmode = sortmode[0] |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
74 else: |
|
a4f13dc5e3f7
Support Mercurial 5.6 and Python-3.6
Roy Marples <roy@marples.name>
parents:
73
diff
changeset
|
75 sortmode = defaultsort |
|
73
a99e5c6c8e1c
Fix compatibility with 4.6+
Daniel Johnson <daniel@daniel-johnson.org>
parents:
72
diff
changeset
|
76 |
|
47
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
77 # not implemented: filemap, revmapfile |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
78 revmapfile = destc.revmapfile() |
|
7ff36dc9f0b1
Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
79 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
|
80 c.convert(sortmode) |
