author | Thomas Arendsen Hein <thomas@intevation.de> |
Thu, 19 Jul 2007 07:28:27 +0200 | |
changeset 4943 | 9af1b47fe585 |
parent 4924 | ad09ce1d393c |
child 4957 | cdd33a048289 |
permissions | -rw-r--r-- |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
1 |
# convert.py Foreign SCM converter |
3917
645e1dd4b8ae
convert-repo: update usage information
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3911
diff
changeset
|
2 |
# |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4591
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
316 | 4 |
# |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
5 |
# This software may be used and distributed according to the terms |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
6 |
# of the GNU General Public License, incorporated herein by reference. |
316 | 7 |
|
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
8 |
from common import NoRepo, converter_source, converter_sink |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
9 |
from cvs import convert_cvs |
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
10 |
from git import convert_git |
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
11 |
from hg import convert_mercurial |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
12 |
from subversion import convert_svn |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
13 |
|
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
14 |
import os, shutil |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
15 |
from mercurial import hg, ui, util, commands |
3821
158fce02dc40
Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents:
2657
diff
changeset
|
16 |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
17 |
commands.norepo += " convert" |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
18 |
|
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
19 |
converters = [convert_cvs, convert_git, convert_svn, convert_mercurial] |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
20 |
|
4780
169fe1e6104c
convert: make convertsource option handling transparent
Brendan Cully <brendan@kublai.com>
parents:
4766
diff
changeset
|
21 |
def convertsource(ui, path, **opts): |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
22 |
for c in converters: |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
23 |
if not hasattr(c, 'getcommit'): |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
24 |
continue |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
25 |
try: |
4780
169fe1e6104c
convert: make convertsource option handling transparent
Brendan Cully <brendan@kublai.com>
parents:
4766
diff
changeset
|
26 |
return c(ui, path, **opts) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
27 |
except NoRepo: |
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
28 |
pass |
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
29 |
raise util.Abort('%s: unknown repository type' % path) |
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
30 |
|
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
31 |
def convertsink(ui, path): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
32 |
if not os.path.isdir(path): |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
33 |
raise util.Abort("%s: not a directory" % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
34 |
for c in converters: |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
35 |
if not hasattr(c, 'putcommit'): |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
36 |
continue |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
37 |
try: |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
38 |
return c(ui, path) |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
39 |
except NoRepo: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
40 |
pass |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
41 |
raise util.Abort('%s: unknown repository type' % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
42 |
|
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
43 |
class convert(object): |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
44 |
def __init__(self, ui, source, dest, mapfile, opts): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
45 |
|
316 | 46 |
self.source = source |
47 |
self.dest = dest |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
48 |
self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
49 |
self.opts = opts |
316 | 50 |
self.commitcache = {} |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
51 |
self.mapfile = mapfile |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
52 |
self.mapfilefd = None |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
53 |
self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
54 |
self.authorfile = None |
316 | 55 |
|
56 |
self.map = {} |
|
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
57 |
try: |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
58 |
origmapfile = open(self.mapfile, 'r') |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
59 |
for l in origmapfile: |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
60 |
sv, dv = l[:-1].split() |
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
61 |
self.map[sv] = dv |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
62 |
origmapfile.close() |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
63 |
except IOError: |
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
64 |
pass |
316 | 65 |
|
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
66 |
# Read first the dst author map if any |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
67 |
authorfile = self.dest.authorfile() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
68 |
if authorfile and os.path.exists(authorfile): |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
69 |
self.readauthormap(authorfile) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
70 |
# Extend/Override with new author map if necessary |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
71 |
if opts.get('authors'): |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
72 |
self.readauthormap(opts.get('authors')) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
73 |
self.authorfile = self.dest.authorfile() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
74 |
|
316 | 75 |
def walktree(self, heads): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
76 |
'''Return a mapping that identifies the uncommitted parents of every |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
77 |
uncommitted changeset.''' |
316 | 78 |
visit = heads |
79 |
known = {} |
|
80 |
parents = {} |
|
81 |
while visit: |
|
82 |
n = visit.pop(0) |
|
83 |
if n in known or n in self.map: continue |
|
84 |
known[n] = 1 |
|
85 |
self.commitcache[n] = self.source.getcommit(n) |
|
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
86 |
cp = self.commitcache[n].parents |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
87 |
parents[n] = [] |
316 | 88 |
for p in cp: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
89 |
parents[n].append(p) |
316 | 90 |
visit.append(p) |
91 |
||
92 |
return parents |
|
93 |
||
94 |
def toposort(self, parents): |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
95 |
'''Return an ordering such that every uncommitted changeset is |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
96 |
preceeded by all its uncommitted ancestors.''' |
316 | 97 |
visit = parents.keys() |
98 |
seen = {} |
|
99 |
children = {} |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
100 |
|
316 | 101 |
while visit: |
102 |
n = visit.pop(0) |
|
103 |
if n in seen: continue |
|
104 |
seen[n] = 1 |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
105 |
# Ensure that nodes without parents are present in the 'children' |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
106 |
# mapping. |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
107 |
children.setdefault(n, []) |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
108 |
for p in parents[n]: |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
109 |
if not p in self.map: |
316 | 110 |
visit.append(p) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
111 |
children.setdefault(p, []).append(n) |
316 | 112 |
|
113 |
s = [] |
|
114 |
removed = {} |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
115 |
visit = children.keys() |
316 | 116 |
while visit: |
117 |
n = visit.pop(0) |
|
118 |
if n in removed: continue |
|
119 |
dep = 0 |
|
120 |
if n in parents: |
|
121 |
for p in parents[n]: |
|
122 |
if p in self.map: continue |
|
123 |
if p not in removed: |
|
124 |
# we're still dependent |
|
125 |
visit.append(n) |
|
126 |
dep = 1 |
|
127 |
break |
|
128 |
||
129 |
if not dep: |
|
130 |
# all n's parents are in the list |
|
131 |
removed[n] = 1 |
|
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
132 |
if n not in self.map: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
133 |
s.append(n) |
316 | 134 |
if n in children: |
135 |
for c in children[n]: |
|
136 |
visit.insert(0, c) |
|
137 |
||
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
138 |
if self.opts.get('datesort'): |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
139 |
depth = {} |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
140 |
for n in s: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
141 |
depth[n] = 0 |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
142 |
pl = [p for p in self.commitcache[n].parents |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
143 |
if p not in self.map] |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
144 |
if pl: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
145 |
depth[n] = max([depth[p] for p in pl]) + 1 |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
146 |
|
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
147 |
s = [(depth[n], self.commitcache[n].date, n) for n in s] |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
148 |
s.sort() |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
149 |
s = [e[2] for e in s] |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
150 |
|
316 | 151 |
return s |
152 |
||
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
153 |
def mapentry(self, src, dst): |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
154 |
if self.mapfilefd is None: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
155 |
try: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
156 |
self.mapfilefd = open(self.mapfile, "a") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
157 |
except IOError, (errno, strerror): |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
158 |
raise util.Abort("Could not open map file %s: %s, %s\n" % (self.mapfile, errno, strerror)) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
159 |
self.map[src] = dst |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
160 |
self.mapfilefd.write("%s %s\n" % (src, dst)) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
161 |
self.mapfilefd.flush() |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
162 |
|
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
163 |
def writeauthormap(self): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
164 |
authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
165 |
if authorfile: |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
166 |
self.ui.status('Writing author map file %s\n' % authorfile) |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
167 |
ofile = open(authorfile, 'w+') |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
168 |
for author in self.authors: |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
169 |
ofile.write("%s=%s\n" % (author, self.authors[author])) |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
170 |
ofile.close() |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
171 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
172 |
def readauthormap(self, authorfile): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
173 |
afile = open(authorfile, 'r') |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
174 |
for line in afile: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
175 |
try: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
176 |
srcauthor = line.split('=')[0].strip() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
177 |
dstauthor = line.split('=')[1].strip() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
178 |
if srcauthor in self.authors and dstauthor != self.authors[srcauthor]: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
179 |
self.ui.status( |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
180 |
'Overriding mapping for author %s, was %s, will be %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
181 |
% (srcauthor, self.authors[srcauthor], dstauthor)) |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
182 |
else: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
183 |
self.ui.debug('Mapping author %s to %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
184 |
% (srcauthor, dstauthor)) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
185 |
self.authors[srcauthor] = dstauthor |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
186 |
except IndexError: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
187 |
self.ui.warn( |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
188 |
'Ignoring bad line in author file map %s: %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
189 |
% (authorfile, line)) |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
190 |
afile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
191 |
|
316 | 192 |
def copy(self, rev): |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
193 |
c = self.commitcache[rev] |
316 | 194 |
files = self.source.getchanges(rev) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
195 |
|
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
196 |
do_copies = (hasattr(c, 'copies') and hasattr(self.dest, 'copyfile')) |
316 | 197 |
|
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
198 |
for f, v in files: |
316 | 199 |
try: |
200 |
data = self.source.getfile(f, v) |
|
201 |
except IOError, inst: |
|
202 |
self.dest.delfile(f) |
|
203 |
else: |
|
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
204 |
e = self.source.getmode(f, v) |
316 | 205 |
self.dest.putfile(f, e, data) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
206 |
if do_copies: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
207 |
if f in c.copies: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
208 |
# Merely marks that a copy happened. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
209 |
self.dest.copyfile(c.copies[f], f) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
210 |
|
316 | 211 |
|
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
212 |
r = [self.map[v] for v in c.parents] |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
213 |
f = [f for f, v in files] |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
214 |
newnode = self.dest.putcommit(f, r, c) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
215 |
self.mapentry(rev, newnode) |
316 | 216 |
|
217 |
def convert(self): |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
218 |
try: |
4812
a5209b0487e0
convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents:
4780
diff
changeset
|
219 |
self.source.setrevmap(self.map) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
220 |
self.ui.status("scanning source...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
221 |
heads = self.source.getheads() |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
222 |
parents = self.walktree(heads) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
223 |
self.ui.status("sorting...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
224 |
t = self.toposort(parents) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
225 |
num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
226 |
c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
227 |
|
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
228 |
self.ui.status("converting...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
229 |
for c in t: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
230 |
num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
231 |
desc = self.commitcache[c].desc |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
232 |
if "\n" in desc: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
233 |
desc = desc.splitlines()[0] |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
234 |
author = self.commitcache[c].author |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
235 |
author = self.authors.get(author, author) |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
236 |
self.commitcache[c].author = author |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
237 |
self.ui.status("%d %s\n" % (num, desc)) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
238 |
self.copy(c) |
316 | 239 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
240 |
tags = self.source.gettags() |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
241 |
ctags = {} |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
242 |
for k in tags: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
243 |
v = tags[k] |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
244 |
if v in self.map: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
245 |
ctags[k] = self.map[v] |
316 | 246 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
247 |
if c and ctags: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
248 |
nrev = self.dest.puttags(ctags) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
249 |
# write another hash correspondence to override the previous |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
250 |
# one so we don't end up with extra tag heads |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
251 |
if nrev: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
252 |
self.mapentry(c, nrev) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
253 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
254 |
self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
255 |
finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
256 |
self.cleanup() |
694 | 257 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
258 |
def cleanup(self): |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
259 |
if self.mapfilefd: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
260 |
self.mapfilefd.close() |
694 | 261 |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
262 |
def _convert(ui, src, dest=None, mapfile=None, **opts): |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
263 |
'''Convert a foreign SCM repository to a Mercurial one. |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
264 |
|
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
265 |
Accepted source formats: |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
266 |
- GIT |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
267 |
- CVS |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
268 |
- SVN |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
269 |
|
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
270 |
Accepted destination formats: |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
271 |
- Mercurial |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
272 |
|
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4719
diff
changeset
|
273 |
If no revision is given, all revisions will be converted. Otherwise, |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4719
diff
changeset
|
274 |
convert will only import up to the named revision (given in a format |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4719
diff
changeset
|
275 |
understood by the source). |
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4719
diff
changeset
|
276 |
|
4883
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
277 |
If no destination directory name is specified, it defaults to the |
4924
ad09ce1d393c
convert/subversion.py: escape quotes to make code readable in Emacs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4896
diff
changeset
|
278 |
basename of the source with \'-hg\' appended. If the destination |
ad09ce1d393c
convert/subversion.py: escape quotes to make code readable in Emacs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4896
diff
changeset
|
279 |
repository doesn\'t exist, it will be created. |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
280 |
|
4924
ad09ce1d393c
convert/subversion.py: escape quotes to make code readable in Emacs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4896
diff
changeset
|
281 |
If <mapfile> isn\'t given, it will be put in a default location |
4883
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
282 |
(<dest>/.hg/shamap by default). The <mapfile> is a simple text |
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
283 |
file that maps each source commit ID to the destination ID for |
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
284 |
that revision, like so: |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
285 |
<source ID> <destination ID> |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
286 |
|
4924
ad09ce1d393c
convert/subversion.py: escape quotes to make code readable in Emacs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4896
diff
changeset
|
287 |
If the file doesn\'t exist, it\'s automatically created. It\'s updated |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
288 |
on each commit copied, so convert-repo can be interrupted and can |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
289 |
be run repeatedly to copy new commits. |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
290 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
291 |
The [username mapping] file is a simple text file that maps each source |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
292 |
commit author to a destination commit author. It is handy for source SCMs |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
293 |
that use unix logins to identify authors (eg: CVS). One line per author |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
294 |
mapping and the line format is: |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
295 |
srcauthor=whatever string you want |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
296 |
''' |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
297 |
|
4895
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
298 |
util._encoding = 'UTF-8' |
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
299 |
|
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
300 |
if not dest: |
4883
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
301 |
dest = hg.defaultdest(src) + "-hg" |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
302 |
ui.status("assuming destination %s\n" % dest) |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
303 |
|
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
304 |
# Try to be smart and initalize things when required |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
305 |
created = False |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
306 |
if os.path.isdir(dest): |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
307 |
if len(os.listdir(dest)) > 0: |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
308 |
try: |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
309 |
hg.repository(ui, dest) |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
310 |
ui.status("destination %s is a Mercurial repository\n" % dest) |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
311 |
except hg.RepoError: |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
312 |
raise util.Abort( |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
313 |
"destination directory %s is not empty.\n" |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
314 |
"Please specify an empty directory to be initialized\n" |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
315 |
"or an already initialized mercurial repository" |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
316 |
% dest) |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
317 |
else: |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
318 |
ui.status("initializing destination %s repository\n" % dest) |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
319 |
hg.repository(ui, dest, create=True) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
320 |
created = True |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
321 |
elif os.path.exists(dest): |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
322 |
raise util.Abort("destination %s exists and is not a directory" % dest) |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
323 |
else: |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
324 |
ui.status("initializing destination %s repository\n" % dest) |
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
325 |
hg.repository(ui, dest, create=True) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
326 |
created = True |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
327 |
|
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
328 |
destc = convertsink(ui, dest) |
316 | 329 |
|
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
330 |
try: |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
331 |
srcc = convertsource(ui, src, rev=opts.get('rev')) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
332 |
except Exception: |
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
333 |
if created: |
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
334 |
shutil.rmtree(dest, True) |
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
335 |
raise |
316 | 336 |
|
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
337 |
if not mapfile: |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
338 |
try: |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
339 |
mapfile = destc.mapfile() |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
340 |
except: |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
341 |
mapfile = os.path.join(destc, "map") |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
342 |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
343 |
c = convert(ui, srcc, destc, mapfile, opts) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
344 |
c.convert() |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
345 |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
346 |
cmdtable = { |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
347 |
"convert": |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
348 |
(_convert, |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
349 |
[('A', 'authors', '', 'username mapping filename'), |
4760
07efcce17d28
convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents:
4719
diff
changeset
|
350 |
('r', 'rev', '', 'import up to target revision REV'), |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
351 |
('', 'datesort', None, 'try to sort changesets by date')], |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
352 |
'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'), |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
353 |
} |