Mercurial > hgsubversion
annotate hgsubversion/svnexternals.py @ 846:7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
author | Vitaliy Filippov <vitalif@yourcmc.ru> |
---|---|
date | Fri, 20 Jan 2012 19:06:32 +0400 |
parents | 0cbf9fd89672 |
children | 9ce00cb1d676 |
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 _ |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
6 |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
7 try: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
8 from mercurial import subrepo |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
9 # require svnsubrepo and hg >= 1.7.1 |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
10 subrepo.svnsubrepo |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
11 hgutil.checknlink |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
12 except (ImportError, AttributeError), e: |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
13 subrepo = None |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
14 |
817
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
15 passpegrev = True # see svnsubrepo below |
803
6b1ad75f8cda
svnexternals: fix canonpath import after hg.bfeaa88b875d
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
789
diff
changeset
|
16 try: |
819
e30ff6d5feff
Fix import based feature detection
Patrick Mezard <pmezard@gmail.com>
parents:
817
diff
changeset
|
17 canonpath = hgutil.canonpath |
817
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
18 except (ImportError, AttributeError): |
819
e30ff6d5feff
Fix import based feature detection
Patrick Mezard <pmezard@gmail.com>
parents:
817
diff
changeset
|
19 from mercurial import scmutil |
825
c3450512237d
svnexternals.py: style cleanups
Yonggang Luo <luoyonggang@gmail.com>
parents:
819
diff
changeset
|
20 canonpath = scmutil.canonpath |
817
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
21 passpegrev = False |
803
6b1ad75f8cda
svnexternals: fix canonpath import after hg.bfeaa88b875d
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
789
diff
changeset
|
22 |
387
f6050c4dde31
svnexternals: Change an absolute import to be relative.
Augie Fackler <durin42@gmail.com>
parents:
340
diff
changeset
|
23 import util |
174
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 class externalsfile(dict): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
26 """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
|
27 """ |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 def __init__(self): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
29 super(externalsfile, self).__init__() |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 self.encoding = 'utf-8' |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
31 |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
32 def __setitem__(self, key, value): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 if value is None: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 value = [] |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
35 elif isinstance(value, basestring): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 value = value.splitlines() |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 if key == '.': |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 key = '' |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
39 if not value: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
40 if key in self: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
41 del self[key] |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 else: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 super(externalsfile, self).__setitem__(key, value) |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
45 def write(self): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 fp = cStringIO.StringIO() |
286
552deb1351ce
Replace mercurial.util.sort with sorted buildin (after mercurial a1a5a57efe90)
Martijn Pieters <mj@zopatista.com>
parents:
250
diff
changeset
|
47 for target in sorted(self): |
174
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 lines = self[target] |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 if not lines: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 continue |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 if not target: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
52 target = '.' |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 fp.write('[%s]\n' % target) |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
54 for l in lines: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
55 l = ' ' + l + '\n' |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
56 fp.write(l) |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
57 return fp.getvalue() |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
58 |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
59 def read(self, data): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
60 self.clear() |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
61 fp = cStringIO.StringIO(data) |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
62 target = None |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
63 for line in fp.readlines(): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
64 if not line.strip(): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
65 continue |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
66 if line.startswith('['): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
67 line = line.strip() |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
68 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
|
69 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
|
70 target = line[1:-1] |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
71 if target == '.': |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
72 target = '' |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
73 elif line.startswith(' '): |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
74 line = line.rstrip('\n') |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
75 if target is None or not line: |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
76 continue |
f80132c5fea5
Convert svn:externals properties into a .hgsvnexternals file
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
77 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
|
78 |
175
2412800b1258
Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents:
174
diff
changeset
|
79 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
|
80 """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
|
81 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
|
82 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
|
83 """ |
759
864b5b67a5f0
svnexternals: keep diff() simple for the caller, return a list
Patrick Mezard <pmezard@gmail.com>
parents:
758
diff
changeset
|
84 changes = [] |
175
2412800b1258
Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents:
174
diff
changeset
|
85 for d in ext1: |
2412800b1258
Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents:
174
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 for d in ext2: |
2412800b1258
Support svn:externals changes via .hgsvnexternals updates
Patrick Mezard <pmezard@gmail.com>
parents:
174
diff
changeset
|
91 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
|
92 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
|
93 return changes |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
94 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
95 class BadDefinition(Exception): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
96 pass |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
97 |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
98 re_defold = re.compile(r'^\s*(.*?)\s+(?:-r\s*(\d+|\{REV\})\s+)?([a-zA-Z]+://.*)\s*$') |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
99 re_defnew = re.compile(r'^\s*(?:-r\s*(\d+|\{REV\})\s+)?((?:[a-zA-Z]+://|\^/).*)\s+(\S+)\s*$') |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
100 re_scheme = re.compile(r'^[a-zA-Z]+://') |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
101 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
102 def parsedefinition(line): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
103 """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
|
104 or raise BadDefinition. |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
105 """ |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
106 # 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
|
107 # 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
|
108 # these either. |
761
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
109 pegrev, revgroup = None, 1 |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
110 m = re_defnew.search(line) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
111 if m: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
112 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
|
113 if '@' in source: |
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
114 source, pegrev = source.rsplit('@', 1) |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
115 else: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
116 m = re_defold.search(line) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
117 if not m: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
118 raise BadDefinition() |
761
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
119 revgroup = 2 |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
120 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
|
121 try: |
836
0cbf9fd89672
svnexternals: comment on the purpose of int(rev)
Augie Fackler <durin42@gmail.com>
parents:
825
diff
changeset
|
122 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
|
123 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
|
124 except (TypeError, ValueError): |
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
125 norevline = line |
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
126 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
|
127 |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
128 class RelativeSourceError(Exception): |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
129 pass |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
130 |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
131 def resolvesource(ui, svnroot, source): |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
132 if re_scheme.search(source): |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
133 return source |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
134 if source.startswith('^/'): |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
135 if svnroot is None: |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
136 raise RelativeSourceError() |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
137 return svnroot + source[1:] |
782
1f1aeb1f5ffc
svnexternals: missing EOL in ui.warn()
Patrick Mezard <pmezard@gmail.com>
parents:
781
diff
changeset
|
138 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
|
139 % source)) |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
140 return None |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
141 |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
142 def parsedefinitions(ui, repo, svnroot, exts): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
143 """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
|
144 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
|
145 """ |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
146 defs = [] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
147 for base in sorted(exts): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
148 for line in exts[base]: |
789
a5be5ca638de
externals: ignore externals blank or comment lines
Patrick Mezard <pmezard@gmail.com>
parents:
784
diff
changeset
|
149 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
|
150 # Ignore comments and blank lines |
a5be5ca638de
externals: ignore externals blank or comment lines
Patrick Mezard <pmezard@gmail.com>
parents:
784
diff
changeset
|
151 continue |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
152 try: |
761
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
153 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
|
154 except BadDefinition: |
782
1f1aeb1f5ffc
svnexternals: missing EOL in ui.warn()
Patrick Mezard <pmezard@gmail.com>
parents:
781
diff
changeset
|
155 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
|
156 continue |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
157 source = resolvesource(ui, svnroot, source) |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
158 if source is None: |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
159 continue |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
160 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
|
161 wpath = canonpath(repo.root, '', wpath) |
761
979148947967
svnexternals: generate externals with a revision placeholder
Patrick Mezard <pmezard@gmail.com>
parents:
759
diff
changeset
|
162 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
|
163 # Check target dirs are not nested |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
164 defs.sort() |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
165 for i, d in enumerate(defs): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
166 for d2 in defs[i+1:]: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
167 if d2[0].startswith(d[0] + '/'): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
168 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
|
169 % (d[0], d2[0])) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
170 return defs |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
171 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
172 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
|
173 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
174 def listdefs(data): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
175 defs = {} |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
176 exts = externalsfile() |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
177 exts.read(data) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
178 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
|
179 defs[d[0]] = d |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
180 return defs |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
181 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
182 ext1 = listdefs(ext1) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
183 ext2 = listdefs(ext2) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
184 for wp1 in ext1: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
185 if wp1 in ext2: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
186 yield 'u', ext2[wp1] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
187 else: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
188 yield 'd', ext1[wp1] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
189 for wp2 in ext2: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
190 if wp2 not in ext1: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
191 yield 'u', ext2[wp2] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
192 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
193 def getsvninfo(svnurl): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
194 """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
|
195 directory path. |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
196 """ |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
197 # 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
|
198 args = ['svn', 'info', '--xml', svnurl] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 stdout = p.communicate()[0] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
203 if p.returncode: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
204 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
|
205 % svnurl) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
206 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
|
207 if not m: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
208 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
|
209 % svnurl) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
210 root = m.group(1).rstrip('/') |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
211 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
212 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
|
213 if not m: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
214 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
|
215 url = m.group(1) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
216 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
217 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
|
218 if not m: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
219 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
|
220 rev = m.group(1) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
221 return url, root, rev |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
222 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
223 class externalsupdater: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
224 def __init__(self, ui, repo): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
225 self.repo = repo |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
226 self.ui = ui |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
227 |
315
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
228 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
|
229 path = self.repo.wjoin(wpath) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
230 revspec = [] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
231 if rev: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
232 revspec = ['-r', rev] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
233 if os.path.isdir(path): |
825
c3450512237d
svnexternals.py: style cleanups
Yonggang Luo <luoyonggang@gmail.com>
parents:
819
diff
changeset
|
234 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
|
235 # 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
|
236 # 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
|
237 # 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
|
238 # 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
|
239 # and updating again. |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
240 if source == exturl: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
241 if extrev != rev: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
242 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
|
243 (wpath, rev or 'HEAD')) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
244 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
|
245 self.svn(['update'] + revspec, cwd) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
246 return |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
247 self.delete(wpath) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
248 cwd, dest = os.path.split(path) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
249 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
|
250 if not os.path.isdir(cwd): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
251 os.makedirs(cwd) |
315
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
252 if not pegrev and rev: |
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
253 pegrev = rev |
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
254 if pegrev: |
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
255 source = '%s@%s' % (source, pegrev) |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
256 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
|
257 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
|
258 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
259 def delete(self, wpath): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
260 path = self.repo.wjoin(wpath) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
261 if os.path.isdir(path): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
262 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
|
263 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
264 def onerror(function, path, excinfo): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
265 if function is not os.remove: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
266 raise |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
267 # 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
|
268 s = os.stat(path) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
269 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
|
270 raise |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
271 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
|
272 os.remove(path) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
273 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
274 shutil.rmtree(path, onerror=onerror) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
275 return 1 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
276 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
277 def svn(self, args, cwd): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
278 args = ['svn'] + args |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
279 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
|
280 shell = os.name == 'nt' |
470
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
281 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
|
282 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
283 for line in p.stdout: |
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
284 self.ui.note(line) |
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
285 p.wait() |
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
286 if p.returncode != 0: |
6bfaa9deb432
svnexternals: display svn commands output with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
387
diff
changeset
|
287 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
|
288 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
289 def updateexternals(ui, args, repo, **opts): |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
290 """update repository externals |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
291 """ |
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
|
292 if len(args) > 2: |
291
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 if args: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
301 node = args[0] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
302 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
303 svnroot = getsvninfo(svnurl)[1] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
304 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
305 # Retrieve current externals status |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
306 try: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
307 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
|
308 except IOError: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
309 oldext = '' |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
310 newext = '' |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
311 ctx = repo[node] |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
312 if '.hgsvnexternals' in ctx: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
313 newext = ctx['.hgsvnexternals'].data() |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
314 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
315 updater = externalsupdater(ui, repo) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
316 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
|
317 for action, ext in actions: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
318 if action == 'u': |
315
963d27a0b1c2
svnexternals: do not use peg revisions as --rev replacements
Patrick Mezard <pmezard@gmail.com>
parents:
291
diff
changeset
|
319 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
|
320 elif action == 'd': |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
321 updater.delete(ext[0]) |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
322 else: |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
323 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
|
324 |
ba8e91a7c077
Add 'updateexternals' to synchronize externals with remote repo.
Patrick Mezard <pmezard@gmail.com>
parents:
286
diff
changeset
|
325 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
|
326 |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
327 def getchanges(ui, repo, parentctx, exts): |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
328 """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
|
329 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
|
330 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
|
331 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
|
332 """ |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
333 mode = ui.config('hgsubversion', 'externals', 'svnexternals') |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
334 if mode == 'svnexternals': |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
335 files = { |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
336 '.hgsvnexternals': 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 files['.hgsvnexternals'] = exts.write() |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
340 elif mode == 'subrepos': |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
341 # 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
|
342 files = { |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
343 '.hgsub': None, |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
344 '.hgsubstate': None, |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
345 } |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
346 if exts: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
347 defs = parsedefinitions(ui, repo, '', exts) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
348 hgsub, hgsubstate = [], [] |
825
c3450512237d
svnexternals.py: style cleanups
Yonggang Luo <luoyonggang@gmail.com>
parents:
819
diff
changeset
|
349 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
|
350 hgsub.append('%s = [hgsubversion] %s:%s\n' |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
351 % (path, base, norevline)) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
352 if rev is None: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
353 rev = 'HEAD' |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
354 hgsubstate.append('%s %s\n' % (rev, path)) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
355 files['.hgsub'] = ''.join(hgsub) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
356 files['.hgsubstate'] = ''.join(hgsubstate) |
776
f025d00bfc4a
svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents:
764
diff
changeset
|
357 elif mode == 'ignore': |
f025d00bfc4a
svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents:
764
diff
changeset
|
358 files = {} |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
359 else: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
360 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
|
361 |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
362 # Should the really be updated? |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
363 updates = {} |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
364 for fn, data in files.iteritems(): |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
365 if data is not None: |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
366 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
|
367 updates[fn] = data |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
368 else: |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
369 if fn in parentctx: |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
370 updates[fn] = None |
6e18d9ab6557
pull: stop handling .hgsvnexternals explicitely in memctx
Patrick Mezard <pmezard@gmail.com>
parents:
470
diff
changeset
|
371 return updates |
758
76ebfc41f490
svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents:
757
diff
changeset
|
372 |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
373 def parse(ui, ctx): |
758
76ebfc41f490
svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents:
757
diff
changeset
|
374 """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
|
375 externalsfile(). |
76ebfc41f490
svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents:
757
diff
changeset
|
376 """ |
76ebfc41f490
svnexternals: hide .hgsvnexternals parsing in parse()
Patrick Mezard <pmezard@gmail.com>
parents:
757
diff
changeset
|
377 external = externalsfile() |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
378 mode = ui.config('hgsubversion', 'externals', 'svnexternals') |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
379 if mode == 'svnexternals': |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
380 if '.hgsvnexternals' in ctx: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
381 external.read(ctx['.hgsvnexternals'].data()) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
382 elif mode == 'subrepos': |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
383 for path in ctx.substate: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
384 src, rev = ctx.substate[path][:2] |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
385 base, norevline = src.split(':', 1) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
386 base = base.strip() |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
387 if rev is None: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
388 rev = 'HEAD' |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
389 line = norevline.replace('{REV}', rev) |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
390 external.setdefault(base, []).append(line) |
776
f025d00bfc4a
svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents:
764
diff
changeset
|
391 elif mode == 'ignore': |
f025d00bfc4a
svnexternals: add 'ignore' mode to avoid converting externals
Patrick Mezard <pmezard@gmail.com>
parents:
764
diff
changeset
|
392 pass |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
393 else: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
394 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
|
395 return external |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
396 |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
397 if subrepo: |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
398 class svnsubrepo(subrepo.svnsubrepo): |
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
399 def __init__(self, ctx, path, state): |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
400 state = (state[0].split(':', 1)[1], state[1]) |
762
c31a1f92e1c6
svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents:
761
diff
changeset
|
401 super(svnsubrepo, self).__init__(ctx, path, state) |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
402 |
784
f214fb3f92cd
svnexternals: handle new overwrite argument of subrepo.get()
Patrick Mezard <pmezard@gmail.com>
parents:
782
diff
changeset
|
403 def get(self, state, *args, **kwargs): |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
404 # Resolve source first |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
405 line = state[0].split(':', 1)[1] |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
406 source, pegrev = parsedefinition(line)[2:4] |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
407 try: |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
408 # Getting the root SVN repository URL is expensive. |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
409 # Assume the externals is absolute. |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
410 source = resolvesource(self._ui, None, source) |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
411 except RelativeSourceError: |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
412 svnurl = self._ctx._repo.ui.expandpath('default') |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
413 svnroot = getsvninfo(util.normalize_url(svnurl))[1] |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
414 source = resolvesource(self._ui, svnroot, source) |
817
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
415 # hg < 1.9 svnsubrepo calls "svn checkout" with --rev |
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
416 # only, so peg revisions are correctly used. 1.9 and |
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
417 # higher, append the rev as a peg revision to the source |
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
418 # URL, so we cannot add our own. We assume that "-r10 |
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
419 # url@2" will be similar to "url@10" most of the time. |
3b613d32ef11
svnexternals: fix subrepo peg revision handling (7ef125fa9b35)
Patrick Mezard <pmezard@gmail.com>
parents:
807
diff
changeset
|
420 if pegrev is not None and passpegrev: |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
421 source = source + '@' + pegrev |
784
f214fb3f92cd
svnexternals: handle new overwrite argument of subrepo.get()
Patrick Mezard <pmezard@gmail.com>
parents:
782
diff
changeset
|
422 state = (source, state[1]) |
f214fb3f92cd
svnexternals: handle new overwrite argument of subrepo.get()
Patrick Mezard <pmezard@gmail.com>
parents:
782
diff
changeset
|
423 # hg-1.7.4-c19b9282d3a7 introduced the overwrite argument |
f214fb3f92cd
svnexternals: handle new overwrite argument of subrepo.get()
Patrick Mezard <pmezard@gmail.com>
parents:
782
diff
changeset
|
424 return super(svnsubrepo, self).get(state, *args, **kwargs) |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
425 |
778
184d25bc1c0b
svnexternals: add ignoreupdate param to svnsubrepo.dirty()
Patrick Mezard <pmezard@gmail.com>
parents:
776
diff
changeset
|
426 def dirty(self, ignoreupdate=False): |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
427 # You cannot compare anything with HEAD. Just accept it |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
428 # can be anything. |
781
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
429 if hasattr(self, '_wcrevs'): |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
430 wcrevs = self._wcrevs() |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
431 else: |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
432 wcrev = self._wcrev() |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
433 wcrevs = (wcrev, wcrev) |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
434 if (('HEAD' in wcrevs or self._state[1] == 'HEAD' or |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
435 self._state[1] in wcrevs or ignoreupdate) |
16252bea2026
svnexternals: update subrepo after mercurial changes
Patrick Mezard <pmezard@gmail.com>
parents:
778
diff
changeset
|
436 and not self._wcchanged()[0]): |
763
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
437 return False |
6463b34bbcb6
svnexternals: support subrepos based externals checkout
Patrick Mezard <pmezard@gmail.com>
parents:
762
diff
changeset
|
438 return True |
764
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
439 |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
440 def commit(self, text, user, date): |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
441 rev = super(svnsubrepo, self).commit(text, user, date) |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
442 # Keep unversioned externals unversioned |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
443 if self._state[1] == 'HEAD': |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
444 rev = 'HEAD' |
bc5c176b63eb
svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents:
763
diff
changeset
|
445 return rev |