annotate hgext/convert/subversion.py @ 8380:a00a4db76a15

context: replace pseudo-set by real set
author Simon Heimberg <simohe@besonet.ch>
date Thu, 14 May 2009 10:59:55 +0200
parents f55869abb5c3
children b9ec04eb2aa3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
4 #
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
5 # Configuration options:
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
6 #
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
7 # convert.svn.trunk
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
8 # Relative path to the trunk (default: "trunk")
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
9 # convert.svn.branches
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
10 # Relative path to tree of branches (default: "branches")
5462
91a522a69c13 convert: svn -- fix tags handling
Kirill Smelkov <kirr@landau.phys.spbu.ru>
parents: 5461
diff changeset
11 # convert.svn.tags
91a522a69c13 convert: svn -- fix tags handling
Kirill Smelkov <kirr@landau.phys.spbu.ru>
parents: 5461
diff changeset
12 # Relative path to tree of tags (default: "tags")
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
13 #
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
14 # Set these in a hgrc, or on the command line as follows:
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
15 #
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
16 # hg convert --config convert.svn.trunk=wackoname [...]
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
17
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
18 import locale
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
19 import os
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
20 import re
5139
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
21 import sys
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
22 import cPickle as pickle
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
23 import tempfile
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
24 import urllib
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
25
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
26 from mercurial import strutil, util
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
27 from mercurial.i18n import _
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
28
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
29 # Subversion stuff. Works best with very recent Python SVN bindings
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
30 # 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
31 # these bindings.
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
32
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
33 from cStringIO import StringIO
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
34
7447
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
35 from common import NoRepo, MissingTool, commit, encodeargs, decodeargs
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
36 from common import commandline, converter_source, converter_sink, mapfile
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
37
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
38 try:
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
39 from svn.core import SubversionException, Pool
5010
6b2d8caf87b2 convert svn: try to extract URL from source if it is a working directory
Brendan Cully <brendan@kublai.com>
parents: 5008
diff changeset
40 import svn
6b2d8caf87b2 convert svn: try to extract URL from source if it is a working directory
Brendan Cully <brendan@kublai.com>
parents: 5008
diff changeset
41 import svn.client
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
42 import svn.core
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
43 import svn.ra
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
44 import svn.delta
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
45 import transport
8221
f35b933044cc convert: hide svn deprecation warnings
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8219
diff changeset
46 import warnings
f35b933044cc convert: hide svn deprecation warnings
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8219
diff changeset
47 warnings.filterwarnings('ignore',
f35b933044cc convert: hide svn deprecation warnings
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8219
diff changeset
48 module='svn.core',
f35b933044cc convert: hide svn deprecation warnings
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8219
diff changeset
49 category=DeprecationWarning)
f35b933044cc convert: hide svn deprecation warnings
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 8219
diff changeset
50
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
51 except ImportError:
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
52 pass
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
53
7381
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
54 class SvnPathNotFound(Exception):
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
55 pass
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
56
5008
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
57 def geturl(path):
5010
6b2d8caf87b2 convert svn: try to extract URL from source if it is a working directory
Brendan Cully <brendan@kublai.com>
parents: 5008
diff changeset
58 try:
5020
780051cca03c convert svn: canonicalize path before calling url_from_path.
Brendan Cully <brendan@kublai.com>
parents: 5010
diff changeset
59 return svn.client.url_from_path(svn.core.svn_path_canonicalize(path))
5010
6b2d8caf87b2 convert svn: try to extract URL from source if it is a working directory
Brendan Cully <brendan@kublai.com>
parents: 5008
diff changeset
60 except SubversionException:
6b2d8caf87b2 convert svn: try to extract URL from source if it is a working directory
Brendan Cully <brendan@kublai.com>
parents: 5008
diff changeset
61 pass
5008
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
62 if os.path.isdir(path):
5793
68f5bf9aa582 convert: Accept local path on win32.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5790
diff changeset
63 path = os.path.normpath(os.path.abspath(path))
68f5bf9aa582 convert: Accept local path on win32.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5790
diff changeset
64 if os.name == 'nt':
5842
111ed8c871bf Use util.normpath() instead of direct path string operation.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5841
diff changeset
65 path = '/' + util.normpath(path)
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
66 return 'file://%s' % urllib.quote(path)
5008
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
67 return path
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
68
5117
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
69 def optrev(number):
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
70 optrev = svn.core.svn_opt_revision_t()
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
71 optrev.kind = svn.core.svn_opt_revision_number
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
72 optrev.value.number = number
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
73 return optrev
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
74
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
75 class changedpath(object):
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
76 def __init__(self, p):
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
77 self.copyfrom_path = p.copyfrom_path
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
78 self.copyfrom_rev = p.copyfrom_rev
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
79 self.action = p.action
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
80
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
81 def get_log_child(fp, url, paths, start, end, limit=0, discover_changed_paths=True,
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
82 strict_node_history=False):
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
83 protocol = -1
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
84 def receiver(orig_paths, revnum, author, date, message, pool):
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
85 if orig_paths is not None:
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
86 for k, v in orig_paths.iteritems():
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
87 orig_paths[k] = changedpath(v)
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
88 pickle.dump((orig_paths, revnum, author, date, message),
5143
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5141
diff changeset
89 fp, protocol)
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5141
diff changeset
90
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
91 try:
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
92 # Use an ra of our own so that our parent can consume
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
93 # our results without confusing the server.
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
94 t = transport.SvnRaTransport(url=url)
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
95 svn.ra.get_log(t.ra, paths, start, end, limit,
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
96 discover_changed_paths,
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
97 strict_node_history,
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
98 receiver)
5140
792c1d979097 Replace _ with inst for catching exceptions to not shadow gettext.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5139
diff changeset
99 except SubversionException, (inst, num):
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
100 pickle.dump(num, fp, protocol)
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
101 except IOError:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
102 # Caller may interrupt the iteration
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
103 pickle.dump(None, fp, protocol)
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
104 else:
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
105 pickle.dump(None, fp, protocol)
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
106 fp.close()
6397
e1402cf5e08a convert: avoid svn log retrieval process cleanup
Patrick Mezard <pmezard@gmail.com>
parents: 6281
diff changeset
107 # With large history, cleanup process goes crazy and suddenly
e1402cf5e08a convert: avoid svn log retrieval process cleanup
Patrick Mezard <pmezard@gmail.com>
parents: 6281
diff changeset
108 # consumes *huge* amount of memory. The output file being closed,
e1402cf5e08a convert: avoid svn log retrieval process cleanup
Patrick Mezard <pmezard@gmail.com>
parents: 6281
diff changeset
109 # there is no need for clean termination.
e1402cf5e08a convert: avoid svn log retrieval process cleanup
Patrick Mezard <pmezard@gmail.com>
parents: 6281
diff changeset
110 os._exit(0)
5127
39b6eaee6fd7 convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents: 5122
diff changeset
111
5139
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
112 def debugsvnlog(ui, **opts):
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
113 """Fetch SVN log in a subprocess and channel them back to parent to
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
114 avoid memory collection issues.
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
115 """
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
116 util.set_binary(sys.stdin)
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
117 util.set_binary(sys.stdout)
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
118 args = decodeargs(sys.stdin.read())
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
119 get_log_child(sys.stdout, *args)
18abf13064cb Move debugsvnlog to subversion module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5138
diff changeset
120
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
121 class logstream:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
122 """Interruptible revision log iterator."""
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
123 def __init__(self, stdout):
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
124 self._stdout = stdout
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
125
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
126 def __iter__(self):
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
127 while True:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
128 entry = pickle.load(self._stdout)
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
129 try:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
130 orig_paths, revnum, author, date, message = entry
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
131 except:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
132 if entry is None:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
133 break
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
134 raise SubversionException("child raised exception", entry)
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
135 yield entry
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
136
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
137 def close(self):
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
138 if self._stdout:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
139 self._stdout.close()
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
140 self._stdout = None
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
141
8074
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
142
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
143 # Check to see if the given path is a local Subversion repo. Verify this by
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
144 # looking for several svn-specific files and directories in the given
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
145 # directory.
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
146 def filecheck(path, proto):
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
147 for x in ('locks', 'hooks', 'format', 'db', ):
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
148 if not os.path.exists(os.path.join(path, x)):
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
149 return False
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
150 return True
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
151
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
152 # Check to see if a given path is the root of an svn repo over http. We verify
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
153 # this by requesting a version-controlled URL we know can't exist and looking
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
154 # for the svn-specific "not found" XML.
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
155 def httpcheck(path, proto):
8219
21cf74ff2deb whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8214
diff changeset
156 return ('<m:human-readable errcode="160013">' in
21cf74ff2deb whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8214
diff changeset
157 urllib.urlopen('%s://%s/!svn/ver/0/.svn' % (proto, path)).read())
8074
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
158
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
159 protomap = {'http': httpcheck,
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
160 'https': httpcheck,
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
161 'file': filecheck,
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
162 }
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
163 def issvnurl(url):
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
164 if not '://' in url:
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
165 return False
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
166 proto, path = url.split('://', 1)
8214
a2af1d92b913 convert/svn: fix pathname parsing from URL under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 8210
diff changeset
167 path = urllib.url2pathname(path).replace(os.sep, '/')
8074
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
168 check = protomap.get(proto, lambda p, p2: False)
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
169 while '/' in path:
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
170 if check(path, proto):
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
171 return True
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
172 path = path.rsplit('/', 1)[0]
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
173 return False
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
174
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
175 # SVN conversion code stolen from bzr-svn and tailor
5876
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
176 #
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
177 # Subversion looks like a versioned filesystem, branches structures
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
178 # are defined by conventions and not enforced by the tool. First,
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
179 # we define the potential branches (modules) as "trunk" and "branches"
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
180 # children directories. Revisions are then identified by their
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
181 # module and revision number (and a repository identifier).
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
182 #
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
183 # The revision graph is really a tree (or a forest). By default, a
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
184 # revision parent is the previous revision in the same module. If the
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
185 # module directory is copied/moved from another module then the
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
186 # revision is the module root and its parent the source revision in
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
187 # the parent module. A revision has at most one parent.
fb93c774dfff convert: document the subversion conversion model
Patrick Mezard <pmezard@gmail.com>
parents: 5875
diff changeset
188 #
5438
6fa5258be3d4 convert: rename convert_svn to svn_source
Bryan O'Sullivan <bos@serpentine.com>
parents: 5437
diff changeset
189 class svn_source(converter_source):
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
190 def __init__(self, ui, url, rev=None):
5438
6fa5258be3d4 convert: rename convert_svn to svn_source
Bryan O'Sullivan <bos@serpentine.com>
parents: 5437
diff changeset
191 super(svn_source, self).__init__(ui, url, rev=rev)
4807
15a3cbfc6568 convert: call superclass init from engine init functions
Brendan Cully <brendan@kublai.com>
parents: 4799
diff changeset
192
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7875
diff changeset
193 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7875
diff changeset
194 (os.path.exists(url) and
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7875
diff changeset
195 os.path.exists(os.path.join(url, '.svn'))) or
8074
fc78313cba53 convert: Improved svn source detection.
Augie Fackler <durin42@gmail.com>
parents: 7973
diff changeset
196 issvnurl(url)):
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7875
diff changeset
197 raise NoRepo("%s does not look like a Subversion repo" % url)
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7875
diff changeset
198
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
199 try:
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
200 SubversionException
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
201 except NameError:
7447
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
202 raise MissingTool(_('Subversion python bindings could not be loaded'))
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
203
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
204 try:
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
205 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
206 if version < (1, 4):
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
207 raise MissingTool(_('Subversion python bindings %d.%d found, '
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
208 '1.4 or later required') % version)
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
209 except AttributeError:
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
210 raise MissingTool(_('Subversion python bindings are too old, 1.4 '
4fd92687f331 convert: improve reporting of invalid svn bindings
Patrick Mezard <pmezard@gmail.com>
parents: 7446
diff changeset
211 'or later required'))
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
212
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
213 self.encoding = locale.getpreferredencoding()
4813
1fcdf2fe3d7c convert: svn: use revmap to parse only new revisions in incremental conversions
Brendan Cully <brendan@kublai.com>
parents: 4811
diff changeset
214 self.lastrevs = {}
1fcdf2fe3d7c convert: svn: use revmap to parse only new revisions in incremental conversions
Brendan Cully <brendan@kublai.com>
parents: 4811
diff changeset
215
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
216 latest = None
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
217 try:
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
218 # Support file://path@rev syntax. Useful e.g. to convert
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
219 # deleted branches.
4927
5e89b0dafce5 convert/subversion.py: str.rsplit is not available in Python 2.3
Bryan O'Sullivan <bos@serpentine.com>
parents: 4925
diff changeset
220 at = url.rfind('@')
5e89b0dafce5 convert/subversion.py: str.rsplit is not available in Python 2.3
Bryan O'Sullivan <bos@serpentine.com>
parents: 4925
diff changeset
221 if at >= 0:
5e89b0dafce5 convert/subversion.py: str.rsplit is not available in Python 2.3
Bryan O'Sullivan <bos@serpentine.com>
parents: 4925
diff changeset
222 latest = int(url[at+1:])
5e89b0dafce5 convert/subversion.py: str.rsplit is not available in Python 2.3
Bryan O'Sullivan <bos@serpentine.com>
parents: 4925
diff changeset
223 url = url[:at]
7874
d812029cda85 cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7857
diff changeset
224 except ValueError:
4766
95cbb6b74790 convert: activate subversion engine
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
225 pass
5008
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
226 self.url = geturl(url)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
227 self.encoding = 'UTF-8' # Subversion is always nominal UTF-8
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
228 try:
5008
b6c3abdbe0eb convert: urlify svn repos if necessary.
Brendan Cully <brendan@kublai.com>
parents: 4960
diff changeset
229 self.transport = transport.SvnRaTransport(url=self.url)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
230 self.ra = self.transport.ra
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
231 self.ctx = self.transport.client
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
232 self.baseurl = svn.ra.get_repos_root(self.ra)
6538
05dff77bfbd9 convert: fix subpaths detection in svn source
Patrick Mezard <pmezard@gmail.com>
parents: 6493
diff changeset
233 # Module is either empty or a repository path starting with
05dff77bfbd9 convert: fix subpaths detection in svn source
Patrick Mezard <pmezard@gmail.com>
parents: 6493
diff changeset
234 # a slash and not ending with a slash.
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
235 self.module = urllib.unquote(self.url[len(self.baseurl):])
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
236 self.prevmodule = None
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
237 self.rootmodule = self.module
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
238 self.commits = {}
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
239 self.paths = {}
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
240 self.uuid = svn.ra.get_uuid(self.ra).decode(self.encoding)
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
241 except SubversionException:
8206
cce63ef1045b ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents: 8172
diff changeset
242 ui.traceback()
5521
03496d4fa509 convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5462
diff changeset
243 raise NoRepo("%s does not look like a Subversion repo" % self.url)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
244
5145
0751c25ea0c0 raise util.Abort again if specified revision is not an integer.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5144
diff changeset
245 if rev:
0751c25ea0c0 raise util.Abort again if specified revision is not an integer.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5144
diff changeset
246 try:
0751c25ea0c0 raise util.Abort again if specified revision is not an integer.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5144
diff changeset
247 latest = int(rev)
0751c25ea0c0 raise util.Abort again if specified revision is not an integer.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5144
diff changeset
248 except ValueError:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
249 raise util.Abort(_('svn: revision %s is not an integer') % rev)
5145
0751c25ea0c0 raise util.Abort again if specified revision is not an integer.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5144
diff changeset
250
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
251 self.startrev = self.ui.config('convert', 'svn.startrev', default=0)
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
252 try:
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
253 self.startrev = int(self.startrev)
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
254 if self.startrev < 0:
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
255 self.startrev = 0
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
256 except ValueError:
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
257 raise util.Abort(_('svn: start revision %s is not an integer')
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
258 % self.startrev)
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
259
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
260 try:
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
261 self.get_blacklist()
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
262 except IOError:
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
263 pass
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
264
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
265 self.head = self.latest(self.module, latest)
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
266 if not self.head:
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
267 raise util.Abort(_('no revision found in module %s') %
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
268 self.module.encode(self.encoding))
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
269 self.last_changed = self.revnum(self.head)
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
270
5382
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
271 self._changescache = None
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
272
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
273 if os.path.exists(os.path.join(url, '.svn/entries')):
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
274 self.wc = url
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
275 else:
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
276 self.wc = None
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
277 self.convertfp = None
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
278
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5462
diff changeset
279 def setrevmap(self, revmap):
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
280 lastrevs = {}
5511
03bb1296a1c3 convert: iterate
Bryan O'Sullivan <bos@serpentine.com>
parents: 5510
diff changeset
281 for revid in revmap.iterkeys():
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
282 uuid, module, revnum = self.revsplit(revid)
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
283 lastrevnum = lastrevs.setdefault(module, revnum)
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
284 if revnum > lastrevnum:
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
285 lastrevs[module] = revnum
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
286 self.lastrevs = lastrevs
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
287
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
288 def exists(self, path, optrev):
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
289 try:
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
290 svn.client.ls(self.url.rstrip('/') + '/' + urllib.quote(path),
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
291 optrev, False, self.ctx)
5461
ab4d2e9f3b97 convert: svn -- fix 'exists'
Kirill Smelkov <kirr@landau.phys.spbu.ru>
parents: 5438
diff changeset
292 return True
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
293 except SubversionException:
5461
ab4d2e9f3b97 convert: svn -- fix 'exists'
Kirill Smelkov <kirr@landau.phys.spbu.ru>
parents: 5438
diff changeset
294 return False
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
295
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
296 def getheads(self):
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
297
6491
2bdd43246c95 convert: check svn branches are directories
Patrick Mezard <pmezard@gmail.com>
parents: 6400
diff changeset
298 def isdir(path, revnum):
6848
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
299 kind = self._checkpath(path, revnum)
6491
2bdd43246c95 convert: check svn branches are directories
Patrick Mezard <pmezard@gmail.com>
parents: 6400
diff changeset
300 return kind == svn.core.svn_node_dir
2bdd43246c95 convert: check svn branches are directories
Patrick Mezard <pmezard@gmail.com>
parents: 6400
diff changeset
301
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
302 def getcfgpath(name, rev):
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
303 cfgpath = self.ui.config('convert', 'svn.' + name)
6172
0cd6846e5200 convert: allow svn trunk/branches/tags detection to be skipped
Patrick Mezard <pmezard@gmail.com>
parents: 6053
diff changeset
304 if cfgpath is not None and cfgpath.strip() == '':
0cd6846e5200 convert: allow svn trunk/branches/tags detection to be skipped
Patrick Mezard <pmezard@gmail.com>
parents: 6053
diff changeset
305 return None
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
306 path = (cfgpath or name).strip('/')
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
307 if not self.exists(path, rev):
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
308 if cfgpath:
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
309 raise util.Abort(_('expected %s to be at %r, but not found')
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
310 % (name, path))
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
311 return None
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
312 self.ui.note(_('found %s at %r\n') % (name, path))
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
313 return path
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
314
5117
c89ed1f27e78 convert: svn: add helper function for optrevs
Brendan Cully <brendan@kublai.com>
parents: 5114
diff changeset
315 rev = optrev(self.last_changed)
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
316 oldmodule = ''
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
317 trunk = getcfgpath('trunk', rev)
6400
c237b27e1350 convert: allow tags detection to be disabled
Patrick Mezard <pmezard@gmail.com>
parents: 6399
diff changeset
318 self.tags = getcfgpath('tags', rev)
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
319 branches = getcfgpath('branches', rev)
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
320
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
321 # If the project has a trunk or branches, we will extract heads
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
322 # from them. We keep the project root otherwise.
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
323 if trunk:
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
324 oldmodule = self.module or ''
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
325 self.module += '/' + trunk
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
326 self.head = self.latest(self.module, self.last_changed)
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
327 if not self.head:
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
328 raise util.Abort(_('no revision found in module %s') %
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
329 self.module.encode(self.encoding))
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
330
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
331 # First head in the list is the module's head
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
332 self.heads = [self.head]
6400
c237b27e1350 convert: allow tags detection to be disabled
Patrick Mezard <pmezard@gmail.com>
parents: 6399
diff changeset
333 if self.tags is not None:
c237b27e1350 convert: allow tags detection to be disabled
Patrick Mezard <pmezard@gmail.com>
parents: 6399
diff changeset
334 self.tags = '%s/%s' % (oldmodule , (self.tags or 'tags'))
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
335
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
336 # Check if branches bring a few more heads to the list
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
337 if branches:
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
338 rpath = self.url.strip('/')
7184
380fda3eed13 clean up trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7074
diff changeset
339 branchnames = svn.client.ls(rpath + '/' + urllib.quote(branches),
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
340 rev, False, self.ctx)
4925
2642726b61b6 convert/subversion.py: fix bad assumptions about SVN path naming
Bryan O'Sullivan <bos@serpentine.com>
parents: 4873
diff changeset
341 for branch in branchnames.keys():
5854
8b95f598097c convert: separate trunk detection from branch layout detection
Edouard Gomez <ed.gomez@free.fr>
parents: 5842
diff changeset
342 module = '%s/%s/%s' % (oldmodule, branches, branch)
6491
2bdd43246c95 convert: check svn branches are directories
Patrick Mezard <pmezard@gmail.com>
parents: 6400
diff changeset
343 if not isdir(module, self.last_changed):
2bdd43246c95 convert: check svn branches are directories
Patrick Mezard <pmezard@gmail.com>
parents: 6400
diff changeset
344 continue
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
345 brevid = self.latest(module, self.last_changed)
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
346 if not brevid:
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
347 self.ui.note(_('ignoring empty branch %s\n') %
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
348 branch.encode(self.encoding))
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
349 continue
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
350 self.ui.note(_('found branch %s at %d\n') %
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
351 (branch, self.revnum(brevid)))
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
352 self.heads.append(brevid)
5462
91a522a69c13 convert: svn -- fix tags handling
Kirill Smelkov <kirr@landau.phys.spbu.ru>
parents: 5461
diff changeset
353
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
354 if self.startrev and self.heads:
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
355 if len(self.heads) > 1:
8086
89b6450148d0 convert: fix typo
Wagner Bruna <wbruna@yahoo.com>
parents: 7973
diff changeset
356 raise util.Abort(_('svn: start revision is not supported '
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
357 'with more than one branch'))
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
358 revnum = self.revnum(self.heads[0])
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
359 if revnum < self.startrev:
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
360 raise util.Abort(_('svn: no revision found after start revision %d')
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
361 % self.startrev)
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
362
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
363 return self.heads
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
364
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
365 def getfile(self, file, rev):
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
366 data, mode = self._getfile(file, rev)
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
367 self.modecache[(file, rev)] = mode
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
368 return data
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
369
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4949
diff changeset
370 def getmode(self, file, rev):
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
371 return self.modecache[(file, rev)]
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
372
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
373 def getchanges(self, rev):
5382
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
374 if self._changescache and self._changescache[0] == rev:
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
375 return self._changescache[1]
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
376 self._changescache = None
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
377 self.modecache = {}
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
378 (paths, parents) = self.paths[rev]
5956
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
379 if parents:
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
380 files, copies = self.expandpaths(rev, paths, parents)
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
381 else:
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
382 # Perform a full checkout on roots
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
383 uuid, module, revnum = self.revsplit(rev)
7184
380fda3eed13 clean up trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7074
diff changeset
384 entries = svn.client.ls(self.baseurl + urllib.quote(module),
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
385 optrev(revnum), True, self.ctx)
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
386 files = [n for n,e in entries.iteritems()
5956
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
387 if e.kind == svn.core.svn_node_file]
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
388 copies = {}
094638b3cbed convert: checkout svn root revisions
Patrick Mezard <pmezard@gmail.com>
parents: 5955
diff changeset
389
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
390 files.sort()
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
391 files = zip(files, [rev] * len(files))
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
392
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
393 # caller caches the result, so free it here to release memory
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
394 del self.paths[rev]
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
395 return (files, copies)
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
396
5382
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
397 def getchangedfiles(self, rev, i):
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
398 changes = self.getchanges(rev)
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
399 self._changescache = (rev, changes)
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
400 return [f[0] for f in changes[0]]
d7d395fb7cd5 convert_svn: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5373
diff changeset
401
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
402 def getcommit(self, rev):
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
403 if rev not in self.commits:
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
404 uuid, module, revnum = self.revsplit(rev)
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
405 self.module = module
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
406 self.reparent(module)
5875
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
407 # We assume that:
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
408 # - requests for revisions after "stop" come from the
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
409 # revision graph backward traversal. Cache all of them
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
410 # down to stop, they will be used eventually.
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
411 # - requests for revisions before "stop" come to get
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
412 # isolated branches parents. Just fetch what is needed.
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
413 stop = self.lastrevs.get(module, 0)
5875
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
414 if revnum < stop:
f1504d3355bb convert: fetch less revisions when looking for a branch parent
Patrick Mezard <pmezard@gmail.com>
parents: 5873
diff changeset
415 stop = revnum + 1
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
416 self._fetch_revisions(revnum, stop)
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
417 commit = self.commits[rev]
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
418 # caller caches the result, so free it here to release memory
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
419 del self.commits[rev]
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
420 return commit
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
421
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
422 def gettags(self):
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
423 tags = {}
6172
0cd6846e5200 convert: allow svn trunk/branches/tags detection to be skipped
Patrick Mezard <pmezard@gmail.com>
parents: 6053
diff changeset
424 if self.tags is None:
0cd6846e5200 convert: allow svn trunk/branches/tags detection to be skipped
Patrick Mezard <pmezard@gmail.com>
parents: 6053
diff changeset
425 return tags
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
426
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
427 # svn tags are just a convention, project branches left in a
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
428 # 'tags' directory. There is no other relationship than
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
429 # ancestry, which is expensive to discover and makes them hard
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
430 # to update incrementally. Worse, past revisions may be
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
431 # referenced by tags far away in the future, requiring a deep
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
432 # history traversal on every calculation. Current code
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
433 # performs a single backward traversal, tracking moves within
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
434 # the tags directory (tag renaming) and recording a new tag
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
435 # everytime a project is copied from outside the tags
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
436 # directory. It also lists deleted tags, this behaviour may
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
437 # change in the future.
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
438 pendings = []
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
439 tagspath = self.tags
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
440 start = svn.ra.get_latest_revnum(self.ra)
4949
2f0f9528e77b convert/subversion: rehandle the no-tags case
Bryan O'Sullivan <bos@serpentine.com>
parents: 4946
diff changeset
441 try:
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
442 for entry in self._getlog([self.tags], start, self.startrev):
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
443 origpaths, revnum, author, date, message = entry
6493
c19c26718d22 Fix spacing error introduced in 5efd447a9b8d
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6491
diff changeset
444 copies = [(e.copyfrom_path, e.copyfrom_rev, p) for p, e
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
445 in origpaths.iteritems() if e.copyfrom_path]
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
446 # Apply moves/copies from more specific to general
8210
344751cd8cb8 replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents: 8209
diff changeset
447 copies.sort(reverse=True)
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
448
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
449 srctagspath = tagspath
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
450 if copies and copies[-1][2] == tagspath:
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
451 # Track tags directory moves
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
452 srctagspath = copies.pop()[0]
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
453
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
454 for source, sourcerev, dest in copies:
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
455 if not dest.startswith(tagspath + '/'):
4949
2f0f9528e77b convert/subversion: rehandle the no-tags case
Bryan O'Sullivan <bos@serpentine.com>
parents: 4946
diff changeset
456 continue
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
457 for tag in pendings:
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
458 if tag[0].startswith(dest):
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
459 tagpath = source + tag[0][len(dest):]
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
460 tag[:2] = [tagpath, sourcerev]
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
461 break
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
462 else:
8248
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
463 pendings.append([source, sourcerev, dest])
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
464
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
465 # Filter out tags with children coming from different
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
466 # parts of the repository like:
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
467 # /tags/tag.1 (from /trunk:10)
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
468 # /tags/tag.1/foo (from /branches/foo:12)
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
469 # Here/tags/tag.1 discarded as well as its children.
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
470 # It happens with tools like cvs2svn. Such tags cannot
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
471 # be represented in mercurial.
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
472 addeds = dict((p, e.copyfrom_path) for p,e
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
473 in origpaths.iteritems() if e.action == 'A')
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
474 badroots = set()
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
475 for destroot in addeds:
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
476 for source, sourcerev, dest in pendings:
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
477 if (not dest.startswith(destroot + '/')
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
478 or source.startswith(addeds[destroot] + '/')):
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
479 continue
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
480 badroots.add(destroot)
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
481 break
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
482
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
483 for badroot in badroots:
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
484 pendings = [p for p in pendings if p[2] != badroot
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
485 and not p[2].startswith(badroot + '/')]
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
486
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
487 # Tell tag renamings from tag creations
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
488 remainings = []
8248
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
489 for source, sourcerev, dest in pendings:
d093e57671ea convert/svn: ignore composite tags
Patrick Mezard <pmezard@gmail.com>
parents: 8247
diff changeset
490 tagname = dest.split('/')[-1]
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
491 if source.startswith(srctagspath):
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
492 remainings.append([source, sourcerev, tagname])
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
493 continue
8246
965b11c1bd82 convert/svn: keep latest and not oldest tag value
Patrick Mezard <pmezard@gmail.com>
parents: 7857
diff changeset
494 if tagname in tags:
965b11c1bd82 convert/svn: keep latest and not oldest tag value
Patrick Mezard <pmezard@gmail.com>
parents: 7857
diff changeset
495 # Keep the latest tag value
965b11c1bd82 convert/svn: keep latest and not oldest tag value
Patrick Mezard <pmezard@gmail.com>
parents: 7857
diff changeset
496 continue
965b11c1bd82 convert/svn: keep latest and not oldest tag value
Patrick Mezard <pmezard@gmail.com>
parents: 7857
diff changeset
497 # From revision may be fake, get one with changes
7381
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
498 try:
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
499 tagid = self.latest(source, sourcerev)
8246
965b11c1bd82 convert/svn: keep latest and not oldest tag value
Patrick Mezard <pmezard@gmail.com>
parents: 7857
diff changeset
500 if tagid and tagname not in tags:
7381
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
501 tags[tagname] = tagid
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
502 except SvnPathNotFound:
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
503 # It happens when we are following directories we assumed
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
504 # were copied with their parents but were really created
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
505 # in the tag directory.
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
506 pass
6399
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
507 pendings = remainings
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
508 tagspath = srctagspath
5efd447a9b8d convert: follow svn tags history (issue953)
Patrick Mezard <pmezard@gmail.com>
parents: 6397
diff changeset
509
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
510 except SubversionException:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
511 self.ui.note(_('no tags found at revision %d\n') % start)
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
512 return tags
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
513
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
514 def converted(self, rev, destrev):
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
515 if not self.wc:
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
516 return
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
517 if self.convertfp is None:
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
518 self.convertfp = open(os.path.join(self.wc, '.svn', 'hg-shamap'),
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
519 'a')
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
520 self.convertfp.write('%s %d\n' % (destrev, self.revnum(rev)))
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
521 self.convertfp.flush()
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
522
4840
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
523 # -- helper functions --
a265fe42abe7 convert: svn code movement (no actual changes)
Brendan Cully <brendan@kublai.com>
parents: 4839
diff changeset
524
4810
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
525 def revid(self, revnum, module=None):
4795
ea618c5934f3 convert: svn: get parent for branch creation events
Brendan Cully <brendan@kublai.com>
parents: 4794
diff changeset
526 if not module:
ea618c5934f3 convert: svn: get parent for branch creation events
Brendan Cully <brendan@kublai.com>
parents: 4794
diff changeset
527 module = self.module
5287
c6f932d3e0f6 Don't decode unicode strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5276
diff changeset
528 return u"svn:%s%s@%s" % (self.uuid, module.decode(self.encoding),
c6f932d3e0f6 Don't decode unicode strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5276
diff changeset
529 revnum)
4774
d305852a5ec8 convert: svn: add revnum() to convert rev to revnum
Brendan Cully <brendan@kublai.com>
parents: 4773
diff changeset
530
d305852a5ec8 convert: svn: add revnum() to convert rev to revnum
Brendan Cully <brendan@kublai.com>
parents: 4773
diff changeset
531 def revnum(self, rev):
d305852a5ec8 convert: svn: add revnum() to convert rev to revnum
Brendan Cully <brendan@kublai.com>
parents: 4773
diff changeset
532 return int(rev.split('@')[-1])
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
533
4794
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
534 def revsplit(self, rev):
8155
b7cdfa2527be strutil: removed rsplit
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
535 url, revnum = rev.encode(self.encoding).rsplit('@', 1)
4794
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
536 revnum = int(revnum)
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
537 parts = url.split('/', 1)
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
538 uuid = parts.pop(0)[4:]
4797
09dae950919f convert: svn: autodetect /branches, /tags, /trunk.
Brendan Cully <brendan@kublai.com>
parents: 4796
diff changeset
539 mod = ''
4794
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
540 if parts:
4797
09dae950919f convert: svn: autodetect /branches, /tags, /trunk.
Brendan Cully <brendan@kublai.com>
parents: 4796
diff changeset
541 mod = '/' + parts[0]
4794
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
542 return uuid, mod, revnum
1f10a6cccdb5 convert: add optional module argument to svn._fetch_revisions
Brendan Cully <brendan@kublai.com>
parents: 4793
diff changeset
543
4790
c2ef09a35c53 convert: typo in svn.latest
Brendan Cully <brendan@kublai.com>
parents: 4789
diff changeset
544 def latest(self, path, stop=0):
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
545 """Find the latest revid affecting path, up to stop. It may return
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
546 a revision in a different module, since a branch may be moved without
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
547 a change being reported. Return None if computed module does not
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
548 belong to rootmodule subtree.
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
549 """
6281
3e5f99b13998 convert: avoid querying log of foreign svn branches
Patrick Mezard <pmezard@gmail.com>
parents: 6214
diff changeset
550 if not path.startswith(self.rootmodule):
3e5f99b13998 convert: avoid querying log of foreign svn branches
Patrick Mezard <pmezard@gmail.com>
parents: 6214
diff changeset
551 # Requests on foreign branches may be forbidden at server level
3e5f99b13998 convert: avoid querying log of foreign svn branches
Patrick Mezard <pmezard@gmail.com>
parents: 6214
diff changeset
552 self.ui.debug(_('ignoring foreign branch %r\n') % path)
3e5f99b13998 convert: avoid querying log of foreign svn branches
Patrick Mezard <pmezard@gmail.com>
parents: 6214
diff changeset
553 return None
3e5f99b13998 convert: avoid querying log of foreign svn branches
Patrick Mezard <pmezard@gmail.com>
parents: 6214
diff changeset
554
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
555 if not stop:
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
556 stop = svn.ra.get_latest_revnum(self.ra)
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
557 try:
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
558 prevmodule = self.reparent('')
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
559 dirent = svn.ra.stat(self.ra, path.strip('/'), stop)
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
560 self.reparent(prevmodule)
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
561 except SubversionException:
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
562 dirent = None
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
563 if not dirent:
7381
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
564 raise SvnPathNotFound(_('%s not found up to revision %d') % (path, stop))
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
565
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
566 # stat() gives us the previous revision on this line of development, but
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
567 # it might be in *another module*. Fetch the log and detect renames down
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
568 # to the latest revision.
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
569 stream = self._getlog([path], stop, dirent.created_rev)
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
570 try:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
571 for entry in stream:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
572 paths, revnum, author, date, message = entry
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
573 if revnum <= dirent.created_rev:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
574 break
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
575
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
576 for p in paths:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
577 if not path.startswith(p) or not paths[p].copyfrom_path:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
578 continue
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
579 newpath = paths[p].copyfrom_path + path[len(p):]
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
580 self.ui.debug(_("branch renamed from %s to %s at %d\n") %
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
581 (path, newpath, revnum))
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
582 path = newpath
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
583 break
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
584 finally:
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
585 stream.close()
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
586
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
587 if not path.startswith(self.rootmodule):
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
588 self.ui.debug(_('ignoring foreign branch %r\n') % path)
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
589 return None
5955
c4496b7c10ce convert: fix svn_source.latest()
Patrick Mezard <pmezard@gmail.com>
parents: 5921
diff changeset
590 return self.revid(dirent.created_rev, path)
4789
c5dd8e184279 convert: svn: add function to get the latest revision touching a path
Brendan Cully <brendan@kublai.com>
parents: 4788
diff changeset
591
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
592 def get_blacklist(self):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
593 """Avoid certain revision numbers.
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
594 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
595 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
596 of making a branch'. The converted repository is significantly
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
597 smaller if we ignore such revisions."""
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8129
diff changeset
598 self.blacklist = set()
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
599 blacklist = self.blacklist
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
600 for line in file("blacklist.txt", "r"):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
601 if not line.startswith("#"):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
602 try:
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
603 svn_rev = int(line.strip())
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
604 blacklist.add(svn_rev)
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
605 except ValueError:
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
606 pass # not an integer or a comment
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
607
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
608 def is_blacklisted(self, svn_rev):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
609 return svn_rev in self.blacklist
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
610
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
611 def reparent(self, module):
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
612 """Reparent the svn transport and return the previous parent."""
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
613 if self.prevmodule == module:
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
614 return module
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
615 svnurl = self.baseurl + urllib.quote(module)
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
616 prevmodule = self.prevmodule
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
617 if prevmodule is None:
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
618 prevmodule = ''
7075
6db6f6db026a Merge with crew-stable
Patrick Mezard <pmezard@gmail.com>
parents: 6956 7074
diff changeset
619 self.ui.debug(_("reparent to %s\n") % svnurl)
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
620 svn.ra.reparent(self.ra, svnurl)
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
621 self.prevmodule = module
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
622 return prevmodule
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
623
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
624 def expandpaths(self, rev, paths, parents):
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
625 entries = []
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
626 copyfrom = {} # Map of entrypath, revision for finding source of deleted revisions.
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
627 copies = {}
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
628
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
629 new_module, revnum = self.revsplit(rev)[1:]
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
630 if new_module != self.module:
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
631 self.module = new_module
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
632 self.reparent(self.module)
5121
ef338e34a906 convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents: 5120
diff changeset
633
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
634 for path, ent in paths:
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
635 entrypath = self.getrelpath(path)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
636 entry = entrypath.decode(self.encoding)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
637
6848
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
638 kind = self._checkpath(entrypath, revnum)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
639 if kind == svn.core.svn_node_file:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
640 entries.append(self.recode(entry))
6546
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
641 if not ent.copyfrom_path or not parents:
6544
3447c088a516 convert: cleanup svn file copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6543
diff changeset
642 continue
6546
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
643 # Copy sources not in parent revisions cannot be represented,
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
644 # ignore their origin for now
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
645 pmodule, prevnum = self.revsplit(parents[0])[1:]
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
646 if ent.copyfrom_rev < prevnum:
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
647 continue
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
648 copyfrom_path = self.getrelpath(ent.copyfrom_path, pmodule)
6544
3447c088a516 convert: cleanup svn file copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6543
diff changeset
649 if not copyfrom_path:
3447c088a516 convert: cleanup svn file copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6543
diff changeset
650 continue
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
651 self.ui.debug(_("copied to %s from %s@%s\n") %
6544
3447c088a516 convert: cleanup svn file copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6543
diff changeset
652 (entrypath, copyfrom_path, ent.copyfrom_rev))
6546
075b2c9aed37 convert: fix svn file copy detection code
Patrick Mezard <pmezard@gmail.com>
parents: 6545
diff changeset
653 copies[self.recode(entry)] = self.recode(copyfrom_path)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
654 elif kind == 0: # gone, but had better be a deleted *file*
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
655 self.ui.debug(_("gone from %s\n") % ent.copyfrom_rev)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
656
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
657 # if a branch is created but entries are removed in the same
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
658 # changeset, get the right fromrev
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
659 # parents cannot be empty here, you cannot remove things from
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
660 # a root revision.
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
661 uuid, old_module, fromrev = self.revsplit(parents[0])
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
662
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
663 basepath = old_module + "/" + self.getrelpath(path)
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
664 entrypath = basepath
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
665
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
666 def lookup_parts(p):
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
667 rc = None
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
668 parts = p.split("/")
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
669 for i in range(len(parts)):
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
670 part = "/".join(parts[:i])
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
671 info = part, copyfrom.get(part, None)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
672 if info[1] is not None:
7599
7bf7c073375e lowercase ui.debug and assert output
Martin Geisler <mg@daimi.au.dk>
parents: 7476
diff changeset
673 self.ui.debug(_("found parent directory %s\n") % info[1])
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
674 rc = info
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
675 return rc
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
676
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
677 self.ui.debug(_("base, entry %s %s\n") % (basepath, entrypath))
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
678
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
679 frompath, froment = lookup_parts(entrypath) or (None, revnum - 1)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
680
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
681 # need to remove fragment from lookup_parts and replace with copyfrom_path
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
682 if frompath is not None:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
683 self.ui.debug(_("munge-o-matic\n"))
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
684 self.ui.debug(entrypath + '\n')
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
685 self.ui.debug(entrypath[len(frompath):] + '\n')
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
686 entrypath = froment.copyfrom_path + entrypath[len(frompath):]
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
687 fromrev = froment.copyfrom_rev
7599
7bf7c073375e lowercase ui.debug and assert output
Martin Geisler <mg@daimi.au.dk>
parents: 7476
diff changeset
688 self.ui.debug(_("info: %s %s %s %s\n") % (frompath, froment, ent, entrypath))
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
689
5880
b32a0596b2d7 convert: fix invalid svn.ra.check_path() call (issue 771)
Patrick Mezard <pmezard@gmail.com>
parents: 5617
diff changeset
690 # We can avoid the reparent calls if the module has not changed
b32a0596b2d7 convert: fix invalid svn.ra.check_path() call (issue 771)
Patrick Mezard <pmezard@gmail.com>
parents: 5617
diff changeset
691 # but it probably does not worth the pain.
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
692 prevmodule = self.reparent('')
5880
b32a0596b2d7 convert: fix invalid svn.ra.check_path() call (issue 771)
Patrick Mezard <pmezard@gmail.com>
parents: 5617
diff changeset
693 fromkind = svn.ra.check_path(self.ra, entrypath.strip('/'), fromrev)
6847
9d6d1fdb7d72 convert: restore previous svn transport parent correctly
Patrick Mezard <pmezard@gmail.com>
parents: 6553
diff changeset
694 self.reparent(prevmodule)
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
695
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
696 if fromkind == svn.core.svn_node_file: # a deleted file
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
697 entries.append(self.recode(entry))
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
698 elif fromkind == svn.core.svn_node_dir:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
699 # print "Deleted/moved non-file:", revnum, path, ent
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
700 # children = self._find_children(path, revnum - 1)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
701 # print "find children %s@%d from %d action %s" % (path, revnum, ent.copyfrom_rev, ent.action)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
702 # Sometimes this is tricky. For example: in
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
703 # The Subversion Repository revision 6940 a dir
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
704 # was copied and one of its files was deleted
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
705 # from the new location in the same commit. This
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
706 # code can't deal with that yet.
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
707 if ent.action == 'C':
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
708 children = self._find_children(path, fromrev)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
709 else:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
710 oroot = entrypath.strip('/')
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
711 nroot = path.strip('/')
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
712 children = self._find_children(oroot, fromrev)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
713 children = [s.replace(oroot,nroot) for s in children]
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
714 # Mark all [files, not directories] as deleted.
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
715 for child in children:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
716 # Can we move a child directory and its
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
717 # parent in the same commit? (probably can). Could
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
718 # cause problems if instead of revnum -1,
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
719 # we have to look in (copyfrom_path, revnum - 1)
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
720 entrypath = self.getrelpath("/" + child, module=old_module)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
721 if entrypath:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
722 entry = self.recode(entrypath.decode(self.encoding))
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
723 if entry in copies:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
724 # deleted file within a copy
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
725 del copies[entry]
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
726 else:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
727 entries.append(entry)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
728 else:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
729 self.ui.debug(_('unknown path in revision %d: %s\n') % \
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
730 (revnum, path))
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
731 elif kind == svn.core.svn_node_dir:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
732 # Should probably synthesize normal file entries
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
733 # and handle as above to clean up copy/rename handling.
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
734
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
735 # If the directory just had a prop change,
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
736 # then we shouldn't need to look for its children.
5870
0d583ade5817 convert: don't scan directories on property changes
Patrick Mezard <pmezard@gmail.com>
parents: 5854
diff changeset
737 if ent.action == 'M':
0d583ade5817 convert: don't scan directories on property changes
Patrick Mezard <pmezard@gmail.com>
parents: 5854
diff changeset
738 continue
0d583ade5817 convert: don't scan directories on property changes
Patrick Mezard <pmezard@gmail.com>
parents: 5854
diff changeset
739
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
740 # Also this could create duplicate entries. Not sure
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
741 # whether this will matter. Maybe should make entries a set.
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
742 # print "Changed directory", revnum, path, ent.action, ent.copyfrom_path, ent.copyfrom_rev
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
743 # This will fail if a directory was copied
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
744 # from another branch and then some of its files
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
745 # were deleted in the same transaction.
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
746 children = sorted(self._find_children(path, revnum))
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
747 for child in children:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
748 # Can we move a child directory and its
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
749 # parent in the same commit? (probably can). Could
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
750 # cause problems if instead of revnum -1,
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
751 # we have to look in (copyfrom_path, revnum - 1)
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
752 entrypath = self.getrelpath("/" + child)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
753 # print child, self.module, entrypath
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
754 if entrypath:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
755 # Need to filter out directories here...
6848
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
756 kind = self._checkpath(entrypath, revnum)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
757 if kind != svn.core.svn_node_dir:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
758 entries.append(self.recode(entrypath))
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
759
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
760 # Copies here (must copy all from source)
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
761 # Probably not a real problem for us if
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
762 # source does not exist
6543
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
763 if not ent.copyfrom_path or not parents:
6542
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
764 continue
6543
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
765 # Copy sources not in parent revisions cannot be represented,
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
766 # ignore their origin for now
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
767 pmodule, prevnum = self.revsplit(parents[0])[1:]
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
768 if ent.copyfrom_rev < prevnum:
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
769 continue
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
770 copyfrompath = ent.copyfrom_path.decode(self.encoding)
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
771 copyfrompath = self.getrelpath(copyfrompath, pmodule)
6542
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
772 if not copyfrompath:
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
773 continue
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
774 copyfrom[path] = ent
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
775 self.ui.debug(_("mark %s came from %s:%d\n")
6542
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
776 % (path, copyfrompath, ent.copyfrom_rev))
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
777 children = self._find_children(ent.copyfrom_path, ent.copyfrom_rev)
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
778 children.sort()
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
779 for child in children:
6543
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
780 entrypath = self.getrelpath("/" + child, pmodule)
6542
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
781 if not entrypath:
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
782 continue
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
783 entry = entrypath.decode(self.encoding)
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
784 copytopath = path + entry[len(copyfrompath):]
e7810e61f7c1 convert: more cleanup in svn directory copy handling
Patrick Mezard <pmezard@gmail.com>
parents: 6541
diff changeset
785 copytopath = self.getrelpath(copytopath)
6543
a6e2e60b34d0 convert: handle past or foreign partial svn copies
Patrick Mezard <pmezard@gmail.com>
parents: 6542
diff changeset
786 copies[self.recode(copytopath)] = self.recode(entry, pmodule)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
787
8151
127281884959 util: use built-in set instead of util.unique
Martin Geisler <mg@lazybytes.net>
parents: 8150
diff changeset
788 return (list(set(entries)), copies)
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
789
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
790 def _fetch_revisions(self, from_revnum, to_revnum):
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
791 if from_revnum < to_revnum:
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
792 from_revnum, to_revnum = to_revnum, from_revnum
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
793
4940
961379b2c586 convert/subversion: reduce memory usage by filtering early
Bryan O'Sullivan <bos@serpentine.com>
parents: 4927
diff changeset
794 self.child_cset = None
6545
a7492fb2107b convert: fix svn branch source detection corner case
Patrick Mezard <pmezard@gmail.com>
parents: 6544
diff changeset
795
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
796 def parselogentry(orig_paths, revnum, author, date, message):
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
797 """Return the parsed commit object or None, and True if
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
798 the revision is a branch root.
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
799 """
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
800 self.ui.debug(_("parsing revision %d (%d changes)\n") %
4946
e8f4e40f285a convert/subversion: work around memory leak in svn's python bindings
Bryan O'Sullivan <bos@serpentine.com>
parents: 4944
diff changeset
801 (revnum, len(orig_paths)))
4940
961379b2c586 convert/subversion: reduce memory usage by filtering early
Bryan O'Sullivan <bos@serpentine.com>
parents: 4927
diff changeset
802
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
803 branched = False
4810
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
804 rev = self.revid(revnum)
4837
4cdbaa885d8a convert: svn: some improvements in memory usage
Brendan Cully <brendan@kublai.com>
parents: 4814
diff changeset
805 # branch log might return entries for a parent we already have
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
806
8117
2b30d8488819 remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents: 8086
diff changeset
807 if rev in self.commits or revnum < to_revnum:
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
808 return None, branched
4837
4cdbaa885d8a convert: svn: some improvements in memory usage
Brendan Cully <brendan@kublai.com>
parents: 4814
diff changeset
809
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
810 parents = []
5958
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
811 # check whether this revision is the start of a branch or part
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
812 # of a branch renaming
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
813 orig_paths = sorted(orig_paths.iteritems())
5958
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
814 root_paths = [(p,e) for p,e in orig_paths if self.module.startswith(p)]
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
815 if root_paths:
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
816 path, ent = root_paths[-1]
5119
4cef0b93969d convert: svn: hoist up branch creation check
Brendan Cully <brendan@kublai.com>
parents: 5118
diff changeset
817 if ent.copyfrom_path:
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
818 branched = True
5958
59dce24933ad convert: follow svn module parent moves
Patrick Mezard <pmezard@gmail.com>
parents: 5957
diff changeset
819 newpath = ent.copyfrom_path + self.module[len(path):]
5119
4cef0b93969d convert: svn: hoist up branch creation check
Brendan Cully <brendan@kublai.com>
parents: 5118
diff changeset
820 # ent.copyfrom_rev may not be the actual last revision
7476
6644c111f9e9 convert: backout a7492fb2107b
Patrick Mezard <pmezard@gmail.com>
parents: 7447
diff changeset
821 previd = self.latest(newpath, ent.copyfrom_rev)
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
822 if previd is not None:
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
823 prevmodule, prevnum = self.revsplit(previd)[1:]
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
824 if prevnum >= self.startrev:
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
825 parents = [previd]
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
826 self.ui.note(_('found parent of branch %s at %d: %s\n') %
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
827 (self.module, prevnum, prevmodule))
5119
4cef0b93969d convert: svn: hoist up branch creation check
Brendan Cully <brendan@kublai.com>
parents: 5118
diff changeset
828 else:
7599
7bf7c073375e lowercase ui.debug and assert output
Martin Geisler <mg@daimi.au.dk>
parents: 7476
diff changeset
829 self.ui.debug(_("no copyfrom path, don't know what to do.\n"))
5119
4cef0b93969d convert: svn: hoist up branch creation check
Brendan Cully <brendan@kublai.com>
parents: 5118
diff changeset
830
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
831 paths = []
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
832 # filter out unrelated paths
4940
961379b2c586 convert/subversion: reduce memory usage by filtering early
Bryan O'Sullivan <bos@serpentine.com>
parents: 4927
diff changeset
833 for path, ent in orig_paths:
6540
55bd855fc0af convert: improve subversion branch filtering
Patrick Mezard <pmezard@gmail.com>
parents: 6539
diff changeset
834 if self.getrelpath(path) is None:
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
835 continue
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
836 paths.append((path, ent))
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
837
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
838 # Example SVN datetime. Includes microseconds.
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
839 # ISO-8601 conformant
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
840 # '2007-01-04T17:35:00.902377Z'
5617
924fd86f0579 convert: fix SVN date parser dropping the final whole second digit
David J. Mellor <dmellor@whistlingcat.com>
parents: 5521
diff changeset
841 date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
842
5916
b6deda0f69fa convert: Do not abort with TypeError if svn commit message is None (issue934)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5883
diff changeset
843 log = message and self.recode(message) or ''
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
844 author = author and self.recode(author) or ''
5120
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
845 try:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
846 branch = self.module.split("/")[-1]
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
847 if branch == 'trunk':
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
848 branch = ''
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
849 except IndexError:
514c06098e9c convert: svn: pull up path to file expansion code into separate function.
Brendan Cully <brendan@kublai.com>
parents: 5119
diff changeset
850 branch = None
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
851
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
852 cset = commit(author=author,
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4949
diff changeset
853 date=util.datestr(date),
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4949
diff changeset
854 desc=log,
4795
ea618c5934f3 convert: svn: get parent for branch creation events
Brendan Cully <brendan@kublai.com>
parents: 4794
diff changeset
855 parents=parents,
4873
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4848
diff changeset
856 branch=branch,
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4848
diff changeset
857 rev=rev.encode('utf-8'))
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
858
4796
26857a6f9dd0 convert: svn: pull out broken batching code, add alpha tags support
Brendan Cully <brendan@kublai.com>
parents: 4795
diff changeset
859 self.commits[rev] = cset
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
860 # The parents list is *shared* among self.paths and the
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
861 # commit object. Both will be updated below.
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
862 self.paths[rev] = (paths, cset.parents)
4796
26857a6f9dd0 convert: svn: pull out broken batching code, add alpha tags support
Brendan Cully <brendan@kublai.com>
parents: 4795
diff changeset
863 if self.child_cset and not self.child_cset.parents:
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
864 self.child_cset.parents[:] = [rev]
4788
62e1b6412b62 convert: svn: add an early return to move most changeset parsing out an indent level
Brendan Cully <brendan@kublai.com>
parents: 4787
diff changeset
865 self.child_cset = cset
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
866 return cset, branched
4796
26857a6f9dd0 convert: svn: pull out broken batching code, add alpha tags support
Brendan Cully <brendan@kublai.com>
parents: 4795
diff changeset
867
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
868 self.ui.note(_('fetching revision log for "%s" from %d to %d\n') %
4797
09dae950919f convert: svn: autodetect /branches, /tags, /trunk.
Brendan Cully <brendan@kublai.com>
parents: 4796
diff changeset
869 (self.module, from_revnum, to_revnum))
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
870
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
871 try:
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
872 firstcset = None
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
873 lastonbranch = False
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
874 stream = self._getlog([self.module], from_revnum, to_revnum)
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
875 try:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
876 for entry in stream:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
877 paths, revnum, author, date, message = entry
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
878 if revnum < self.startrev:
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
879 lastonbranch = True
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
880 break
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
881 if self.is_blacklisted(revnum):
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
882 self.ui.note(_('skipping blacklisted revision %d\n')
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
883 % revnum)
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
884 continue
8172
36b935cad495 Fix subversion convert not detecting empty changesets.
Francis Barber <fedora@barber-family.id.au>
parents: 8155
diff changeset
885 if not paths:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
886 self.ui.debug(_('revision %d has no entries\n') % revnum)
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
887 continue
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6173
diff changeset
888 cset, lastonbranch = parselogentry(paths, revnum, author,
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
889 date, message)
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
890 if cset:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
891 firstcset = cset
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
892 if lastonbranch:
5873
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
893 break
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
894 finally:
ecb4eb0cbff2 convert: make svn revision iterator interruptible
Patrick Mezard <pmezard@gmail.com>
parents: 5872
diff changeset
895 stream.close()
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
896
6173
963000ed8cac convert: add shallow, single branch svn conversions via svn.startrev
Patrick Mezard <pmezard@gmail.com>
parents: 6172
diff changeset
897 if not lastonbranch and firstcset and not firstcset.parents:
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
898 # The first revision of the sequence (the last fetched one)
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
899 # has invalid parents if not a branch root. Find the parent
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
900 # revision now, if any.
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
901 try:
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
902 firstrevnum = self.revnum(firstcset.rev)
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
903 if firstrevnum > 1:
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
904 latest = self.latest(self.module, firstrevnum - 1)
5957
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
905 if latest:
971a17af5982 convert: prevent svn branches to leave the root module tree
Patrick Mezard <pmezard@gmail.com>
parents: 5956
diff changeset
906 firstcset.parents.append(latest)
7381
b965605dfb2e convert: be even more tolerant when detecting svn tags
Patrick Mezard <pmezard@gmail.com>
parents: 7184
diff changeset
907 except SvnPathNotFound:
5871
c1244685425a convert: fix parents of last fetched svn revision
Patrick Mezard <pmezard@gmail.com>
parents: 5870
diff changeset
908 pass
5140
792c1d979097 Replace _ with inst for catching exceptions to not shadow gettext.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5139
diff changeset
909 except SubversionException, (inst, num):
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
910 if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION:
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
911 raise util.Abort(_('svn: branch has no revision %s') % to_revnum)
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
912 raise
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
913
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
914 def _getfile(self, file, rev):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
915 # 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
916 mode = ''
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
917 try:
5872
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
918 new_module, revnum = self.revsplit(rev)[1:]
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
919 if self.module != new_module:
7d4149cccc5d convert: fix cross-branches subversion revisions handling
Patrick Mezard <pmezard@gmail.com>
parents: 5871
diff changeset
920 self.module = new_module
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
921 self.reparent(self.module)
7446
2d2e0be762be convert: work around svn.ra.get_files() not releasing input buffer
Patrick Mezard <pmezard@gmail.com>
parents: 7382
diff changeset
922 io = StringIO()
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
923 info = svn.ra.get_file(self.ra, file, revnum, io)
7446
2d2e0be762be convert: work around svn.ra.get_files() not releasing input buffer
Patrick Mezard <pmezard@gmail.com>
parents: 7382
diff changeset
924 data = io.getvalue()
2d2e0be762be convert: work around svn.ra.get_files() not releasing input buffer
Patrick Mezard <pmezard@gmail.com>
parents: 7382
diff changeset
925 # ra.get_files() seems to keep a reference on the input buffer
2d2e0be762be convert: work around svn.ra.get_files() not releasing input buffer
Patrick Mezard <pmezard@gmail.com>
parents: 7382
diff changeset
926 # preventing collection. Release it explicitely.
2d2e0be762be convert: work around svn.ra.get_files() not releasing input buffer
Patrick Mezard <pmezard@gmail.com>
parents: 7382
diff changeset
927 io.close()
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
928 if isinstance(info, list):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
929 info = info[-1]
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
930 mode = ("svn:executable" in info) and 'x' or ''
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
931 mode = ("svn:special" in info) and 'l' or mode
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
932 except SubversionException, e:
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
933 notfound = (svn.core.SVN_ERR_FS_NOT_FOUND,
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
934 svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND)
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
935 if e.apr_err in notfound: # File not found
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
936 raise IOError()
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
937 raise
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
938 if mode == 'l':
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
939 link_prefix = "link "
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
940 if data.startswith(link_prefix):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
941 data = data[len(link_prefix):]
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
942 return data, mode
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
943
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
944 def _find_children(self, path, revnum):
5114
35f67dd712d0 convert: svn: ensure leading / is removed from paths in _find_children (broken in 2bd996d0aaf8)
Brendan Cully <brendan@kublai.com>
parents: 5050
diff changeset
945 path = path.strip('/')
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
diff changeset
946 pool = Pool()
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
947 rpath = '/'.join([self.baseurl, urllib.quote(path)]).strip('/')
7184
380fda3eed13 clean up trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7074
diff changeset
948 return ['%s/%s' % (path, x) for x in
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
949 svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool).keys()]
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
950
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
951 def getrelpath(self, path, module=None):
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
952 if module is None:
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
953 module = self.module
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
954 # Given the repository url of this wc, say
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
955 # "http://server/plone/CMFPlone/branches/Plone-2_0-branch"
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
956 # extract the "entry" portion (a relative path) from what
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
957 # svn log --xml says, ie
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
958 # "/CMFPlone/branches/Plone-2_0-branch/tests/PloneTestCase.py"
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
959 # that is to say "tests/PloneTestCase.py"
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
960 if path.startswith(module):
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
961 relative = path.rstrip('/')[len(module):]
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
962 if relative.startswith('/'):
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
963 return relative[1:]
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
964 elif relative == '':
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
965 return relative
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
966
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
967 # The path is outside our tracked tree...
6956
12472a240398 i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents: 6884
diff changeset
968 self.ui.debug(_('%r is not under %r, ignoring\n') % (path, module))
6539
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
969 return None
7814d7bb77bc convert: rename get_entry_from_path() into an svn_source method
Patrick Mezard <pmezard@gmail.com>
parents: 6538
diff changeset
970
6848
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
971 def _checkpath(self, path, revnum):
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
972 # ra.check_path does not like leading slashes very much, it leads
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
973 # to PROPFIND subversion errors
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
974 return svn.ra.check_path(self.ra, path.strip('/'), revnum)
59c40c60d8d8 convert: remove leading slash from ra.check_path inputs (issue 1236)
Patrick Mezard <pmezard@gmail.com>
parents: 6847
diff changeset
975
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
976 def _getlog(self, paths, start, end, limit=0, discover_changed_paths=True,
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
977 strict_node_history=False):
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
978 # Normalize path names, svn >= 1.5 only wants paths relative to
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
979 # supplied URL
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
980 relpaths = []
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
981 for p in paths:
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
982 if not p.startswith('/'):
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
983 p = self.module + '/' + p
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
984 relpaths.append(p.strip('/'))
7074
b1a4f67b98d0 convert: properly encode subversion URLs (issue 1224)
Patrick Mezard <pmezard@gmail.com>
parents: 6877
diff changeset
985 args = [self.baseurl, relpaths, start, end, limit, discover_changed_paths,
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
986 strict_node_history]
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
987 arg = encodeargs(args)
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
988 hgexe = util.hgexecutable()
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
989 cmd = '%s debugsvnlog' % util.shellquote(hgexe)
8339
f55869abb5c3 util: remove ignored mode argument in popen[23]
Martin Geisler <mg@lazybytes.net>
parents: 8248
diff changeset
990 stdin, stdout = util.popen2(cmd)
6850
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
991 stdin.write(arg)
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
992 stdin.close()
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
993 return logstream(stdout)
c6bb8fae3bd2 convert: normalize paths sent to svn get_log (issue 1219)
Patrick Mezard <pmezard@gmail.com>
parents: 6848
diff changeset
994
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
995 pre_revprop_change = '''#!/bin/sh
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
996
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
997 REPOS="$1"
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
998 REV="$2"
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
999 USER="$3"
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1000 PROPNAME="$4"
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1001 ACTION="$5"
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1002
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1003 if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1004 if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1005 if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1006
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1007 echo "Changing prohibited revision property" >&2
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1008 exit 1
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1009 '''
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1010
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1011 class svn_sink(converter_sink, commandline):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1012 commit_re = re.compile(r'Committed revision (\d+).', re.M)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1013
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1014 def prerun(self):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1015 if self.wc:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1016 os.chdir(self.wc)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1017
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1018 def postrun(self):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1019 if self.wc:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1020 os.chdir(self.cwd)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1021
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1022 def join(self, name):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1023 return os.path.join(self.wc, '.svn', name)
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5705
diff changeset
1024
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1025 def revmapfile(self):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1026 return self.join('hg-shamap')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1027
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1028 def authorfile(self):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1029 return self.join('hg-authormap')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1030
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1031 def __init__(self, ui, path):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1032 converter_sink.__init__(self, ui, path)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1033 commandline.__init__(self, ui, 'svn')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1034 self.delete = []
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1035 self.setexec = []
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1036 self.delexec = []
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1037 self.copies = []
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1038 self.wc = None
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1039 self.cwd = os.getcwd()
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1040
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1041 path = os.path.realpath(path)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1042
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1043 created = False
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1044 if os.path.isfile(os.path.join(path, '.svn', 'entries')):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1045 self.wc = path
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1046 self.run0('update')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1047 else:
5535
7501ef26402b convert: fix svn file:// URL generation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
1048 wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc')
7501ef26402b convert: fix svn file:// URL generation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
1049
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1050 if os.path.isdir(os.path.dirname(path)):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1051 if not os.path.exists(os.path.join(path, 'db', 'fs-type')):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1052 ui.status(_('initializing svn repo %r\n') %
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1053 os.path.basename(path))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1054 commandline(ui, 'svnadmin').run0('create', path)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1055 created = path
5842
111ed8c871bf Use util.normpath() instead of direct path string operation.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5841
diff changeset
1056 path = util.normpath(path)
5535
7501ef26402b convert: fix svn file:// URL generation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
1057 if not path.startswith('/'):
7501ef26402b convert: fix svn file:// URL generation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5528
diff changeset
1058 path = '/' + path
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1059 path = 'file://' + path
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5705
diff changeset
1060
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1061 ui.status(_('initializing svn wc %r\n') % os.path.basename(wcpath))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1062 self.run0('checkout', path, wcpath)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1063
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1064 self.wc = wcpath
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1065 self.opener = util.opener(self.wc)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1066 self.wopener = util.opener(self.wc)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1067 self.childmap = mapfile(ui, self.join('hg-childmap'))
5536
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1068 self.is_exec = util.checkexec(self.wc) and util.is_exec or None
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1069
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1070 if created:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1071 hook = os.path.join(created, 'hooks', 'pre-revprop-change')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1072 fp = open(hook, 'w')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1073 fp.write(pre_revprop_change)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1074 fp.close()
6877
1d38f3605b20 util: set_flags shouldn't know about repo flag formats
Matt Mackall <mpm@selenic.com>
parents: 6850
diff changeset
1075 util.set_flags(hook, False, True)
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1076
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1077 xport = transport.SvnRaTransport(url=geturl(path))
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1078 self.uuid = svn.ra.get_uuid(xport.ra)
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1079
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1080 def wjoin(self, *names):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1081 return os.path.join(self.wc, *names)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1082
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1083 def putfile(self, filename, flags, data):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1084 if 'l' in flags:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1085 self.wopener.symlink(data, filename)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1086 else:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1087 try:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1088 if os.path.islink(self.wjoin(filename)):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1089 os.unlink(filename)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1090 except OSError:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1091 pass
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1092 self.wopener(filename, 'w').write(data)
5536
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1093
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1094 if self.is_exec:
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1095 was_exec = self.is_exec(self.wjoin(filename))
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1096 else:
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1097 # On filesystems not supporting execute-bit, there is no way
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1098 # to know if it is set but asking subversion. Setting it
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1099 # systematically is just as expensive and much simpler.
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1100 was_exec = 'x' not in flags
fdee5d614fcc convert: force svn:executable when execute-bit is not supported
Patrick Mezard <pmezard@gmail.com>
parents: 5535
diff changeset
1101
6877
1d38f3605b20 util: set_flags shouldn't know about repo flag formats
Matt Mackall <mpm@selenic.com>
parents: 6850
diff changeset
1102 util.set_flags(self.wjoin(filename), False, 'x' in flags)
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1103 if was_exec:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1104 if 'x' not in flags:
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1105 self.delexec.append(filename)
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1106 else:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1107 if 'x' in flags:
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1108 self.setexec.append(filename)
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1109
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1110 def _copyfile(self, source, dest):
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1111 # SVN's copy command pukes if the destination file exists, but
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1112 # our copyfile method expects to record a copy that has
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1113 # already occurred. Cross the semantic gap.
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1114 wdest = self.wjoin(dest)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1115 exists = os.path.exists(wdest)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1116 if exists:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1117 fd, tempname = tempfile.mkstemp(
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1118 prefix='hg-copy-', dir=os.path.dirname(wdest))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1119 os.close(fd)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1120 os.unlink(tempname)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1121 os.rename(wdest, tempname)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1122 try:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1123 self.run0('copy', source, dest)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1124 finally:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1125 if exists:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1126 try:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1127 os.unlink(wdest)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1128 except OSError:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1129 pass
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1130 os.rename(tempname, wdest)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1131
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1132 def dirs_of(self, files):
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8129
diff changeset
1133 dirs = set()
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1134 for f in files:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1135 if os.path.isdir(self.wjoin(f)):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1136 dirs.add(f)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1137 for i in strutil.rfindall(f, '/'):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1138 dirs.add(f[:i])
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1139 return dirs
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1140
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1141 def add_dirs(self, files):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
1142 add_dirs = [d for d in sorted(self.dirs_of(files))
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1143 if not os.path.exists(self.wjoin(d, '.svn', 'entries'))]
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1144 if add_dirs:
5832
2192ed187319 convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents: 5806
diff changeset
1145 self.xargs(add_dirs, 'add', non_recursive=True, quiet=True)
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1146 return add_dirs
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1147
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1148 def add_files(self, files):
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1149 if files:
5832
2192ed187319 convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents: 5806
diff changeset
1150 self.xargs(files, 'add', quiet=True)
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1151 return files
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5705
diff changeset
1152
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1153 def tidy_dirs(self, names):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1154 deleted = []
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
1155 for d in sorted(self.dirs_of(names), reverse=True):
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1156 wd = self.wjoin(d)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1157 if os.listdir(wd) == '.svn':
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1158 self.run0('delete', d)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1159 deleted.append(d)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1160 return deleted
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1161
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1162 def addchild(self, parent, child):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1163 self.childmap[parent] = child
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1164
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1165 def revid(self, rev):
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1166 return u"svn:%s@%s" % (self.uuid, rev)
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1167
6716
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1168 def putcommit(self, files, copies, parents, commit, source):
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1169 # Apply changes to working copy
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1170 for f, v in files:
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1171 try:
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1172 data = source.getfile(f, v)
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
1173 except IOError:
6716
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1174 self.delete.append(f)
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1175 else:
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1176 e = source.getmode(f, v)
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1177 self.putfile(f, e, data)
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1178 if f in copies:
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1179 self.copies.append([copies[f], f])
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1180 files = [f[0] for f in files]
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6557
diff changeset
1181
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1182 for parent in parents:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1183 try:
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1184 return self.revid(self.childmap[parent])
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1185 except KeyError:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1186 pass
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8129
diff changeset
1187 entries = set(self.delete)
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8129
diff changeset
1188 files = frozenset(files)
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1189 entries.update(self.add_dirs(files.difference(entries)))
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1190 if self.copies:
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1191 for s, d in self.copies:
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1192 self._copyfile(s, d)
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1193 self.copies = []
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1194 if self.delete:
5832
2192ed187319 convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents: 5806
diff changeset
1195 self.xargs(self.delete, 'delete')
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1196 self.delete = []
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1197 entries.update(self.add_files(files.difference(entries)))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1198 entries.update(self.tidy_dirs(entries))
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1199 if self.delexec:
5832
2192ed187319 convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents: 5806
diff changeset
1200 self.xargs(self.delexec, 'propdel', 'svn:executable')
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1201 self.delexec = []
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1202 if self.setexec:
5832
2192ed187319 convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents: 5806
diff changeset
1203 self.xargs(self.setexec, 'propset', 'svn:executable', '*')
5698
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1204 self.setexec = []
b63ef7b1441c convert: svn-sink: copy and set properties after adding dirs/files
Maxim Dounin <mdounin@mdounin.ru>
parents: 5618
diff changeset
1205
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1206 fd, messagefile = tempfile.mkstemp(prefix='hg-convert-')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1207 fp = os.fdopen(fd, 'w')
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1208 fp.write(commit.desc)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1209 fp.close()
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1210 try:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1211 output = self.run0('commit',
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1212 username=util.shortuser(commit.author),
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1213 file=messagefile,
5790
f85c0034a062 convert: svn_sink: workaround of command line size limitation on win32.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 5789
diff changeset
1214 encoding='utf-8')
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1215 try:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1216 rev = self.commit_re.search(output).group(1)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1217 except AttributeError:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1218 self.ui.warn(_('unexpected svn output:\n'))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1219 self.ui.warn(output)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1220 raise util.Abort(_('unable to cope with svn output'))
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1221 if commit.rev:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1222 self.run('propset', 'hg:convert-rev', commit.rev,
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1223 revprop=True, revision=rev)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1224 if commit.branch and commit.branch != 'default':
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1225 self.run('propset', 'hg:convert-branch', commit.branch,
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1226 revprop=True, revision=rev)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1227 for parent in parents:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1228 self.addchild(parent, rev)
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5537
diff changeset
1229 return self.revid(rev)
5513
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1230 finally:
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1231 os.unlink(messagefile)
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1232
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1233 def puttags(self, tags):
f0c58fd4b798 convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5511
diff changeset
1234 self.ui.warn(_('XXX TAGS NOT IMPLEMENTED YET\n'))