##// END OF EJS Templates
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard -
r5934:e495f3f3 default
parent child Browse files
Show More
@@ -0,0 +1,54 b''
1 #!/bin/sh
2
3 echo "[extensions]" >> $HGRCPATH
4 echo "hgext.convert = " >> $HGRCPATH
5 echo "[convert]" >> $HGRCPATH
6 echo "hg.tagsbranch=0" >> $HGRCPATH
7
8 hg init source
9 cd source
10 echo a > a
11 hg ci -qAm adda
12 # Add a merge with one parent in the same branch
13 echo a >> a
14 hg ci -qAm changea
15 hg up -qC 0
16 hg branch branch0
17 echo b > b
18 hg ci -qAm addb
19 hg up -qC
20 hg merge
21 hg ci -qm mergeab
22 hg tag -ql mergeab
23 cd ..
24
25 # Miss perl... sometimes
26 cat > filter.py <<EOF
27 import sys, re
28
29 r = re.compile(r'^(?:\d+|pulling from)')
30 sys.stdout.writelines([l for l in sys.stdin if r.search(l)])
31 EOF
32
33 echo % convert
34 hg convert -v --config convert.hg.clonebranches=1 source dest |
35 python filter.py
36
37 # Add a merge with both parents and child in different branches
38 cd source
39 hg branch branch1
40 echo a > file1
41 hg ci -qAm c1
42 hg up -qC mergeab
43 hg branch branch2
44 echo a > file2
45 hg ci -qAm c2
46 hg merge branch1
47 hg branch branch3
48 hg ci -qAm c3
49 cd ..
50
51 echo % incremental conversion
52 hg convert -v --config convert.hg.clonebranches=1 source dest |
53 python filter.py
54
@@ -0,0 +1,29 b''
1 marked working directory as branch branch0
2 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 (branch merge, don't forget to commit)
4 % convert
5 3 adda
6 2 addb
7 pulling from default into branch0
8 1 changesets found
9 1 changea
10 0 mergeab
11 pulling from default into branch0
12 1 changesets found
13 marked working directory as branch branch1
14 marked working directory as branch branch2
15 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 (branch merge, don't forget to commit)
17 marked working directory as branch branch3
18 % incremental conversion
19 2 c1
20 pulling from branch0 into branch1
21 2 changesets found
22 1 c2
23 pulling from branch0 into branch2
24 2 changesets found
25 0 c3
26 pulling from branch2 into branch3
27 3 changesets found
28 pulling from branch1 into branch3
29 1 changesets found
@@ -167,12 +167,11 b' class converter_sink(object):'
167 tags: {tagname: sink_rev_id, ...}"""
167 tags: {tagname: sink_rev_id, ...}"""
168 raise NotImplementedError()
168 raise NotImplementedError()
169
169
170 def setbranch(self, branch, pbranch, parents):
170 def setbranch(self, branch, pbranches):
171 """Set the current branch name. Called before the first putfile
171 """Set the current branch name. Called before the first putfile
172 on the branch.
172 on the branch.
173 branch: branch name for subsequent commits
173 branch: branch name for subsequent commits
174 pbranch: branch name of parent commit
174 pbranches: (converted parent revision, parent branch) tuples"""
175 parents: destination revisions of parent"""
176 pass
175 pass
177
176
178 def setfilemapmode(self, active):
177 def setfilemapmode(self, active):
@@ -222,15 +222,14 b' class converter(object):'
222 self.mapentry(rev, dest)
222 self.mapentry(rev, dest)
223 return
223 return
224 files, copies = changes
224 files, copies = changes
225 parents = [self.map[r] for r in commit.parents]
225 pbranches = []
226 if commit.parents:
226 if commit.parents:
227 prev = commit.parents[0]
227 for prev in commit.parents:
228 if prev not in self.commitcache:
228 if prev not in self.commitcache:
229 self.cachecommit(prev)
229 self.cachecommit(prev)
230 pbranch = self.commitcache[prev].branch
230 pbranches.append((self.map[prev],
231 else:
231 self.commitcache[prev].branch))
232 pbranch = None
232 self.dest.setbranch(commit.branch, pbranches)
233 self.dest.setbranch(commit.branch, pbranch, parents)
234 for f, v in files:
233 for f, v in files:
235 filenames.append(f)
234 filenames.append(f)
236 try:
235 try:
@@ -246,6 +245,7 b' class converter(object):'
246 # Merely marks that a copy happened.
245 # Merely marks that a copy happened.
247 self.dest.copyfile(copyf, f)
246 self.dest.copyfile(copyf, f)
248
247
248 parents = [b[0] for b in pbranches]
249 newnode = self.dest.putcommit(filenames, parents, commit)
249 newnode = self.dest.putcommit(filenames, parents, commit)
250 self.mapentry(rev, newnode)
250 self.mapentry(rev, newnode)
251
251
@@ -80,29 +80,42 b' class mercurial_sink(converter_sink):'
80 except OSError:
80 except OSError:
81 pass
81 pass
82
82
83 def setbranch(self, branch, pbranch, parents):
83 def setbranch(self, branch, pbranches):
84 if (not self.clonebranches) or (branch == self.lastbranch):
84 if not self.clonebranches:
85 return
85 return
86
86
87 setbranch = (branch != self.lastbranch)
87 self.lastbranch = branch
88 self.lastbranch = branch
88 self.after()
89 if not branch:
89 if not branch:
90 branch = 'default'
90 branch = 'default'
91 if not pbranch:
91 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
92 pbranch = 'default'
92 pbranch = pbranches and pbranches[0][1] or 'default'
93
93
94 branchpath = os.path.join(self.path, branch)
94 branchpath = os.path.join(self.path, branch)
95 if setbranch:
96 self.after()
95 try:
97 try:
96 self.repo = hg.repository(self.ui, branchpath)
98 self.repo = hg.repository(self.ui, branchpath)
97 except:
99 except:
98 if not parents:
99 self.repo = hg.repository(self.ui, branchpath, create=True)
100 self.repo = hg.repository(self.ui, branchpath, create=True)
100 else:
101 self.before()
101 self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch))
102
102 hg.clone(self.ui, os.path.join(self.path, pbranch),
103 # pbranches may bring revisions from other branches (merge parents)
103 branchpath, rev=parents, update=False,
104 # Make sure we have them, or pull them.
104 stream=True)
105 missings = {}
105 self.repo = hg.repository(self.ui, branchpath)
106 for b in pbranches:
107 try:
108 self.repo.lookup(b[0])
109 except:
110 missings.setdefault(b[1], []).append(b[0])
111
112 if missings:
113 self.after()
114 for pbranch, heads in missings.iteritems():
115 pbranchpath = os.path.join(self.path, pbranch)
116 prepo = hg.repository(self.ui, pbranchpath)
117 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
118 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
106 self.before()
119 self.before()
107
120
108 def putcommit(self, files, parents, commit):
121 def putcommit(self, files, parents, commit):
General Comments 0
You need to be logged in to leave comments. Login now