author | Brendan Cully <brendan@kublai.com> |
Sun, 10 Jun 2007 20:08:47 -0700 | |
changeset 4536 | cc9b79216a76 |
parent 4532 | hgext/convert/__init__.py@c3a78a49d7f0 |
child 4589 | 451e91ed535e |
permissions | -rw-r--r-- |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
1 |
# hg backend for convert extension |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
2 |
|
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
3 |
import os, time |
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
4 |
from mercurial import hg |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
5 |
|
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
6 |
from common import NoRepo, converter_sink |
694 | 7 |
|
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
8 |
class convert_mercurial(converter_sink): |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
9 |
def __init__(self, ui, path): |
316 | 10 |
self.path = path |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
11 |
self.ui = ui |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
12 |
try: |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
13 |
self.repo = hg.repository(self.ui, path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
14 |
except: |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
15 |
raise NoRepo("could open hg repo %s" % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
16 |
|
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
17 |
def mapfile(self): |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
18 |
return os.path.join(self.path, ".hg", "shamap") |
316 | 19 |
|
20 |
def getheads(self): |
|
21 |
h = self.repo.changelog.heads() |
|
1335
bea6356b8bca
git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents:
1237
diff
changeset
|
22 |
return [ hg.hex(x) for x in h ] |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
23 |
|
316 | 24 |
def putfile(self, f, e, data): |
4082
6b2909e84203
convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents:
4062
diff
changeset
|
25 |
self.repo.wwrite(f, data, e) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
26 |
if self.repo.dirstate.state(f) == '?': |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
27 |
self.repo.dirstate.update([f], "a") |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
28 |
|
316 | 29 |
def delfile(self, f): |
30 |
try: |
|
31 |
os.unlink(self.repo.wjoin(f)) |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
32 |
#self.repo.remove([f]) |
316 | 33 |
except: |
34 |
pass |
|
35 |
||
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
36 |
def putcommit(self, files, parents, commit): |
431 | 37 |
seen = {} |
38 |
pl = [] |
|
39 |
for p in parents: |
|
40 |
if p not in seen: |
|
41 |
pl.append(p) |
|
42 |
seen[p] = 1 |
|
43 |
parents = pl |
|
316 | 44 |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
45 |
if len(parents) < 2: parents.append("0" * 40) |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
46 |
if len(parents) < 2: parents.append("0" * 40) |
431 | 47 |
p2 = parents.pop(0) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
48 |
|
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
49 |
text = commit.desc |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
50 |
extra = {} |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
51 |
try: |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
52 |
extra["branch"] = commit.branch |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
53 |
except AttributeError: |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
54 |
pass |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
55 |
|
431 | 56 |
while parents: |
57 |
p1 = p2 |
|
58 |
p2 = parents.pop(0) |
|
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
59 |
a = self.repo.rawcommit(files, text, commit.author, commit.date, |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
60 |
hg.bin(p1), hg.bin(p2), extra=extra) |
431 | 61 |
text = "(octopus merge fixup)\n" |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
62 |
p2 = hg.hex(self.repo.changelog.tip()) |
431 | 63 |
|
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
64 |
return p2 |
316 | 65 |
|
694 | 66 |
def puttags(self, tags): |
67 |
try: |
|
68 |
old = self.repo.wfile(".hgtags").read() |
|
69 |
oldlines = old.splitlines(1) |
|
70 |
oldlines.sort() |
|
71 |
except: |
|
72 |
oldlines = [] |
|
73 |
||
74 |
k = tags.keys() |
|
75 |
k.sort() |
|
76 |
newlines = [] |
|
77 |
for tag in k: |
|
78 |
newlines.append("%s %s\n" % (tags[tag], tag)) |
|
79 |
||
80 |
newlines.sort() |
|
81 |
||
82 |
if newlines != oldlines: |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
83 |
self.ui.status("updating tags\n") |
694 | 84 |
f = self.repo.wfile(".hgtags", "w") |
85 |
f.write("".join(newlines)) |
|
86 |
f.close() |
|
87 |
if not oldlines: self.repo.add([".hgtags"]) |
|
1335
bea6356b8bca
git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents:
1237
diff
changeset
|
88 |
date = "%s 0" % int(time.mktime(time.gmtime())) |
694 | 89 |
self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
90 |
date, self.repo.changelog.tip(), hg.nullid) |
|
1387
0c7e8d345564
convert-repo: linearize the tag commit
Matt Mackall <mpm@selenic.com>
parents:
1386
diff
changeset
|
91 |
return hg.hex(self.repo.changelog.tip()) |