Mercurial > hgsubversion
comparison hg_delta_editor.py @ 250:79349fd04836
utils: standardizing imported name to hgutil, our_util to util
author | Daniel Tang <dytang@cs.purdue.edu> |
---|---|
date | Fri, 10 Apr 2009 13:43:44 -0400 |
parents | c90cfa665b81 |
children | ffccf0080e54 |
comparison
equal
deleted
inserted
replaced
249:a065bf61caa1 | 250:79349fd04836 |
---|---|
6 import traceback | 6 import traceback |
7 | 7 |
8 from mercurial import context | 8 from mercurial import context |
9 from mercurial import hg | 9 from mercurial import hg |
10 from mercurial import ui | 10 from mercurial import ui |
11 from mercurial import util | 11 from mercurial import util as hgutil |
12 from mercurial import revlog | 12 from mercurial import revlog |
13 from mercurial import node | 13 from mercurial import node |
14 from svn import delta | 14 from svn import delta |
15 from svn import core | 15 from svn import core |
16 | 16 |
17 import svnexternals | 17 import svnexternals |
18 import util as our_util | 18 import util |
19 | 19 |
20 def pickle_atomic(data, file_path, dir=None): | 20 def pickle_atomic(data, file_path, dir=None): |
21 """pickle some data to a path atomically. | 21 """pickle some data to a path atomically. |
22 | 22 |
23 This is present because I kept corrupting my revmap by managing to hit ^C | 23 This is present because I kept corrupting my revmap by managing to hit ^C |
29 pickle.dump(data, f) | 29 pickle.dump(data, f) |
30 f.close() | 30 f.close() |
31 except: #pragma: no cover | 31 except: #pragma: no cover |
32 raise | 32 raise |
33 else: | 33 else: |
34 util.rename(path, file_path) | 34 hgutil.rename(path, file_path) |
35 | 35 |
36 def stash_exception_on_self(fn): | 36 def stash_exception_on_self(fn): |
37 """Stash any exception raised in the method on self. | 37 """Stash any exception raised in the method on self. |
38 | 38 |
39 This is required because the SWIG bindings just mutate any exception into | 39 This is required because the SWIG bindings just mutate any exception into |
98 self.subdir = subdir | 98 self.subdir = subdir |
99 if self.subdir and self.subdir[0] == '/': | 99 if self.subdir and self.subdir[0] == '/': |
100 self.subdir = self.subdir[1:] | 100 self.subdir = self.subdir[1:] |
101 self.revmap = {} | 101 self.revmap = {} |
102 if os.path.exists(self.revmap_file): | 102 if os.path.exists(self.revmap_file): |
103 self.revmap = our_util.parse_revmap(self.revmap_file) | 103 self.revmap = util.parse_revmap(self.revmap_file) |
104 self.branches = {} | 104 self.branches = {} |
105 if os.path.exists(self.branch_info_file): | 105 if os.path.exists(self.branch_info_file): |
106 f = open(self.branch_info_file) | 106 f = open(self.branch_info_file) |
107 self.branches = pickle.load(f) | 107 self.branches = pickle.load(f) |
108 f.close() | 108 f.close() |
158 assert os.path.isfile(self.uuid_file) | 158 assert os.path.isfile(self.uuid_file) |
159 else: | 159 else: |
160 self.repo = hg.repository(self.ui, repo_path, create=True) | 160 self.repo = hg.repository(self.ui, repo_path, create=True) |
161 os.makedirs(os.path.dirname(self.uuid_file)) | 161 os.makedirs(os.path.dirname(self.uuid_file)) |
162 f = open(self.revmap_file, 'w') | 162 f = open(self.revmap_file, 'w') |
163 f.write('%s\n' % our_util.REVMAP_FILE_VERSION) | 163 f.write('%s\n' % util.REVMAP_FILE_VERSION) |
164 f.flush() | 164 f.flush() |
165 f.close() | 165 f.close() |
166 | 166 |
167 def clear_current_info(self): | 167 def clear_current_info(self): |
168 '''Clear the info relevant to a replayed revision so that the next | 168 '''Clear the info relevant to a replayed revision so that the next |
632 parents = (self.get_parent_revision(rev.revnum, branch), | 632 parents = (self.get_parent_revision(rev.revnum, branch), |
633 revlog.nullid) | 633 revlog.nullid) |
634 if parents[0] in closed_revs and branch in self.branches_to_delete: | 634 if parents[0] in closed_revs and branch in self.branches_to_delete: |
635 continue | 635 continue |
636 # TODO this needs to be fixed with the new revmap | 636 # TODO this needs to be fixed with the new revmap |
637 extra = our_util.build_extra(rev.revnum, branch, | 637 extra = util.build_extra(rev.revnum, branch, |
638 open(self.uuid_file).read(), | 638 open(self.uuid_file).read(), |
639 self.subdir) | 639 self.subdir) |
640 if branch is not None: | 640 if branch is not None: |
641 if (branch not in self.branches | 641 if (branch not in self.branches |
642 and branch not in self.repo.branchtags()): | 642 and branch not in self.repo.branchtags()): |
643 continue | 643 continue |
644 parent_ctx = self.repo.changectx(parents[0]) | 644 parent_ctx = self.repo.changectx(parents[0]) |
674 filectxfn, | 674 filectxfn, |
675 self.authorforsvnauthor(rev.author), | 675 self.authorforsvnauthor(rev.author), |
676 date, | 676 date, |
677 extra) | 677 extra) |
678 new_hash = self.repo.commitctx(current_ctx) | 678 new_hash = self.repo.commitctx(current_ctx) |
679 our_util.describe_commit(self.ui, new_hash, branch) | 679 util.describe_commit(self.ui, new_hash, branch) |
680 if (rev.revnum, branch) not in self.revmap: | 680 if (rev.revnum, branch) not in self.revmap: |
681 self.add_to_revmap(rev.revnum, branch, new_hash) | 681 self.add_to_revmap(rev.revnum, branch, new_hash) |
682 # now we handle branches that need to be committed without any files | 682 # now we handle branches that need to be committed without any files |
683 for branch in self.commit_branches_empty: | 683 for branch in self.commit_branches_empty: |
684 ha = self.get_parent_revision(rev.revnum, branch) | 684 ha = self.get_parent_revision(rev.revnum, branch) |
687 parent_ctx = self.repo.changectx(ha) | 687 parent_ctx = self.repo.changectx(ha) |
688 def del_all_files(*args): | 688 def del_all_files(*args): |
689 raise IOError | 689 raise IOError |
690 # True here meant nuke all files, shouldn't happen with branch closing | 690 # True here meant nuke all files, shouldn't happen with branch closing |
691 if self.commit_branches_empty[branch]: #pragma: no cover | 691 if self.commit_branches_empty[branch]: #pragma: no cover |
692 raise util.Abort('Empty commit to an open branch attempted. ' | 692 raise hgutil.Abort('Empty commit to an open branch attempted. ' |
693 'Please report this issue.') | 693 'Please report this issue.') |
694 extra = our_util.build_extra(rev.revnum, branch, | 694 extra = util.build_extra(rev.revnum, branch, |
695 open(self.uuid_file).read(), | 695 open(self.uuid_file).read(), |
696 self.subdir) | 696 self.subdir) |
697 current_ctx = context.memctx(self.repo, | 697 current_ctx = context.memctx(self.repo, |
698 (ha, node.nullid), | 698 (ha, node.nullid), |
699 rev.message or ' ', | 699 rev.message or ' ', |
701 del_all_files, | 701 del_all_files, |
702 self.authorforsvnauthor(rev.author), | 702 self.authorforsvnauthor(rev.author), |
703 date, | 703 date, |
704 extra) | 704 extra) |
705 new_hash = self.repo.commitctx(current_ctx) | 705 new_hash = self.repo.commitctx(current_ctx) |
706 our_util.describe_commit(self.ui, new_hash, branch) | 706 util.describe_commit(self.ui, new_hash, branch) |
707 if (rev.revnum, branch) not in self.revmap: | 707 if (rev.revnum, branch) not in self.revmap: |
708 self.add_to_revmap(rev.revnum, branch, new_hash) | 708 self.add_to_revmap(rev.revnum, branch, new_hash) |
709 self._save_metadata() | 709 self._save_metadata() |
710 self.clear_current_info() | 710 self.clear_current_info() |
711 | 711 |
854 br_path2 = br_path + '/' | 854 br_path2 = br_path + '/' |
855 # assuming it is a directory | 855 # assuming it is a directory |
856 self.externals[path] = None | 856 self.externals[path] = None |
857 map(self.delete_file, [pat for pat in self.current_files.iterkeys() | 857 map(self.delete_file, [pat for pat in self.current_files.iterkeys() |
858 if pat.startswith(path+'/')]) | 858 if pat.startswith(path+'/')]) |
859 for f in ctx.walk(our_util.PrefixMatch(br_path2)): | 859 for f in ctx.walk(util.PrefixMatch(br_path2)): |
860 f_p = '%s/%s' % (path, f[len(br_path2):]) | 860 f_p = '%s/%s' % (path, f[len(br_path2):]) |
861 if f_p not in self.current_files: | 861 if f_p not in self.current_files: |
862 self.delete_file(f_p) | 862 self.delete_file(f_p) |
863 self.delete_file(path) | 863 self.delete_file(path) |
864 delete_entry = stash_exception_on_self(delete_entry) | 864 delete_entry = stash_exception_on_self(delete_entry) |
1053 target = cStringIO.StringIO() | 1053 target = cStringIO.StringIO() |
1054 self.stream = target | 1054 self.stream = target |
1055 | 1055 |
1056 handler, baton = delta.svn_txdelta_apply(source, target, None) | 1056 handler, baton = delta.svn_txdelta_apply(source, target, None) |
1057 if not callable(handler): #pragma: no cover | 1057 if not callable(handler): #pragma: no cover |
1058 raise util.Abort('Error in Subversion bindings: ' | 1058 raise hgutil.Abort('Error in Subversion bindings: ' |
1059 'cannot call handler!') | 1059 'cannot call handler!') |
1060 def txdelt_window(window): | 1060 def txdelt_window(window): |
1061 try: | 1061 try: |
1062 if not self._is_path_valid(self.current_file): | 1062 if not self._is_path_valid(self.current_file): |
1063 return | 1063 return |
1064 handler(window, baton) | 1064 handler(window, baton) |
1067 self.current_files[self.current_file] = target.getvalue() | 1067 self.current_files[self.current_file] = target.getvalue() |
1068 except core.SubversionException, e: #pragma: no cover | 1068 except core.SubversionException, e: #pragma: no cover |
1069 if e.apr_err == core.SVN_ERR_INCOMPLETE_DATA: | 1069 if e.apr_err == core.SVN_ERR_INCOMPLETE_DATA: |
1070 self.missing_plaintexts.add(self.current_file) | 1070 self.missing_plaintexts.add(self.current_file) |
1071 else: #pragma: no cover | 1071 else: #pragma: no cover |
1072 raise util.Abort(*e.args) | 1072 raise hgutil.Abort(*e.args) |
1073 except: #pragma: no cover | 1073 except: #pragma: no cover |
1074 print len(base), self.current_file | 1074 print len(base), self.current_file |
1075 self._exception_info = sys.exc_info() | 1075 self._exception_info = sys.exc_info() |
1076 raise | 1076 raise |
1077 return txdelt_window | 1077 return txdelt_window |