annotate hgsubversion/svnexternals.py @ 1141:a4b54b19cd2e

util: add default parameter to load This will help facilitate moving load_string to just use load.
author Sean Farley <sean.michael.farley@gmail.com>
date Sat, 15 Feb 2014 10:42:54 -0600
parents 2efc4abd4602
children 9d5cff8d7f67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
1 import cStringIO
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
2
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
3 import os, re, shutil, stat, subprocess
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 175
diff changeset
4 from mercurial import util as hgutil
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
5 from mercurial.i18n import _
1118
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
6 from mercurial import subrepo
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
7
803
6b1ad75f8cda svnexternals: fix canonpath import after hg.bfeaa88b875d
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 789
diff changeset
8 try:
1119
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
9 from mercurial import scmutil
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
10 canonpath = scmutil.canonpath
817
3b613d32ef11 svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents: 807
diff changeset
11 except (ImportError, AttributeError):
1119
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
12 from mercurial import pathutil
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
13 canonpath = pathutil.canonpath
803
6b1ad75f8cda svnexternals: fix canonpath import after hg.bfeaa88b875d
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 789
diff changeset
14
387
f6050c4dde31 svnexternals: Change an absolute import to be relative.
Augie Fackler <durin42@gmail.com>
parents: 340
diff changeset
15 import util
174
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
16
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
17 class externalsfile(dict):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
18 """Map svn directories to lists of externals entries.
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
19 """
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
20 def __init__(self):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
21 super(externalsfile, self).__init__()
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
22 self.encoding = 'utf-8'
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
23
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
24 def __setitem__(self, key, value):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
25 if value is None:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
26 value = []
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
27 elif isinstance(value, basestring):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
28 value = value.splitlines()
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
29 if key == '.':
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
30 key = ''
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
31 if not value:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
32 if key in self:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
33 del self[key]
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
34 else:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
35 super(externalsfile, self).__setitem__(key, value)
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
36
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
37 def write(self):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
38 fp = cStringIO.StringIO()
286
552deb1351ce Replace mercurial.util.sort with sorted buildin (after mercurial a1a5a57efe90)
Martijn Pieters <mj@zopatista.com>
parents: 250
diff changeset
39 for target in sorted(self):
174
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
40 lines = self[target]
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
41 if not lines:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
42 continue
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
43 if not target:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
44 target = '.'
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
45 fp.write('[%s]\n' % target)
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
46 for l in lines:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
47 l = ' ' + l + '\n'
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
48 fp.write(l)
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
49 return fp.getvalue()
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
50
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
51 def read(self, data):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
52 self.clear()
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
53 fp = cStringIO.StringIO(data)
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
54 target = None
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
55 for line in fp.readlines():
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
56 if not line.strip():
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
57 continue
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
58 if line.startswith('['):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
59 line = line.strip()
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
60 if line[-1] != ']':
250
79349fd04836 utils: standardizing imported name to hgutil, our_util to util
Daniel Tang <dytang@cs.purdue.edu>
parents: 175
diff changeset
61 raise hgutil.Abort('invalid externals section name: %s' % line)
174
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
62 target = line[1:-1]
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
63 if target == '.':
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
64 target = ''
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
65 elif line.startswith(' '):
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
66 line = line.rstrip('\n')
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
67 if target is None or not line:
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
68 continue
f80132c5fea5 Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
69 self.setdefault(target, []).append(line[1:])
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
70
175
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
71 def diff(ext1, ext2):
759
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
72 """Compare 2 externalsfile and return a list of tuples like (dir,
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
73 value1, value2) where value1 is the external value in ext1 for dir
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
74 or None, and value2 the same in ext2.
175
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
75 """
759
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
76 changes = []
175
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
77 for d in ext1:
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
78 if d not in ext2:
759
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
79 changes.append((d, '\n'.join(ext1[d]), None))
175
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
80 elif ext1[d] != ext2[d]:
759
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
81 changes.append((d, '\n'.join(ext1[d]), '\n'.join(ext2[d])))
175
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
82 for d in ext2:
2412800b1258 Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents: 174
diff changeset
83 if d not in ext1:
759
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
84 changes.append((d, None, '\n'.join(ext2[d])))
864b5b67a5f0 svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents: 758
diff changeset
85 return changes
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
86
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
87 class BadDefinition(Exception):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
88 pass
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
89
850
d3bc067c0f72 Cope with non standard schemes in externals
Will Wykeham <will@wykeham.net>
parents: 819
diff changeset
90 re_defold = re.compile(r'^\s*(.*?)\s+(?:-r\s*(\d+|\{REV\})\s+)?([a-zA-Z+]+://.*)\s*$')
d3bc067c0f72 Cope with non standard schemes in externals
Will Wykeham <will@wykeham.net>
parents: 819
diff changeset
91 re_defnew = re.compile(r'^\s*(?:-r\s*(\d+|\{REV\})\s+)?((?:[a-zA-Z+]+://|\^/).*)\s+(\S+)\s*$')
d3bc067c0f72 Cope with non standard schemes in externals
Will Wykeham <will@wykeham.net>
parents: 819
diff changeset
92 re_scheme = re.compile(r'^[a-zA-Z+]+://')
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
93
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
94 def parsedefinition(line):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
95 """Parse an external definition line, return a tuple (path, rev, source)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
96 or raise BadDefinition.
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
97 """
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
98 # The parsing is probably not correct wrt path with whitespaces or
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
99 # potential quotes. svn documentation is not really talkative about
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
100 # these either.
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
101 pegrev, revgroup = None, 1
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
102 m = re_defnew.search(line)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
103 if m:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
104 rev, source, path = m.group(1, 2, 3)
315
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
105 if '@' in source:
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
106 source, pegrev = source.rsplit('@', 1)
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
107 else:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
108 m = re_defold.search(line)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
109 if not m:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
110 raise BadDefinition()
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
111 revgroup = 2
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
112 path, rev, source = m.group(1, 2, 3)
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
113 try:
836
0cbf9fd89672 svnexternals: comment on the purpose of int(rev)
Augie Fackler <durin42@gmail.com>
parents: 825
diff changeset
114 int(rev) # ensure revision is int()able, so we bail otherwise
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
115 norevline = line[:m.start(revgroup)] + '{REV}' + line[m.end(revgroup):]
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
116 except (TypeError, ValueError):
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
117 norevline = line
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
118 return (path, rev, source, pegrev, norevline)
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
119
763
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
120 class RelativeSourceError(Exception):
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
121 pass
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
122
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
123 def resolvesource(ui, svnroot, source):
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
124 if re_scheme.search(source):
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
125 return source
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
126 if source.startswith('^/'):
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
127 if svnroot is None:
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
128 raise RelativeSourceError()
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
129 return svnroot + source[1:]
782
1f1aeb1f5ffc svnexternals: missing EOL in ui.warn()
Patrick Mezard <pmezard@gmail.com>
parents: 781
diff changeset
130 ui.warn(_('ignoring unsupported non-fully qualified external: %r\n'
1f1aeb1f5ffc svnexternals: missing EOL in ui.warn()
Patrick Mezard <pmezard@gmail.com>
parents: 781
diff changeset
131 % source))
763
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
132 return None
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
133
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
134 def parsedefinitions(ui, repo, svnroot, exts):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
135 """Return (targetdir, revision, source) tuples. Fail if nested
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
136 targetdirs are detected. source is an svn project URL.
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
137 """
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
138 defs = []
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
139 for base in sorted(exts):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
140 for line in exts[base]:
789
a5be5ca638de externals: ignore externals blank or comment lines
Patrick Mezard <pmezard@gmail.com>
parents: 784
diff changeset
141 if not line.strip() or line.lstrip().startswith('#'):
a5be5ca638de externals: ignore externals blank or comment lines
Patrick Mezard <pmezard@gmail.com>
parents: 784
diff changeset
142 # Ignore comments and blank lines
a5be5ca638de externals: ignore externals blank or comment lines
Patrick Mezard <pmezard@gmail.com>
parents: 784
diff changeset
143 continue
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
144 try:
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
145 path, rev, source, pegrev, norevline = parsedefinition(line)
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
146 except BadDefinition:
782
1f1aeb1f5ffc svnexternals: missing EOL in ui.warn()
Patrick Mezard <pmezard@gmail.com>
parents: 781
diff changeset
147 ui.warn(_('ignoring invalid external definition: %r\n' % line))
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
148 continue
763
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
149 source = resolvesource(ui, svnroot, source)
6463b34bbcb6 svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
150 if source is None:
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
151 continue
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
152 wpath = hgutil.pconvert(os.path.join(base, path))
803
6b1ad75f8cda svnexternals: fix canonpath import after hg.bfeaa88b875d
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 789
diff changeset
153 wpath = canonpath(repo.root, '', wpath)
761
979148947967 svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents: 759
diff changeset
154 defs.append((wpath, rev, source, pegrev, norevline, base))
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
155 # Check target dirs are not nested
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
156 defs.sort()
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
157 for i, d in enumerate(defs):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
158 for d2 in defs[i+1:]:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
159 if d2[0].startswith(d[0] + '/'):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
160 raise hgutil.Abort(_('external directories cannot nest:\n%s\n%s')
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
161 % (d[0], d2[0]))
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
162 return defs
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
163
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
164 def computeactions(ui, repo, svnroot, ext1, ext2):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
165
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
166 def listdefs(data):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
167 defs = {}
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
168 exts = externalsfile()
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
169 exts.read(data)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
170 for d in parsedefinitions(ui, repo, svnroot, exts):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
171 defs[d[0]] = d
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
172 return defs
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
173
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
174 ext1 = listdefs(ext1)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
175 ext2 = listdefs(ext2)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
176 for wp1 in ext1:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
177 if wp1 in ext2:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
178 yield 'u', ext2[wp1]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
179 else:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
180 yield 'd', ext1[wp1]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
181 for wp2 in ext2:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
182 if wp2 not in ext1:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
183 yield 'u', ext2[wp2]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
184
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
185 def getsvninfo(svnurl):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
186 """Return a tuple (url, root) for supplied svn URL or working
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
187 directory path.
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
188 """
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
189 # Yes, this is ugly, but good enough for now
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
190 args = ['svn', 'info', '--xml', svnurl]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
191 shell = os.name == 'nt'
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
192 p = subprocess.Popen(args, shell=shell,
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
193 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
194 stdout = p.communicate()[0]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
195 if p.returncode:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
196 raise hgutil.Abort(_('cannot get information about %s')
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
197 % svnurl)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
198 m = re.search(r'<root>(.*)</root>', stdout, re.S)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
199 if not m:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
200 raise hgutil.Abort(_('cannot find SVN repository root from %s')
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
201 % svnurl)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
202 root = m.group(1).rstrip('/')
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
203
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
204 m = re.search(r'<url>(.*)</url>', stdout, re.S)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
205 if not m:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
206 raise hgutil.Abort(_('cannot find SVN repository URL from %s') % svnurl)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
207 url = m.group(1)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
208
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
209 m = re.search(r'<entry[^>]+revision="([^"]+)"', stdout, re.S)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
210 if not m:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
211 raise hgutil.Abort(_('cannot find SVN revision from %s') % svnurl)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
212 rev = m.group(1)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
213 return url, root, rev
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
214
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
215 class externalsupdater:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
216 def __init__(self, ui, repo):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
217 self.repo = repo
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
218 self.ui = ui
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
219
315
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
220 def update(self, wpath, rev, source, pegrev):
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
221 path = self.repo.wjoin(wpath)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
222 revspec = []
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
223 if rev:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
224 revspec = ['-r', rev]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
225 if os.path.isdir(path):
825
c3450512237d svnexternals.py: style cleanups
Yonggang Luo <luoyonggang@gmail.com>
parents: 819
diff changeset
226 exturl, _extroot, extrev = getsvninfo(path)
315
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
227 # Comparing the source paths is not enough, but I don't
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
228 # know how to compare path+pegrev. The following update
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
229 # might fail if the path was replaced by another unrelated
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
230 # one. It can be fixed manually by deleting the externals
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
231 # and updating again.
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
232 if source == exturl:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
233 if extrev != rev:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
234 self.ui.status(_('updating external on %s@%s\n') %
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
235 (wpath, rev or 'HEAD'))
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
236 cwd = os.path.join(self.repo.root, path)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
237 self.svn(['update'] + revspec, cwd)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
238 return
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
239 self.delete(wpath)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
240 cwd, dest = os.path.split(path)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
241 cwd = os.path.join(self.repo.root, cwd)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
242 if not os.path.isdir(cwd):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
243 os.makedirs(cwd)
315
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
244 if not pegrev and rev:
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
245 pegrev = rev
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
246 if pegrev:
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
247 source = '%s@%s' % (source, pegrev)
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
248 self.ui.status(_('fetching external %s@%s\n') % (wpath, rev or 'HEAD'))
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
249 self.svn(['co'] + revspec + [source, dest], cwd)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
250
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
251 def delete(self, wpath):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
252 path = self.repo.wjoin(wpath)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
253 if os.path.isdir(path):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
254 self.ui.status(_('removing external %s\n') % wpath)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
255
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
256 def onerror(function, path, excinfo):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
257 if function is not os.remove:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
258 raise
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
259 # read-only files cannot be unlinked under Windows
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
260 s = os.stat(path)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
261 if (s.st_mode & stat.S_IWRITE) != 0:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
262 raise
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
263 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
264 os.remove(path)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
265
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
266 shutil.rmtree(path, onerror=onerror)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
267 return 1
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
268
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
269 def svn(self, args, cwd):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
270 args = ['svn'] + args
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
271 self.ui.debug(_('updating externals: %r, cwd=%s\n') % (args, cwd))
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
272 shell = os.name == 'nt'
470
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
273 p = subprocess.Popen(args, cwd=cwd, shell=shell,
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
274 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
275 for line in p.stdout:
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
276 self.ui.note(line)
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
277 p.wait()
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
278 if p.returncode != 0:
6bfaa9deb432 svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents: 387
diff changeset
279 raise hgutil.Abort("subprocess '%s' failed" % ' '.join(args))
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
280
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
281 def updateexternals(ui, args, repo, **opts):
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
282 """update repository externals
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
283 """
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
284 if len(args) > 2:
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
285 raise hgutil.Abort(_('updateexternals expects at most one changeset'))
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
286 node = None
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
287 if len(args) == 2:
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
288 svnurl = util.normalize_url(repo.ui.expandpath(args[0]))
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
289 args = args[1:]
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
290 else:
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 315
diff changeset
291 svnurl = util.normalize_url(repo.ui.expandpath('default'))
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
292 if args:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
293 node = args[0]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
294
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
295 svnroot = getsvninfo(svnurl)[1]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
296
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
297 # Retrieve current externals status
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
298 try:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
299 oldext = file(repo.join('svn/externals'), 'rb').read()
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
300 except IOError:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
301 oldext = ''
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
302 newext = ''
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
303 ctx = repo[node]
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
304 if '.hgsvnexternals' in ctx:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
305 newext = ctx['.hgsvnexternals'].data()
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
306
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
307 updater = externalsupdater(ui, repo)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
308 actions = computeactions(ui, repo, svnroot, oldext, newext)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
309 for action, ext in actions:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
310 if action == 'u':
315
963d27a0b1c2 svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents: 291
diff changeset
311 updater.update(ext[0], ext[1], ext[2], ext[3])
291
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
312 elif action == 'd':
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
313 updater.delete(ext[0])
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
314 else:
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
315 raise hgutil.Abort(_('unknown update actions: %r') % action)
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
316
ba8e91a7c077 Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents: 286
diff changeset
317 file(repo.join('svn/externals'), 'wb').write(newext)
757
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
318
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
319 def getchanges(ui, repo, parentctx, exts):
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
320 """Take a parent changectx and the new externals definitions as an
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
321 externalsfile and return a dictionary mapping the special file
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
322 hgsubversion needs for externals bookkeeping, to their new content
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
323 as raw bytes or None if the file has to be removed.
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
324 """
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
325 mode = ui.config('hgsubversion', 'externals', 'svnexternals')
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
326 if mode == 'svnexternals':
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
327 files = {
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
328 '.hgsvnexternals': None,
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
329 }
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
330 if exts:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
331 files['.hgsvnexternals'] = exts.write()
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
332 elif mode == 'subrepos':
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
333 # XXX: clobering the subrepos files is good enough for now
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
334 files = {
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
335 '.hgsub': None,
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
336 '.hgsubstate': None,
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
337 }
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
338 if exts:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
339 defs = parsedefinitions(ui, repo, '', exts)
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
340 hgsub, hgsubstate = [], []
825
c3450512237d svnexternals.py: style cleanups
Yonggang Luo <luoyonggang@gmail.com>
parents: 819
diff changeset
341 for path, rev, _source, _pegrev, norevline, base in sorted(defs):
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
342 hgsub.append('%s = [hgsubversion] %s:%s\n'
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
343 % (path, base, norevline))
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
344 if rev is None:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
345 rev = 'HEAD'
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
346 hgsubstate.append('%s %s\n' % (rev, path))
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
347 files['.hgsub'] = ''.join(hgsub)
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
348 files['.hgsubstate'] = ''.join(hgsubstate)
776
f025d00bfc4a svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents: 764
diff changeset
349 elif mode == 'ignore':
f025d00bfc4a svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents: 764
diff changeset
350 files = {}
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
351 else:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
352 raise hgutil.Abort(_('unknown externals modes: %s') % mode)
757
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
353
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
354 # Should the really be updated?
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
355 updates = {}
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
356 for fn, data in files.iteritems():
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
357 if data is not None:
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
358 if fn not in parentctx or parentctx[fn].data() != data:
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
359 updates[fn] = data
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
360 else:
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
361 if fn in parentctx:
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
362 updates[fn] = None
6e18d9ab6557 pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents: 470
diff changeset
363 return updates
758
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
364
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
365 def parse(ui, ctx):
758
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
366 """Return the externals definitions stored in ctx as a (possibly empty)
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
367 externalsfile().
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
368 """
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
369 external = externalsfile()
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
370 mode = ui.config('hgsubversion', 'externals', 'svnexternals')
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
371 if mode == 'svnexternals':
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
372 if '.hgsvnexternals' in ctx:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
373 external.read(ctx['.hgsvnexternals'].data())
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
374 elif mode == 'subrepos':
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
375 for path in ctx.substate:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
376 src, rev = ctx.substate[path][:2]
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
377 base, norevline = src.split(':', 1)
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
378 base = base.strip()
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
379 if rev is None:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
380 rev = 'HEAD'
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
381 line = norevline.replace('{REV}', rev)
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
382 external.setdefault(base, []).append(line)
776
f025d00bfc4a svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents: 764
diff changeset
383 elif mode == 'ignore':
f025d00bfc4a svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents: 764
diff changeset
384 pass
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
385 else:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
386 raise hgutil.Abort(_('unknown externals modes: %s') % mode)
758
76ebfc41f490 svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents: 757
diff changeset
387 return external
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 761
diff changeset
388
1118
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
389 class svnsubrepo(subrepo.svnsubrepo):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
390 def __init__(self, ctx, path, state):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
391 state = (state[0].split(':', 1)[1], state[1])
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
392 super(svnsubrepo, self).__init__(ctx, path, state)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
393
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
394 def get(self, state, *args, **kwargs):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
395 # Resolve source first
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
396 line = state[0].split(':', 1)[1]
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
397 source, pegrev = parsedefinition(line)[2:4]
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
398 try:
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
399 # Getting the root SVN repository URL is expensive.
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
400 # Assume the externals is absolute.
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
401 source = resolvesource(self._ui, None, source)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
402 except RelativeSourceError:
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
403 svnurl = self._ctx._repo.ui.expandpath('default')
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
404 svnroot = getsvninfo(util.normalize_url(svnurl))[1]
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
405 source = resolvesource(self._ui, svnroot, source)
1119
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
406 # hg 1.9 and higher, append the rev as a peg revision to
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
407 # the source URL, so we cannot add our own. We assume
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
408 # that "-r10 url@2" will be similar to "url@10" most of
2efc4abd4602 svnexternals: remove pre-1.9 pegrev code
Sean Farley <sean.michael.farley@gmail.com>
parents: 1118
diff changeset
409 # the time.
1118
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
410 state = (source, state[1])
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
411 return super(svnsubrepo, self).get(state, *args, **kwargs)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
412
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
413 def dirty(self, ignoreupdate=False):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
414 # You cannot compare anything with HEAD. Just accept it
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
415 # can be anything.
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
416 if hasattr(self, '_wcrevs'):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
417 wcrevs = self._wcrevs()
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
418 else:
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
419 wcrev = self._wcrev()
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
420 wcrevs = (wcrev, wcrev)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
421 if (('HEAD' in wcrevs or self._state[1] == 'HEAD' or
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
422 self._state[1] in wcrevs or ignoreupdate)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
423 and not self._wcchanged()[0]):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
424 return False
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
425 return True
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
426
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
427 def commit(self, text, user, date):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
428 rev = super(svnsubrepo, self).commit(text, user, date)
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
429 # Keep unversioned externals unversioned
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
430 if self._state[1] == 'HEAD':
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
431 rev = 'HEAD'
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
432 return rev
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
433
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
434 def basestate(self):
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
435 # basestate() was introduced by bcb973abcc0b in 2.2
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
436 if self._state[1] == 'HEAD':
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
437 return 'HEAD'
5490194e688e svnexternals: remove pre-1.7 code and reindent
Sean Farley <sean.michael.farley@gmail.com>
parents: 1100
diff changeset
438 return super(svnsubrepo, self).basestate()