Mercurial > hg > mercurial-crew-with-dirclash
annotate hgext/convert/hg.py @ 4671:150afe6becf6
identify: take a path to a remote repo
Rather than using -R, we take a path as an argument. This lets us use
url#branch syntaxes that may be in hgrc.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 21 Jun 2007 13:09:01 -0500 |
parents | 451e91ed535e |
children | 07efcce17d28 26692d08c2f9 |
rev | line source |
---|---|
4534
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 |
3954
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3948
diff
changeset
|
2 |
4534
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 |
3954
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3948
diff
changeset
|
5 |
4534
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 |
4447
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4446
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 |
3947
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3916
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) |
3947
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3916
diff
changeset
|
14 except: |
3954
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3948
diff
changeset
|
15 raise NoRepo("could open hg repo %s" % path) |
3947
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3916
diff
changeset
|
16 |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3916
diff
changeset
|
17 def mapfile(self): |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3916
diff
changeset
|
18 return os.path.join(self.path, ".hg", "shamap") |
316 | 19 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4534
diff
changeset
|
20 def authorfile(self): |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4534
diff
changeset
|
21 return os.path.join(self.path, ".hg", "authormap") |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4534
diff
changeset
|
22 |
316 | 23 def getheads(self): |
24 h = self.repo.changelog.heads() | |
1335
bea6356b8bca
git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents:
1237
diff
changeset
|
25 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
|
26 |
316 | 27 def putfile(self, f, e, data): |
4082
6b2909e84203
convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents:
4062
diff
changeset
|
28 self.repo.wwrite(f, data, e) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
29 if self.repo.dirstate.state(f) == '?': |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
30 self.repo.dirstate.update([f], "a") |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
31 |
316 | 32 def delfile(self, f): |
33 try: | |
34 os.unlink(self.repo.wjoin(f)) | |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
35 #self.repo.remove([f]) |
316 | 36 except: |
37 pass | |
38 | |
3955
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
39 def putcommit(self, files, parents, commit): |
431 | 40 seen = {} |
41 pl = [] | |
42 for p in parents: | |
43 if p not in seen: | |
44 pl.append(p) | |
45 seen[p] = 1 | |
46 parents = pl | |
316 | 47 |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
48 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
|
49 if len(parents) < 2: parents.append("0" * 40) |
431 | 50 p2 = parents.pop(0) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
51 |
3955
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
52 text = commit.desc |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
53 extra = {} |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
54 try: |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
55 extra["branch"] = commit.branch |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
56 except AttributeError: |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
57 pass |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
58 |
431 | 59 while parents: |
60 p1 = p2 | |
61 p2 = parents.pop(0) | |
3955
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
62 a = self.repo.rawcommit(files, text, commit.author, commit.date, |
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
63 hg.bin(p1), hg.bin(p2), extra=extra) |
431 | 64 text = "(octopus merge fixup)\n" |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
65 p2 = hg.hex(self.repo.changelog.tip()) |
431 | 66 |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
67 return p2 |
316 | 68 |
694 | 69 def puttags(self, tags): |
70 try: | |
71 old = self.repo.wfile(".hgtags").read() | |
72 oldlines = old.splitlines(1) | |
73 oldlines.sort() | |
74 except: | |
75 oldlines = [] | |
76 | |
77 k = tags.keys() | |
78 k.sort() | |
79 newlines = [] | |
80 for tag in k: | |
81 newlines.append("%s %s\n" % (tags[tag], tag)) | |
82 | |
83 newlines.sort() | |
84 | |
85 if newlines != oldlines: | |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
86 self.ui.status("updating tags\n") |
694 | 87 f = self.repo.wfile(".hgtags", "w") |
88 f.write("".join(newlines)) | |
89 f.close() | |
90 if not oldlines: self.repo.add([".hgtags"]) | |
1335
bea6356b8bca
git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents:
1237
diff
changeset
|
91 date = "%s 0" % int(time.mktime(time.gmtime())) |
694 | 92 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
93 date, self.repo.changelog.tip(), hg.nullid) | |
1387
0c7e8d345564
convert-repo: linearize the tag commit
Matt Mackall <mpm@selenic.com>
parents:
1386
diff
changeset
|
94 return hg.hex(self.repo.changelog.tip()) |