Mercurial > hgsubversion
comparison hgsubversion/replay.py @ 437:45ce07a4807f
replay: merge functions into a single function
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Tue, 16 Jun 2009 09:12:04 +0200 |
parents | 404162e4bb53 |
children | 8c545dcad7b1 |
comparison
equal
deleted
inserted
replaced
436:404162e4bb53 | 437:45ce07a4807f |
---|---|
18 """Exception raised when you try and commit but the replay encountered an | 18 """Exception raised when you try and commit but the replay encountered an |
19 exception. | 19 exception. |
20 """ | 20 """ |
21 | 21 |
22 def convert_rev(ui, meta, svn, r, tbdelta): | 22 def convert_rev(ui, meta, svn, r, tbdelta): |
23 # ui is only passed in for similarity with stupid.convert_rev() | |
24 hg_editor = meta.editor | |
25 hg_editor.current.clear() | |
26 hg_editor.current.rev = r | |
27 meta.save_tbdelta(tbdelta) # needed by get_replay() | |
28 svn.get_replay(r.revnum, meta.editor) | |
29 hg_editor.current.findmissing(svn) | |
30 _updateexternals(meta, hg_editor.current) | |
31 return commit_current_delta(meta, tbdelta, hg_editor.current) | |
32 | 23 |
24 editor = meta.editor | |
25 editor.current.clear() | |
26 editor.current.rev = r | |
27 meta.save_tbdelta(tbdelta) | |
28 svn.get_replay(r.revnum, editor) | |
29 current = editor.current | |
30 current.findmissing(svn) | |
33 | 31 |
34 def _updateexternals(meta, current): | 32 # update externals |
35 if not current.externals: | |
36 return | |
37 # Accumulate externals records for all branches | |
38 revnum = current.rev.revnum | |
39 branches = {} | |
40 for path, entry in current.externals.iteritems(): | |
41 if not meta.is_path_valid(path): | |
42 meta.ui.warn('WARNING: Invalid path %s in externals\n' % path) | |
43 continue | |
44 p, b, bp = meta.split_branch_path(path) | |
45 if bp not in branches: | |
46 external = svnexternals.externalsfile() | |
47 parent = meta.get_parent_revision(revnum, b) | |
48 pctx = meta.repo[parent] | |
49 if '.hgsvnexternals' in pctx: | |
50 external.read(pctx['.hgsvnexternals'].data()) | |
51 branches[bp] = external | |
52 else: | |
53 external = branches[bp] | |
54 external[p] = entry | |
55 | 33 |
56 # Register the file changes | 34 if current.externals: |
57 for bp, external in branches.iteritems(): | |
58 path = bp + '/.hgsvnexternals' | |
59 if external: | |
60 current.set(path, external.write(), False, False) | |
61 else: | |
62 current.delete(path) | |
63 | 35 |
36 # accumulate externals records for all branches | |
37 revnum = current.rev.revnum | |
38 branches = {} | |
39 for path, entry in current.externals.iteritems(): | |
64 | 40 |
65 def commit_current_delta(meta, tbdelta, current): | 41 if not meta.is_path_valid(path): |
42 ui.warn('WARNING: Invalid path %s in externals\n' % path) | |
43 continue | |
44 | |
45 p, b, bp = meta.split_branch_path(path) | |
46 if bp not in branches: | |
47 external = svnexternals.externalsfile() | |
48 parent = meta.get_parent_revision(revnum, b) | |
49 pctx = meta.repo[parent] | |
50 if '.hgsvnexternals' in pctx: | |
51 external.read(pctx['.hgsvnexternals'].data()) | |
52 branches[bp] = external | |
53 else: | |
54 external = branches[bp] | |
55 | |
56 external[p] = entry | |
57 | |
58 # register externals file changes | |
59 for bp, external in branches.iteritems(): | |
60 path = bp + '/.hgsvnexternals' | |
61 if external: | |
62 current.set(path, external.write(), False, False) | |
63 else: | |
64 current.delete(path) | |
66 | 65 |
67 if current.exception is not None: #pragma: no cover | 66 if current.exception is not None: #pragma: no cover |
68 traceback.print_exception(*current.exception) | 67 traceback.print_exception(*current.exception) |
69 raise ReplayException() | 68 raise ReplayException() |
70 if current.missing: | 69 if current.missing: |
136 if current_file in current.files: | 135 if current_file in current.files: |
137 data = current.files[current_file] | 136 data = current.files[current_file] |
138 if is_link and data.startswith('link '): | 137 if is_link and data.startswith('link '): |
139 data = data[len('link '):] | 138 data = data[len('link '):] |
140 elif is_link: | 139 elif is_link: |
141 meta.ui.warn('file marked as link, but contains data: ' | 140 ui.warn('file marked as link, but contains data: ' |
142 '%s (%r)\n' % (current_file, flags)) | 141 '%s (%r)\n' % (current_file, flags)) |
143 else: | 142 else: |
144 data = parent_ctx.filectx(path).data() | 143 data = parent_ctx.filectx(path).data() |
145 return context.memfilectx(path=path, | 144 return context.memfilectx(path=path, |
146 data=data, | 145 data=data, |
147 islink=is_link, isexec=is_exec, | 146 islink=is_link, isexec=is_exec, |
157 meta.authors[rev.author], | 156 meta.authors[rev.author], |
158 date, | 157 date, |
159 extra) | 158 extra) |
160 | 159 |
161 new_hash = meta.repo.commitctx(current_ctx) | 160 new_hash = meta.repo.commitctx(current_ctx) |
162 util.describe_commit(meta.ui, new_hash, branch) | 161 util.describe_commit(ui, new_hash, branch) |
163 if (rev.revnum, branch) not in meta.revmap: | 162 if (rev.revnum, branch) not in meta.revmap: |
164 meta.revmap[rev.revnum, branch] = new_hash | 163 meta.revmap[rev.revnum, branch] = new_hash |
165 | 164 |
166 # 2. handle branches that need to be committed without any files | 165 # 2. handle branches that need to be committed without any files |
167 for branch in current.emptybranches: | 166 for branch in current.emptybranches: |
190 del_all_files, | 189 del_all_files, |
191 meta.authors[rev.author], | 190 meta.authors[rev.author], |
192 date, | 191 date, |
193 extra) | 192 extra) |
194 new_hash = meta.repo.commitctx(current_ctx) | 193 new_hash = meta.repo.commitctx(current_ctx) |
195 util.describe_commit(meta.ui, new_hash, branch) | 194 util.describe_commit(ui, new_hash, branch) |
196 if (rev.revnum, branch) not in meta.revmap: | 195 if (rev.revnum, branch) not in meta.revmap: |
197 meta.revmap[rev.revnum, branch] = new_hash | 196 meta.revmap[rev.revnum, branch] = new_hash |
198 | 197 |
199 return closebranches | 198 return closebranches |