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