Mercurial > hg
annotate hgext/convert/subversion.py @ 4771:e2292928cbe6
convert: svn: convert branch trunk to default
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Jul 2007 22:23:33 -0700 |
parents | 4526ef8c47b2 |
children | 69548a9d9796 |
rev | line source |
---|---|
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
1 # Subversion 1.4/1.5 Python API backend |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
2 # |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
3 # Copyright(C) 2007 Daniel Holth et al |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
4 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
5 import pprint |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
6 import locale |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
7 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
8 from mercurial import util |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
9 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
10 # Subversion stuff. Works best with very recent Python SVN bindings |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
11 # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
12 # these bindings. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
13 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
14 from cStringIO import StringIO |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
15 |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
16 from common import NoRepo, commit, converter_source |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
17 |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
18 try: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
19 from svn.core import SubversionException, Pool |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
20 import svn.core |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
21 import svn.ra |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
22 import svn.delta |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
23 import svn |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
24 import transport |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
25 except ImportError: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
26 pass |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
27 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
28 class CompatibilityException(Exception): pass |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
29 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
30 nbRevisionsPerFetch = 50 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
31 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
32 class svn_entry(object): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
33 """Emulate a Subversion path change.""" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
34 __slots__ = ['path', 'copyfrom_path', 'copyfrom_rev', 'action'] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
35 def __init__(self, entry): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
36 self.copyfrom_path = entry.copyfrom_path |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
37 self.copyfrom_rev = entry.copyfrom_rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
38 self.action = entry.action |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
39 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
40 def __str__(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
41 return "%s %s %s" % (self.action, self.copyfrom_path, self.copyfrom_rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
42 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
43 def __repr__(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
44 return self.__str__() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
45 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
46 class svn_paths(object): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
47 """Emulate a Subversion ordered dictionary of changed paths.""" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
48 __slots__ = ['values', 'order'] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
49 def __init__(self, orig_paths): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
50 self.order = [] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
51 self.values = {} |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
52 if hasattr(orig_paths, 'keys'): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
53 self.order = sorted(orig_paths.keys()) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
54 self.values.update(orig_paths) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
55 return |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
56 if not orig_paths: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
57 return |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
58 for path in orig_paths: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
59 self.order.append(path) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
60 self.values[path] = svn_entry(orig_paths[path]) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
61 self.order.sort() # maybe the order it came in isn't so great... |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
62 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
63 def __iter__(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
64 return iter(self.order) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
65 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
66 def __getitem__(self, key): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
67 return self.values[key] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
68 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
69 def __str__(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
70 s = "{\n" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
71 for path in self.order: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
72 s += "'%s': %s,\n" % (path, self.values[path]) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
73 s += "}" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
74 return s |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
75 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
76 def __repr__(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
77 return self.__str__() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
78 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
79 # SVN conversion code stolen from bzr-svn and tailor |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
80 class convert_svn(converter_source): |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
81 def __init__(self, ui, url, rev=None): |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
82 try: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
83 SubversionException |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
84 except NameError: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
85 msg = 'subversion python bindings could not be loaded\n' |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
86 ui.warn(msg) |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
87 raise NoRepo(msg) |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
88 |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
89 self.ui = ui |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
90 self.encoding = locale.getpreferredencoding() |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
91 latest = None |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
92 if rev: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
93 try: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
94 latest = int(rev) |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
95 except ValueError: |
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
96 raise util.Abort('svn: revision %s is not an integer' % rev) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
97 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
98 # Support file://path@rev syntax. Useful e.g. to convert |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
99 # deleted branches. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
100 url, latest = url.rsplit("@", 1) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
101 latest = int(latest) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
102 except ValueError, e: |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
103 pass |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
104 self.url = url |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
105 self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
106 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
107 self.transport = transport.SvnRaTransport(url = url) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
108 self.ra = self.transport.ra |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
109 self.base = svn.ra.get_repos_root(self.ra) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
110 self.module = self.url[len(self.base):] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
111 self.modulemap = {} # revision, module |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
112 self.commits = {} |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
113 self.files = {} |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
114 self.uuid = svn.ra.get_uuid(self.ra).decode(self.encoding) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
115 except SubversionException, e: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
116 raise NoRepo("couldn't open SVN repo %s" % url) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
117 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
118 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
119 self.get_blacklist() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
120 except IOError, e: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
121 pass |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
122 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
123 if not latest: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
124 latest = svn.ra.get_latest_revnum(self.ra) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
125 dirent = svn.ra.stat(self.ra, self.module, latest) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
126 self.last_changed = dirent.created_rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
127 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
128 self.head = self.rev(self.last_changed) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
129 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
130 # Should lazily fetch revisions in batches of, say, 1,000...: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
131 self._fetch_revisions(from_revnum=self.last_changed, to_revnum=0) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
132 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
133 def rev(self, revnum): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
134 return (u"svn:%s%s@%s" % (self.uuid, self.module, revnum)).decode(self.encoding) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
135 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
136 def get_blacklist(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
137 """Avoid certain revision numbers. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
138 It is not uncommon for two nearby revisions to cancel each other |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
139 out, e.g. 'I copied trunk into a subdirectory of itself instead |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
140 of making a branch'. The converted repository is significantly |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
141 smaller if we ignore such revisions.""" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
142 self.blacklist = set() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
143 blacklist = self.blacklist |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
144 for line in file("blacklist.txt", "r"): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
145 if not line.startswith("#"): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
146 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
147 svn_rev = int(line.strip()) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
148 blacklist.add(svn_rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
149 except ValueError, e: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
150 pass # not an integer or a comment |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
151 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
152 def is_blacklisted(self, svn_rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
153 return svn_rev in self.blacklist |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
154 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
155 def reparent(self, module): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
156 svn_url = self.base + module |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
157 self.ui.debug("reparent to %s\n" % svn_url.encode(self.encoding)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
158 svn.ra.reparent(self.ra, svn_url.encode(self.encoding)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
159 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
160 def _fetch_revisions(self, from_revnum = 0, to_revnum = 347, pb=None): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
161 self.parent_cset = None |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
162 self.child_cset = None |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
163 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
164 self.ui.debug('Fetching revisions %d to %d\n' % (from_revnum, to_revnum)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
165 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
166 def get_entry_from_path(path, module=self.module): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
167 # Given the repository url of this wc, say |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
168 # "http://server/plone/CMFPlone/branches/Plone-2_0-branch" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
169 # extract the "entry" portion (a relative path) from what |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
170 # svn log --xml says, ie |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
171 # "/CMFPlone/branches/Plone-2_0-branch/tests/PloneTestCase.py" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
172 # that is to say "tests/PloneTestCase.py" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
173 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
174 if path.startswith(module): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
175 relative = path[len(module):] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
176 if relative.startswith('/'): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
177 return relative[1:] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
178 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
179 return relative |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
180 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
181 # The path is outside our tracked tree... |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
182 self.ui.debug('Ignoring %r since it is not under %r\n' % (path, module)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
183 return None |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
184 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
185 received = [] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
186 def rcvr(*arg, **args): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
187 orig_paths, revnum, author, date, message, pool = arg |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
188 new_orig_paths = svn_paths(orig_paths) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
189 rcvr2(new_orig_paths, revnum, author, date, message, pool) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
190 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
191 def rcvr2(orig_paths, revnum, author, date, message, pool, better_paths = None): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
192 if not self.is_blacklisted(revnum): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
193 received.append((orig_paths, revnum, author, date, message)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
194 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
195 def after_received(orig_paths, revnum, author, date, message): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
196 if revnum in self.modulemap: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
197 new_module = self.modulemap[revnum] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
198 if new_module != self.module: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
199 self.module = new_module |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
200 self.reparent(self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
201 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
202 copyfrom = {} # Map of entrypath, revision for finding source of deleted revisions. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
203 copies = {} |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
204 entries = [] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
205 self.ui.debug("Parsing revision %d\n" % revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
206 if orig_paths is not None: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
207 rev = self.rev(revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
208 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
209 branch = self.module.split("/")[-1] |
4771
e2292928cbe6
convert: svn: convert branch trunk to default
Brendan Cully <brendan@kublai.com>
parents:
4770
diff
changeset
|
210 if branch == 'trunk': |
e2292928cbe6
convert: svn: convert branch trunk to default
Brendan Cully <brendan@kublai.com>
parents:
4770
diff
changeset
|
211 branch = '' |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
212 except IndexError: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
213 branch = None |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
214 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
215 for path in orig_paths: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
216 # self.ui.write("path %s\n" % path) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
217 if path == self.module: # Follow branching back in history |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
218 ent = orig_paths[path] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
219 if ent: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
220 if ent.copyfrom_path: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
221 self.modulemap[ent.copyfrom_rev] = ent.copyfrom_path |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
222 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
223 self.ui.debug("No copyfrom path, don't know what to do.\n") |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
224 # Maybe it was added and there is no more history. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
225 entrypath = get_entry_from_path(path, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
226 # self.ui.write("entrypath %s\n" % entrypath) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
227 if not entrypath: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
228 # Outside our area of interest |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
229 self.ui.debug("boring@%s: %s\n" % (revnum, path)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
230 continue |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
231 entry = entrypath.decode(self.encoding) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
232 ent = orig_paths[path] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
233 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
234 kind = svn.ra.check_path(self.ra, entrypath, revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
235 if kind == svn.core.svn_node_file: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
236 if ent.copyfrom_path: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
237 copyfrom_path = get_entry_from_path(ent.copyfrom_path) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
238 if copyfrom_path: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
239 self.ui.debug("Copied to %s from %s@%s\n" % (entry, copyfrom_path, ent.copyfrom_rev)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
240 # It's probably important for hg that the source |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
241 # exists in the revision's parent, not just the |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
242 # ent.copyfrom_rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
243 fromkind = svn.ra.check_path(self.ra, copyfrom_path, ent.copyfrom_rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
244 if fromkind != 0: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
245 copies[self.recode(entry)] = self.recode(copyfrom_path) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
246 entries.append(self.recode(entry)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
247 elif kind == 0: # gone, but had better be a deleted *file* |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
248 self.ui.debug("gone from %s\n" % ent.copyfrom_rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
249 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
250 fromrev = revnum - 1 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
251 # might always need to be revnum - 1 in these 3 lines? |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
252 old_module = self.modulemap.get(fromrev, self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
253 basepath = old_module + "/" + get_entry_from_path(path, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
254 entrypath = old_module + "/" + get_entry_from_path(path, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
255 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
256 def lookup_parts(p): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
257 rc = None |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
258 parts = p.split("/") |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
259 for i in range(len(parts)): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
260 part = "/".join(parts[:i]) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
261 info = part, copyfrom.get(part, None) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
262 if info[1] is not None: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
263 self.ui.debug("Found parent directory %s\n" % info) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
264 rc = info |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
265 return rc |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
266 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
267 self.ui.debug("base, entry %s %s\n" % (basepath, entrypath)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
268 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
269 frompath, froment = lookup_parts(entrypath) or (None, revnum - 1) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
270 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
271 # need to remove fragment from lookup_parts and replace with copyfrom_path |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
272 if frompath is not None: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
273 self.ui.debug("munge-o-matic\n") |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
274 self.ui.debug(entrypath + '\n') |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
275 self.ui.debug(entrypath[len(frompath):] + '\n') |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
276 entrypath = froment.copyfrom_path + entrypath[len(frompath):] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
277 fromrev = froment.copyfrom_rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
278 self.ui.debug("Info: %s %s %s %s\n" % (frompath, froment, ent, entrypath)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
279 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
280 fromkind = svn.ra.check_path(self.ra, entrypath, fromrev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
281 if fromkind == svn.core.svn_node_file: # a deleted file |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
282 entries.append(self.recode(entry)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
283 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
284 # print "Deleted/moved non-file:", revnum, path, ent |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
285 # children = self._find_children(path, revnum - 1) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
286 # print "find children %s@%d from %d action %s" % (path, revnum, ent.copyfrom_rev, ent.action) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
287 # Sometimes this is tricky. For example: in |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
288 # The Subversion Repository revision 6940 a dir |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
289 # was copied and one of its files was deleted |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
290 # from the new location in the same commit. This |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
291 # code can't deal with that yet. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
292 if ent.action == 'C': |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
293 children = self._find_children(path, fromrev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
294 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
295 oroot = entrypath.strip('/') |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
296 nroot = path.strip('/') |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
297 children = self._find_children(oroot, fromrev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
298 children = [s.replace(oroot,nroot) for s in children] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
299 # Mark all [files, not directories] as deleted. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
300 for child in children: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
301 # Can we move a child directory and its |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
302 # parent in the same commit? (probably can). Could |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
303 # cause problems if instead of revnum -1, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
304 # we have to look in (copyfrom_path, revnum - 1) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
305 entrypath = get_entry_from_path("/" + child, module=old_module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
306 if entrypath: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
307 entry = self.recode(entrypath.decode(self.encoding)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
308 if entry in copies: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
309 # deleted file within a copy |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
310 del copies[entry] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
311 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
312 entries.append(entry) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
313 elif kind == svn.core.svn_node_dir: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
314 # Should probably synthesize normal file entries |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
315 # and handle as above to clean up copy/rename handling. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
316 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
317 # If the directory just had a prop change, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
318 # then we shouldn't need to look for its children. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
319 # Also this could create duplicate entries. Not sure |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
320 # whether this will matter. Maybe should make entries a set. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
321 # print "Changed directory", revnum, path, ent.action, ent.copyfrom_path, ent.copyfrom_rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
322 # This will fail if a directory was copied |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
323 # from another branch and then some of its files |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
324 # were deleted in the same transaction. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
325 children = self._find_children(path, revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
326 children.sort() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
327 for child in children: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
328 # Can we move a child directory and its |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
329 # parent in the same commit? (probably can). Could |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
330 # cause problems if instead of revnum -1, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
331 # we have to look in (copyfrom_path, revnum - 1) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
332 entrypath = get_entry_from_path("/" + child, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
333 # print child, self.module, entrypath |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
334 if entrypath: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
335 # Need to filter out directories here... |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
336 kind = svn.ra.check_path(self.ra, entrypath, revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
337 if kind != svn.core.svn_node_dir: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
338 entries.append(self.recode(entrypath)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
339 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
340 # Copies here (must copy all from source) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
341 # Probably not a real problem for us if |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
342 # source does not exist |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
343 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
344 # Can do this with the copy command "hg copy" |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
345 # if ent.copyfrom_path: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
346 # copyfrom_entry = get_entry_from_path(ent.copyfrom_path.decode(self.encoding), |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
347 # module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
348 # copyto_entry = entrypath |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
349 # |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
350 # print "copy directory", copyfrom_entry, 'to', copyto_entry |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
351 # |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
352 # copies.append((copyfrom_entry, copyto_entry)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
353 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
354 if ent.copyfrom_path: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
355 copyfrom_path = ent.copyfrom_path.decode(self.encoding) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
356 copyfrom_entry = get_entry_from_path(copyfrom_path, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
357 if copyfrom_entry: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
358 copyfrom[path] = ent |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
359 self.ui.debug("mark %s came from %s\n" % (path, copyfrom[path])) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
360 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
361 # Good, /probably/ a regular copy. Really should check |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
362 # to see whether the parent revision actually contains |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
363 # the directory in question. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
364 children = self._find_children(self.recode(copyfrom_path), ent.copyfrom_rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
365 children.sort() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
366 for child in children: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
367 entrypath = get_entry_from_path("/" + child, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
368 if entrypath: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
369 entry = entrypath.decode(self.encoding) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
370 # print "COPY COPY From", copyfrom_entry, entry |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
371 copyto_path = path + entry[len(copyfrom_entry):] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
372 copyto_entry = get_entry_from_path(copyto_path, module=self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
373 # print "COPY", entry, "COPY To", copyto_entry |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
374 copies[self.recode(copyto_entry)] = self.recode(entry) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
375 # copy from quux splort/quuxfile |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
376 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
377 self.modulemap[revnum] = self.module # track backwards in time |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
378 # a list of (filename, id) where id lets us retrieve the file. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
379 # eg in git, id is the object hash. for svn it'll be the |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
380 self.files[rev] = zip(entries, [rev] * len(entries)) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
381 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
382 # Example SVN datetime. Includes microseconds. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
383 # ISO-8601 conformant |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
384 # '2007-01-04T17:35:00.902377Z' |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
385 date = util.parsedate(date[:18] + " UTC", ["%Y-%m-%dT%H:%M:%S"]) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
386 |
4766
95cbb6b74790
convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
387 log = message and self.recode(message) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
388 author = author and self.recode(author) or '' |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
389 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
390 cset = commit(author=author, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
391 date=util.datestr(date), |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
392 desc=log, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
393 parents=[], |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
394 copies=copies, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
395 branch=branch) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
396 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
397 if self.child_cset is not None: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
398 self.child_cset.parents = [rev] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
399 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
400 self.child_cset = cset |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
401 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
402 self.commits[rev] = cset |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
403 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
404 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
405 discover_changed_paths = True |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
406 strict_node_history = False |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
407 svn.ra.get_log(self.ra, [self.module], from_revnum, to_revnum, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
408 0, discover_changed_paths, strict_node_history, rcvr) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
409 for args in received: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
410 after_received(*args) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
411 self.last_revnum = to_revnum |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
412 except SubversionException, (_, num): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
413 if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
414 raise NoSuchRevision(branch=self, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
415 revision="Revision number %d" % to_revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
416 raise |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
417 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
418 def getheads(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
419 # svn-url@rev |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
420 # Not safe if someone committed: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
421 self.heads = [self.head] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
422 # print self.commits.keys() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
423 return self.heads |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
424 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
425 def _getfile(self, file, rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
426 io = StringIO() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
427 # TODO: ra.get_file transmits the whole file instead of diffs. |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
428 mode = '' |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
429 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
430 revnum = int(rev.split("@")[-1]) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
431 if self.module != self.modulemap[revnum]: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
432 self.module = self.modulemap[revnum] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
433 self.reparent(self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
434 info = svn.ra.get_file(self.ra, file, revnum, io) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
435 if isinstance(info, list): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
436 info = info[-1] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
437 mode = ("svn:executable" in info) and 'x' or '' |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
438 mode = ("svn:special" in info) and 'l' or mode |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
439 except SubversionException, e: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
440 notfound = (svn.core.SVN_ERR_FS_NOT_FOUND, |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
441 svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
442 if e.apr_err in notfound: # File not found |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
443 raise IOError() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
444 raise |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
445 data = io.getvalue() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
446 if mode == 'l': |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
447 link_prefix = "link " |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
448 if data.startswith(link_prefix): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
449 data = data[len(link_prefix):] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
450 return data, mode |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
451 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
452 def getfile(self, file, rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
453 data, mode = self._getfile(file, rev) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
454 self.modecache[(file, rev)] = mode |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
455 return data |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
456 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
457 def getmode(self, file, rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
458 return self.modecache[(file, rev)] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
459 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
460 def getchanges(self, rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
461 self.modecache = {} |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
462 files = self.files[rev] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
463 cl = files |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
464 cl.sort() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
465 return cl |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
466 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
467 def getcommit(self, rev): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
468 return self.commits[rev] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
469 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
470 def gettags(self): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
471 return [] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
472 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
473 def _find_children(self, path, revnum): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
474 path = path.strip("/") |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
475 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
476 def _find_children_fallback(path, revnum): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
477 # SWIG python bindings for getdir are broken up to at least 1.4.3 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
478 if not hasattr(self, 'client_ctx'): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
479 self.client_ctx = svn.client.create_context() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
480 optrev = svn.core.svn_opt_revision_t() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
481 optrev.kind = svn.core.svn_opt_revision_number |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
482 optrev.value.number = revnum |
4770
4526ef8c47b2
convert: svn: fix fallback directory listing code when importing a submodule
Brendan Cully <brendan@kublai.com>
parents:
4769
diff
changeset
|
483 rpath = '/'.join([self.base, path]).strip('/') |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
484 return ['%s/%s' % (path, x) for x in svn.client.ls(rpath, optrev, True, self.client_ctx).keys()] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
485 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
486 if hasattr(self, '_find_children_fallback'): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
487 return _find_children_fallback(path, revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
488 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
489 self.reparent("/" + path) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
490 pool = Pool() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
491 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
492 children = [] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
493 def find_children_inner(children, path, revnum = revnum): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
494 if hasattr(svn.ra, 'get_dir2'): # Since SVN 1.4 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
495 fields = 0xffffffff # Binding does not provide SVN_DIRENT_ALL |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
496 getdir = svn.ra.get_dir2(self.ra, path, revnum, fields, pool) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
497 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
498 getdir = svn.ra.get_dir(self.ra, path, revnum, pool) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
499 if type(getdir) == dict: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
500 # python binding for getdir is broken up to at least 1.4.3 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
501 raise CompatibilityException() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
502 dirents = getdir[0] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
503 if type(dirents) == int: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
504 # got here once due to infinite recursion bug |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
505 # pprint.pprint(getdir) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
506 return |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
507 c = dirents.keys() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
508 c.sort() |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
509 for child in c: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
510 dirent = dirents[child] |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
511 if dirent.kind == svn.core.svn_node_dir: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
512 find_children_inner(children, (path + "/" + child).strip("/")) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
513 else: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
514 children.append((path + "/" + child).strip("/")) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
515 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
516 try: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
517 find_children_inner(children, "") |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
518 except CompatibilityException: |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
519 self._find_children_fallback = True |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
520 self.reparent(self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
521 return _find_children_fallback(path, revnum) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
522 |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
523 self.reparent(self.module) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff
changeset
|
524 return [path + "/" + c for c in children] |