##// END OF EJS Templates
convert: hg sink commits without working dir
Patrick Mezard -
r6717:2011bb8a default
parent child Browse files
Show More
@@ -17,7 +17,7 b' import os, time'
17 17 from mercurial.i18n import _
18 18 from mercurial.repo import RepoError
19 19 from mercurial.node import bin, hex, nullid
20 from mercurial import hg, revlog, util
20 from mercurial import hg, revlog, util, context
21 21
22 22 from common import NoRepo, commit, converter_source, converter_sink
23 23
@@ -54,11 +54,9 b' class mercurial_sink(converter_sink):'
54 54 self.ui.debug(_('run hg sink pre-conversion action\n'))
55 55 self.wlock = self.repo.wlock()
56 56 self.lock = self.repo.lock()
57 self.repo.dirstate.clear()
58 57
59 58 def after(self):
60 59 self.ui.debug(_('run hg sink post-conversion action\n'))
61 self.repo.dirstate.invalidate()
62 60 self.lock = None
63 61 self.wlock = None
64 62
@@ -111,30 +109,18 b' class mercurial_sink(converter_sink):'
111 109 self.before()
112 110
113 111 def putcommit(self, files, copies, parents, commit, source):
114 # Apply changes to working copy
115 for f, v in files:
116 try:
117 data = source.getfile(f, v)
118 except IOError, inst:
119 try:
120 util.unlink(self.repo.wjoin(f))
121 except OSError:
122 pass
123 else:
124 e = source.getmode(f, v)
125 self.repo.wwrite(f, data, e)
126 if f not in self.repo.dirstate:
127 self.repo.dirstate.normallookup(f)
128 if f in copies:
129 self.repo.copy(copies[f], f)
130 files = [f[0] for f in files]
131 112
132 seen = {}
113 files = dict(files)
114 def getfilectx(repo, memctx, f):
115 v = files[f]
116 data = source.getfile(f, v)
117 e = source.getmode(f, v)
118 return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
119
133 120 pl = []
134 121 for p in parents:
135 if p not in seen:
122 if p not in pl:
136 123 pl.append(p)
137 seen[p] = 1
138 124 parents = pl
139 125 nparents = len(parents)
140 126 if self.filemapmode and nparents == 1:
@@ -155,9 +141,9 b' class mercurial_sink(converter_sink):'
155 141 while parents:
156 142 p1 = p2
157 143 p2 = parents.pop(0)
158 a = self.repo.rawcommit(files, text, commit.author, commit.date,
159 bin(p1), bin(p2), extra=extra)
160 self.repo.dirstate.clear()
144 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(), getfilectx,
145 commit.author, commit.date, extra)
146 a = self.repo.commitctx(ctx)
161 147 text = "(octopus merge fixup)\n"
162 148 p2 = hex(self.repo.changelog.tip())
163 149
@@ -166,43 +152,42 b' class mercurial_sink(converter_sink):'
166 152 mnode = self.repo.changelog.read(bin(p2))[0]
167 153 if not man.cmp(m1node, man.revision(mnode)):
168 154 self.repo.rollback()
169 self.repo.dirstate.clear()
170 155 return parent
171 156 return p2
172 157
173 158 def puttags(self, tags):
174 try:
175 old = self.repo.wfile(".hgtags").read()
176 oldlines = old.splitlines(1)
177 oldlines.sort()
178 except:
179 oldlines = []
159 try:
160 parentctx = self.repo.changectx(self.tagsbranch)
161 tagparent = parentctx.node()
162 except RepoError, inst:
163 parentctx = None
164 tagparent = nullid
180 165
181 k = tags.keys()
182 k.sort()
183 newlines = []
184 for tag in k:
185 newlines.append("%s %s\n" % (tags[tag], tag))
186
187 newlines.sort()
166 try:
167 old = parentctx.filectx(".hgtags").data()
168 oldlines = old.splitlines(1)
169 oldlines.sort()
170 except:
171 oldlines = []
188 172
189 if newlines != oldlines:
190 self.ui.status("updating tags\n")
191 f = self.repo.wfile(".hgtags", "w")
192 f.write("".join(newlines))
193 f.close()
194 if not oldlines: self.repo.add([".hgtags"])
195 date = "%s 0" % int(time.mktime(time.gmtime()))
196 extra = {}
197 if self.tagsbranch != 'default':
198 extra['branch'] = self.tagsbranch
199 try:
200 tagparent = self.repo.changectx(self.tagsbranch).node()
201 except RepoError, inst:
202 tagparent = nullid
203 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
204 date, tagparent, nullid, extra=extra)
205 return hex(self.repo.changelog.tip())
173 newlines = [("%s %s\n" % (tags[tag], tag)) for tag in tags.keys()]
174 newlines.sort()
175
176 if newlines == oldlines:
177 return None
178 data = "".join(newlines)
179
180 def getfilectx(repo, memctx, f):
181 return context.memfilectx(f, data, False, False, None)
182
183 self.ui.status("updating tags\n")
184 date = "%s 0" % int(time.mktime(time.gmtime()))
185 extra = {'branch': self.tagsbranch}
186 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
187 [".hgtags"], getfilectx, "convert-repo", date,
188 extra)
189 self.repo.commitctx(ctx)
190 return hex(self.repo.changelog.tip())
206 191
207 192 def setfilemapmode(self, active):
208 193 self.filemapmode = active
@@ -7,6 +7,11 b' cvscall()'
7 7 cvs -f $@
8 8 }
9 9
10 hgcat()
11 {
12 hg --cwd src-hg cat -r tip "$1"
13 }
14
10 15 echo "[extensions]" >> $HGRCPATH
11 16 echo "convert = " >> $HGRCPATH
12 17
@@ -45,13 +50,13 b' cd ..'
45 50
46 51 echo % convert fresh repo
47 52 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
48 cat src-hg/a
49 cat src-hg/b/c
53 hgcat a
54 hgcat b/c
50 55
51 56 echo % convert fresh repo with --filemap
52 57 echo include b/c > filemap
53 58 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
54 cat src-hg/b/c
59 hgcat b/c
55 60 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
56 61
57 62 echo % commit new file revisions
@@ -64,12 +69,12 b' cd ..'
64 69
65 70 echo % convert again
66 71 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
67 cat src-hg/a
68 cat src-hg/b/c
72 hgcat a
73 hgcat b/c
69 74
70 75 echo % convert again with --filemap
71 76 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
72 cat src-hg/b/c
77 hgcat b/c
73 78 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
74 79
75 80 echo % commit branch
@@ -84,12 +89,12 b' cd ..'
84 89
85 90 echo % convert again
86 91 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
87 cat src-hg/a
88 cat src-hg/b/c
92 hgcat a
93 hgcat b/c
89 94
90 95 echo % convert again with --filemap
91 96 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
92 cat src-hg/b/c
97 hgcat b/c
93 98 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
94 99
95 100 echo "graphlog = " >> $HGRCPATH
@@ -7,6 +7,11 b' cvscall()'
7 7 cvs -f "$@"
8 8 }
9 9
10 hgcat()
11 {
12 hg --cwd src-hg cat -r tip "$1"
13 }
14
10 15 echo "[extensions]" >> $HGRCPATH
11 16 echo "convert = " >> $HGRCPATH
12 17 echo "graphlog = " >> $HGRCPATH
@@ -48,13 +53,13 b' cd ..'
48 53
49 54 echo % convert fresh repo
50 55 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
51 cat src-hg/a
52 cat src-hg/b/c
56 hgcat a
57 hgcat b/c
53 58
54 59 echo % convert fresh repo with --filemap
55 60 echo include b/c > filemap
56 61 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
57 cat src-hg/b/c
62 hgcat b/c
58 63 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
59 64
60 65 echo % commit new file revisions
@@ -67,12 +72,12 b' cd ..'
67 72
68 73 echo % convert again
69 74 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
70 cat src-hg/a
71 cat src-hg/b/c
75 hgcat a
76 hgcat b/c
72 77
73 78 echo % convert again with --filemap
74 79 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
75 cat src-hg/b/c
80 hgcat b/c
76 81 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
77 82
78 83 echo % commit branch
@@ -87,12 +92,12 b' cd ..'
87 92
88 93 echo % convert again
89 94 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
90 cat src-hg/a
91 cat src-hg/b/c
95 hgcat a
96 hgcat b/c
92 97
93 98 echo % convert again with --filemap
94 99 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
95 cat src-hg/b/c
100 hgcat b/c
96 101 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
97 102
98 103 echo "graphlog = " >> $HGRCPATH
@@ -104,7 +104,6 b' sorting...'
104 104 converting...
105 105 0 ci2
106 106 a
107 a
108 107 c
109 108 d
110 109 % convert again with --filemap
@@ -79,7 +79,6 b' sorting...'
79 79 converting...
80 80 0 ci2
81 81 a
82 a
83 82 c
84 83 d
85 84 % convert again with --filemap
General Comments 0
You need to be logged in to leave comments. Login now