Mercurial > hg
comparison hgext/convert/hg.py @ 4536:cc9b79216a76
Split convert extension into common and repository type modules
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 10 Jun 2007 20:08:47 -0700 |
parents | hgext/convert/__init__.py@c3a78a49d7f0 |
children | 451e91ed535e |
comparison
equal
deleted
inserted
replaced
4533:36abb07c79d4 | 4536:cc9b79216a76 |
---|---|
1 # hg backend for convert extension | |
2 | |
3 import os, time | |
4 from mercurial import hg | |
5 | |
6 from common import NoRepo, converter_sink | |
7 | |
8 class convert_mercurial(converter_sink): | |
9 def __init__(self, ui, path): | |
10 self.path = path | |
11 self.ui = ui | |
12 try: | |
13 self.repo = hg.repository(self.ui, path) | |
14 except: | |
15 raise NoRepo("could open hg repo %s" % path) | |
16 | |
17 def mapfile(self): | |
18 return os.path.join(self.path, ".hg", "shamap") | |
19 | |
20 def getheads(self): | |
21 h = self.repo.changelog.heads() | |
22 return [ hg.hex(x) for x in h ] | |
23 | |
24 def putfile(self, f, e, data): | |
25 self.repo.wwrite(f, data, e) | |
26 if self.repo.dirstate.state(f) == '?': | |
27 self.repo.dirstate.update([f], "a") | |
28 | |
29 def delfile(self, f): | |
30 try: | |
31 os.unlink(self.repo.wjoin(f)) | |
32 #self.repo.remove([f]) | |
33 except: | |
34 pass | |
35 | |
36 def putcommit(self, files, parents, commit): | |
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 | |
44 | |
45 if len(parents) < 2: parents.append("0" * 40) | |
46 if len(parents) < 2: parents.append("0" * 40) | |
47 p2 = parents.pop(0) | |
48 | |
49 text = commit.desc | |
50 extra = {} | |
51 try: | |
52 extra["branch"] = commit.branch | |
53 except AttributeError: | |
54 pass | |
55 | |
56 while parents: | |
57 p1 = p2 | |
58 p2 = parents.pop(0) | |
59 a = self.repo.rawcommit(files, text, commit.author, commit.date, | |
60 hg.bin(p1), hg.bin(p2), extra=extra) | |
61 text = "(octopus merge fixup)\n" | |
62 p2 = hg.hex(self.repo.changelog.tip()) | |
63 | |
64 return p2 | |
65 | |
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: | |
83 self.ui.status("updating tags\n") | |
84 f = self.repo.wfile(".hgtags", "w") | |
85 f.write("".join(newlines)) | |
86 f.close() | |
87 if not oldlines: self.repo.add([".hgtags"]) | |
88 date = "%s 0" % int(time.mktime(time.gmtime())) | |
89 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", | |
90 date, self.repo.changelog.tip(), hg.nullid) | |
91 return hg.hex(self.repo.changelog.tip()) |