Mercurial > hg-stable
comparison hgext/convert/subversion.py @ 8881:76d3cd914c5e
convert/svn: remove dead code and obsolete comments
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 21 Jun 2009 23:04:01 +0200 |
parents | eb7b247a98ea |
children | 48a04961b0dd |
comparison
equal
deleted
inserted
replaced
8880:a3a936a2fe46 | 8881:76d3cd914c5e |
---|---|
1 # Subversion 1.4/1.5 Python API backend | 1 # Subversion 1.4/1.5 Python API backend |
2 # | 2 # |
3 # Copyright(C) 2007 Daniel Holth et al | 3 # Copyright(C) 2007 Daniel Holth et al |
4 # | |
5 # Configuration options: | |
6 # | |
7 # convert.svn.trunk | |
8 # Relative path to the trunk (default: "trunk") | |
9 # convert.svn.branches | |
10 # Relative path to tree of branches (default: "branches") | |
11 # convert.svn.tags | |
12 # Relative path to tree of tags (default: "tags") | |
13 # | |
14 # Set these in a hgrc, or on the command line as follows: | |
15 # | |
16 # hg convert --config convert.svn.trunk=wackoname [...] | |
17 | 4 |
18 import locale | 5 import locale |
19 import os | 6 import os |
20 import re | 7 import re |
21 import sys | 8 import sys |
211 '1.4 or later required') % version) | 198 '1.4 or later required') % version) |
212 except AttributeError: | 199 except AttributeError: |
213 raise MissingTool(_('Subversion python bindings are too old, 1.4 ' | 200 raise MissingTool(_('Subversion python bindings are too old, 1.4 ' |
214 'or later required')) | 201 'or later required')) |
215 | 202 |
216 self.encoding = locale.getpreferredencoding() | |
217 self.lastrevs = {} | 203 self.lastrevs = {} |
218 | 204 |
219 latest = None | 205 latest = None |
220 try: | 206 try: |
221 # Support file://path@rev syntax. Useful e.g. to convert | 207 # Support file://path@rev syntax. Useful e.g. to convert |
522 self.convertfp = open(os.path.join(self.wc, '.svn', 'hg-shamap'), | 508 self.convertfp = open(os.path.join(self.wc, '.svn', 'hg-shamap'), |
523 'a') | 509 'a') |
524 self.convertfp.write('%s %d\n' % (destrev, self.revnum(rev))) | 510 self.convertfp.write('%s %d\n' % (destrev, self.revnum(rev))) |
525 self.convertfp.flush() | 511 self.convertfp.flush() |
526 | 512 |
527 # -- helper functions -- | |
528 | |
529 def revid(self, revnum, module=None): | 513 def revid(self, revnum, module=None): |
530 if not module: | 514 if not module: |
531 module = self.module | 515 module = self.module |
532 return u"svn:%s%s@%s" % (self.uuid, module.decode(self.encoding), | 516 return u"svn:%s%s@%s" % (self.uuid, module.decode(self.encoding), |
533 revnum) | 517 revnum) |
596 def get_blacklist(self): | 580 def get_blacklist(self): |
597 """Avoid certain revision numbers. | 581 """Avoid certain revision numbers. |
598 It is not uncommon for two nearby revisions to cancel each other | 582 It is not uncommon for two nearby revisions to cancel each other |
599 out, e.g. 'I copied trunk into a subdirectory of itself instead | 583 out, e.g. 'I copied trunk into a subdirectory of itself instead |
600 of making a branch'. The converted repository is significantly | 584 of making a branch'. The converted repository is significantly |
601 smaller if we ignore such revisions.""" | 585 smaller if we ignore such revisions. |
586 """ | |
602 self.blacklist = set() | 587 self.blacklist = set() |
603 blacklist = self.blacklist | 588 blacklist = self.blacklist |
604 for line in file("blacklist.txt", "r"): | 589 for line in file("blacklist.txt", "r"): |
605 if not line.startswith("#"): | 590 if not line.startswith("#"): |
606 try: | 591 try: |
698 # not changed but it probably does not worth the pain. | 683 # not changed but it probably does not worth the pain. |
699 prevmodule = self.reparent('') | 684 prevmodule = self.reparent('') |
700 fromkind = svn.ra.check_path(self.ra, entrypath.strip('/'), fromrev) | 685 fromkind = svn.ra.check_path(self.ra, entrypath.strip('/'), fromrev) |
701 self.reparent(prevmodule) | 686 self.reparent(prevmodule) |
702 | 687 |
703 if fromkind == svn.core.svn_node_file: # a deleted file | 688 if fromkind == svn.core.svn_node_file: |
704 entries.append(self.recode(entry)) | 689 entries.append(self.recode(entry)) |
705 elif fromkind == svn.core.svn_node_dir: | 690 elif fromkind == svn.core.svn_node_dir: |
706 # print "Deleted/moved non-file:", revnum, path, ent | 691 # Sometimes this is tricky. For example: in The |
707 # children = self._find_children(path, revnum - 1) | 692 # Subversion Repository revision 6940 a dir was |
708 # print ("find children %s@%d from %d action %s" % | 693 # copied and one of its files was deleted from the |
709 # (path, revnum, ent.copyfrom_rev, ent.action)) | 694 # new location in the same commit. This code can't |
710 # Sometimes this is tricky. For example: in | 695 # deal with that yet. |
711 # The Subversion Repository revision 6940 a dir | |
712 # was copied and one of its files was deleted | |
713 # from the new location in the same commit. This | |
714 # code can't deal with that yet. | |
715 if ent.action == 'C': | 696 if ent.action == 'C': |
716 children = self._find_children(path, fromrev) | 697 children = self._find_children(path, fromrev) |
717 else: | 698 else: |
718 oroot = entrypath.strip('/') | 699 oroot = entrypath.strip('/') |
719 nroot = path.strip('/') | 700 nroot = path.strip('/') |
735 entries.append(entry) | 716 entries.append(entry) |
736 else: | 717 else: |
737 self.ui.debug(_('unknown path in revision %d: %s\n') % \ | 718 self.ui.debug(_('unknown path in revision %d: %s\n') % \ |
738 (revnum, path)) | 719 (revnum, path)) |
739 elif kind == svn.core.svn_node_dir: | 720 elif kind == svn.core.svn_node_dir: |
740 # Should probably synthesize normal file entries | |
741 # and handle as above to clean up copy/rename handling. | |
742 | |
743 # If the directory just had a prop change, | 721 # If the directory just had a prop change, |
744 # then we shouldn't need to look for its children. | 722 # then we shouldn't need to look for its children. |
745 if ent.action == 'M': | 723 if ent.action == 'M': |
746 continue | 724 continue |
747 | 725 |
748 # Also this could create duplicate entries. Not sure | |
749 # whether this will matter. Maybe should make entries a set. | |
750 # print "Changed directory", revnum, path, ent.action, \ | |
751 # ent.copyfrom_path, ent.copyfrom_rev | |
752 # This will fail if a directory was copied | |
753 # from another branch and then some of its files | |
754 # were deleted in the same transaction. | |
755 children = sorted(self._find_children(path, revnum)) | 726 children = sorted(self._find_children(path, revnum)) |
756 for child in children: | 727 for child in children: |
757 # Can we move a child directory and its | 728 # Can we move a child directory and its |
758 # parent in the same commit? (probably can). Could | 729 # parent in the same commit? (probably can). Could |
759 # cause problems if instead of revnum -1, | 730 # cause problems if instead of revnum -1, |
760 # we have to look in (copyfrom_path, revnum - 1) | 731 # we have to look in (copyfrom_path, revnum - 1) |
761 entrypath = self.getrelpath("/" + child) | 732 entrypath = self.getrelpath("/" + child) |
762 # print child, self.module, entrypath | |
763 if entrypath: | 733 if entrypath: |
764 # Need to filter out directories here... | 734 # Need to filter out directories here... |
765 kind = self._checkpath(entrypath, revnum) | 735 kind = self._checkpath(entrypath, revnum) |
766 if kind != svn.core.svn_node_dir: | 736 if kind != svn.core.svn_node_dir: |
767 entries.append(self.recode(entrypath)) | 737 entries.append(self.recode(entrypath)) |
768 | 738 |
769 # Copies here (must copy all from source) Probably not | 739 # Handle directory copies |
770 # a real problem for us if source does not exist | |
771 if not ent.copyfrom_path or not parents: | 740 if not ent.copyfrom_path or not parents: |
772 continue | 741 continue |
773 # Copy sources not in parent revisions cannot be | 742 # Copy sources not in parent revisions cannot be |
774 # represented, ignore their origin for now | 743 # represented, ignore their origin for now |
775 pmodule, prevnum = self.revsplit(parents[0])[1:] | 744 pmodule, prevnum = self.revsplit(parents[0])[1:] |