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 | 167 | tags: {tagname: sink_rev_id, ...}""" |
|
168 | 168 | raise NotImplementedError() |
|
169 | 169 | |
|
170 |
def setbranch(self, branch, pbranch |
|
|
170 | def setbranch(self, branch, pbranches): | |
|
171 | 171 | """Set the current branch name. Called before the first putfile |
|
172 | 172 | on the branch. |
|
173 | 173 | branch: branch name for subsequent commits |
|
174 | pbranch: branch name of parent commit | |
|
175 | parents: destination revisions of parent""" | |
|
174 | pbranches: (converted parent revision, parent branch) tuples""" | |
|
176 | 175 | pass |
|
177 | 176 | |
|
178 | 177 | def setfilemapmode(self, active): |
@@ -222,15 +222,14 b' class converter(object):' | |||
|
222 | 222 | self.mapentry(rev, dest) |
|
223 | 223 | return |
|
224 | 224 | files, copies = changes |
|
225 | parents = [self.map[r] for r in commit.parents] | |
|
225 | pbranches = [] | |
|
226 | 226 | if commit.parents: |
|
227 |
prev |
|
|
227 | for prev in commit.parents: | |
|
228 | 228 | if prev not in self.commitcache: |
|
229 | 229 | self.cachecommit(prev) |
|
230 |
pbranch |
|
|
231 | else: | |
|
232 | pbranch = None | |
|
233 | self.dest.setbranch(commit.branch, pbranch, parents) | |
|
230 | pbranches.append((self.map[prev], | |
|
231 | self.commitcache[prev].branch)) | |
|
232 | self.dest.setbranch(commit.branch, pbranches) | |
|
234 | 233 | for f, v in files: |
|
235 | 234 | filenames.append(f) |
|
236 | 235 | try: |
@@ -246,6 +245,7 b' class converter(object):' | |||
|
246 | 245 | # Merely marks that a copy happened. |
|
247 | 246 | self.dest.copyfile(copyf, f) |
|
248 | 247 | |
|
248 | parents = [b[0] for b in pbranches] | |
|
249 | 249 | newnode = self.dest.putcommit(filenames, parents, commit) |
|
250 | 250 | self.mapentry(rev, newnode) |
|
251 | 251 |
@@ -80,29 +80,42 b' class mercurial_sink(converter_sink):' | |||
|
80 | 80 | except OSError: |
|
81 | 81 | pass |
|
82 | 82 | |
|
83 |
def setbranch(self, branch, pbranch |
|
|
84 |
if |
|
|
83 | def setbranch(self, branch, pbranches): | |
|
84 | if not self.clonebranches: | |
|
85 | 85 | return |
|
86 | 86 | |
|
87 | setbranch = (branch != self.lastbranch) | |
|
87 | 88 | self.lastbranch = branch |
|
88 | self.after() | |
|
89 | 89 | if not branch: |
|
90 | 90 | branch = 'default' |
|
91 | if not pbranch: | |
|
92 | pbranch = 'default' | |
|
91 | pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches] | |
|
92 | pbranch = pbranches and pbranches[0][1] or 'default' | |
|
93 | 93 | |
|
94 | 94 | branchpath = os.path.join(self.path, branch) |
|
95 | if setbranch: | |
|
96 | self.after() | |
|
95 | 97 | try: |
|
96 | 98 | self.repo = hg.repository(self.ui, branchpath) |
|
97 | 99 | except: |
|
98 | if not parents: | |
|
99 | 100 | self.repo = hg.repository(self.ui, branchpath, create=True) |
|
100 |
|
|
|
101 | self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch)) | |
|
102 | hg.clone(self.ui, os.path.join(self.path, pbranch), | |
|
103 | branchpath, rev=parents, update=False, | |
|
104 | stream=True) | |
|
105 | self.repo = hg.repository(self.ui, branchpath) | |
|
101 | self.before() | |
|
102 | ||
|
103 | # pbranches may bring revisions from other branches (merge parents) | |
|
104 | # Make sure we have them, or pull them. | |
|
105 | missings = {} | |
|
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 | 119 | self.before() |
|
107 | 120 | |
|
108 | 121 | def putcommit(self, files, parents, commit): |
General Comments 0
You need to be logged in to leave comments.
Login now