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 |
@@ -177,12 +177,11 b' class converter_sink(object):' | |||||
177 | tags: {tagname: sink_rev_id, ...}""" |
|
177 | tags: {tagname: sink_rev_id, ...}""" | |
178 | raise NotImplementedError() |
|
178 | raise NotImplementedError() | |
179 |
|
179 | |||
180 |
def setbranch(self, branch, pbranch |
|
180 | def setbranch(self, branch, pbranches): | |
181 | """Set the current branch name. Called before the first putfile |
|
181 | """Set the current branch name. Called before the first putfile | |
182 | on the branch. |
|
182 | on the branch. | |
183 | branch: branch name for subsequent commits |
|
183 | branch: branch name for subsequent commits | |
184 | pbranch: branch name of parent commit |
|
184 | pbranches: (converted parent revision, parent branch) tuples""" | |
185 | parents: destination revisions of parent""" |
|
|||
186 | pass |
|
185 | pass | |
187 |
|
186 | |||
188 | def setfilemapmode(self, active): |
|
187 | def setfilemapmode(self, active): |
@@ -201,15 +201,14 b' class converter(object):' | |||||
201 | self.map[rev] = dest |
|
201 | self.map[rev] = dest | |
202 | return |
|
202 | return | |
203 | files, copies = changes |
|
203 | files, copies = changes | |
204 | parents = [self.map[r] for r in commit.parents] |
|
204 | pbranches = [] | |
205 | if commit.parents: |
|
205 | if commit.parents: | |
206 |
prev |
|
206 | for prev in commit.parents: | |
207 | if prev not in self.commitcache: |
|
207 | if prev not in self.commitcache: | |
208 | self.cachecommit(prev) |
|
208 | self.cachecommit(prev) | |
209 |
pbranch |
|
209 | pbranches.append((self.map[prev], | |
210 | else: |
|
210 | self.commitcache[prev].branch)) | |
211 | pbranch = None |
|
211 | self.dest.setbranch(commit.branch, pbranches) | |
212 | self.dest.setbranch(commit.branch, pbranch, parents) |
|
|||
213 | for f, v in files: |
|
212 | for f, v in files: | |
214 | filenames.append(f) |
|
213 | filenames.append(f) | |
215 | try: |
|
214 | try: | |
@@ -225,6 +224,7 b' class converter(object):' | |||||
225 | # Merely marks that a copy happened. |
|
224 | # Merely marks that a copy happened. | |
226 | self.dest.copyfile(copyf, f) |
|
225 | self.dest.copyfile(copyf, f) | |
227 |
|
226 | |||
|
227 | parents = [b[0] for b in pbranches] | |||
228 | newnode = self.dest.putcommit(filenames, parents, commit) |
|
228 | newnode = self.dest.putcommit(filenames, parents, commit) | |
229 | self.source.converted(rev, newnode) |
|
229 | self.source.converted(rev, newnode) | |
230 | self.map[rev] = newnode |
|
230 | self.map[rev] = newnode |
@@ -86,29 +86,42 b' class mercurial_sink(converter_sink):' | |||||
86 | except OSError: |
|
86 | except OSError: | |
87 | pass |
|
87 | pass | |
88 |
|
88 | |||
89 |
def setbranch(self, branch, pbranch |
|
89 | def setbranch(self, branch, pbranches): | |
90 |
if |
|
90 | if not self.clonebranches: | |
91 | return |
|
91 | return | |
92 |
|
92 | |||
|
93 | setbranch = (branch != self.lastbranch) | |||
93 | self.lastbranch = branch |
|
94 | self.lastbranch = branch | |
94 | self.after() |
|
|||
95 | if not branch: |
|
95 | if not branch: | |
96 | branch = 'default' |
|
96 | branch = 'default' | |
97 | if not pbranch: |
|
97 | pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches] | |
98 | pbranch = 'default' |
|
98 | pbranch = pbranches and pbranches[0][1] or 'default' | |
99 |
|
99 | |||
100 | branchpath = os.path.join(self.path, branch) |
|
100 | branchpath = os.path.join(self.path, branch) | |
|
101 | if setbranch: | |||
|
102 | self.after() | |||
101 | try: |
|
103 | try: | |
102 | self.repo = hg.repository(self.ui, branchpath) |
|
104 | self.repo = hg.repository(self.ui, branchpath) | |
103 | except: |
|
105 | except: | |
104 | if not parents: |
|
|||
105 | self.repo = hg.repository(self.ui, branchpath, create=True) |
|
106 | self.repo = hg.repository(self.ui, branchpath, create=True) | |
106 |
|
|
107 | self.before() | |
107 | self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch)) |
|
108 | ||
108 | hg.clone(self.ui, os.path.join(self.path, pbranch), |
|
109 | # pbranches may bring revisions from other branches (merge parents) | |
109 | branchpath, rev=parents, update=False, |
|
110 | # Make sure we have them, or pull them. | |
110 | stream=True) |
|
111 | missings = {} | |
111 | self.repo = hg.repository(self.ui, branchpath) |
|
112 | for b in pbranches: | |
|
113 | try: | |||
|
114 | self.repo.lookup(b[0]) | |||
|
115 | except: | |||
|
116 | missings.setdefault(b[1], []).append(b[0]) | |||
|
117 | ||||
|
118 | if missings: | |||
|
119 | self.after() | |||
|
120 | for pbranch, heads in missings.iteritems(): | |||
|
121 | pbranchpath = os.path.join(self.path, pbranch) | |||
|
122 | prepo = hg.repository(self.ui, pbranchpath) | |||
|
123 | self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch)) | |||
|
124 | self.repo.pull(prepo, [prepo.lookup(h) for h in heads]) | |||
112 | self.before() |
|
125 | self.before() | |
113 |
|
126 | |||
114 | def putcommit(self, files, parents, commit): |
|
127 | def putcommit(self, files, parents, commit): |
General Comments 0
You need to be logged in to leave comments.
Login now