##// END OF EJS Templates
subrepo: add more debugging output, lose _ markers
Matt Mackall -
r9782:c1c40511 default
parent child Browse files
Show More
@@ -1,220 +1,226 b''
1 1 # subrepo.py - sub-repository handling for Mercurial
2 2 #
3 3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2, incorporated herein by reference.
7 7
8 8 import errno, os
9 9 from i18n import _
10 10 import config, util, node, error
11 11 hg = None
12 12
13 13 nullstate = ('', '')
14 14
15 15 def state(ctx):
16 16 p = config.config()
17 17 def read(f, sections=None, remap=None):
18 18 if f in ctx:
19 19 try:
20 20 p.parse(f, ctx[f].data(), sections, remap)
21 21 except IOError, err:
22 22 if err.errno != errno.ENOENT:
23 23 raise
24 24 read('.hgsub')
25 25
26 26 rev = {}
27 27 if '.hgsubstate' in ctx:
28 28 try:
29 29 for l in ctx['.hgsubstate'].data().splitlines():
30 30 revision, path = l.split(" ", 1)
31 31 rev[path] = revision
32 32 except IOError, err:
33 33 if err.errno != errno.ENOENT:
34 34 raise
35 35
36 36 state = {}
37 37 for path, src in p[''].items():
38 38 state[path] = (src, rev.get(path, ''))
39 39
40 40 return state
41 41
42 42 def writestate(repo, state):
43 43 repo.wwrite('.hgsubstate',
44 44 ''.join(['%s %s\n' % (state[s][1], s)
45 45 for s in sorted(state)]), '')
46 46
47 47 def submerge(repo, wctx, mctx, actx):
48 48 if mctx == actx: # backwards?
49 49 actx = wctx.p1()
50 50 s1 = wctx.substate
51 51 s2 = mctx.substate
52 52 sa = actx.substate
53 53 sm = {}
54 54
55 repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx))
56
55 57 def debug(s, msg, r=""):
56 58 if r:
57 59 r = "%s:%s" % r
58 repo.ui.debug(_(" subrepo %s: %s %s\n") % (s, msg, r))
60 repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r))
59 61
60 62 for s, l in s1.items():
61 63 if wctx.sub(s).dirty():
62 64 l = (l[0], l[1] + "+")
63 65 a = sa.get(s, nullstate)
64 66 if s in s2:
65 67 r = s2[s]
66 68 if l == r or r == a: # no change or local is newer
67 69 sm[s] = l
68 70 continue
69 71 elif l == a: # other side changed
70 debug(s, _("other changed, get"), r)
72 debug(s, "other changed, get", r)
71 73 wctx.sub(s).get(r)
72 74 sm[s] = r
73 75 elif l[0] != r[0]: # sources differ
74 76 if repo.ui.promptchoice(
75 77 _(' subrepository sources for %s differ\n'
76 78 'use (l)ocal source (%s) or (r)emote source (%s)?')
77 79 % (s, l[0], r[0]),
78 80 (_('&Local'), _('&Remote')), 0):
79 debug(s, _("prompt changed, get"), r)
81 debug(s, "prompt changed, get", r)
80 82 wctx.sub(s).get(r)
81 83 sm[s] = r
82 84 elif l[1] == a[1]: # local side is unchanged
83 debug(s, _("other side changed, get"), r)
85 debug(s, "other side changed, get", r)
84 86 wctx.sub(s).get(r)
85 87 sm[s] = r
86 88 else:
87 debug(s, _("both sides changed, merge with"), r)
89 debug(s, "both sides changed, merge with", r)
88 90 wctx.sub(s).merge(r)
89 91 sm[s] = l
90 92 elif l == a: # remote removed, local unchanged
91 debug(s, _("remote removed, remove"))
93 debug(s, "remote removed, remove")
92 94 wctx.sub(s).remove()
93 95 else:
94 96 if repo.ui.promptchoice(
95 97 _(' local changed subrepository %s which remote removed\n'
96 98 'use (c)hanged version or (d)elete?') % s,
97 99 (_('&Changed'), _('&Delete')), 0):
98 debug(s, _("prompt remove"))
100 debug(s, "prompt remove")
99 101 wctx.sub(s).remove()
100 102
101 103 for s, r in s2.items():
102 104 if s in s1:
103 105 continue
104 106 elif s not in sa:
105 debug(s, _("remote added, get"), r)
107 debug(s, "remote added, get", r)
106 108 wctx.sub(s).get(r)
107 109 sm[s] = r
108 110 elif r != sa[s]:
109 111 if repo.ui.promptchoice(
110 112 _(' remote changed subrepository %s which local removed\n'
111 113 'use (c)hanged version or (d)elete?') % s,
112 114 (_('&Changed'), _('&Delete')), 0) == 0:
113 debug(s, _("prompt recreate"), r)
115 debug(s, "prompt recreate", r)
114 116 wctx.sub(s).get(r)
115 117 sm[s] = r
116 118
117 119 # record merged .hgsubstate
118 120 writestate(repo, sm)
119 121
120 122 def _abssource(repo, push=False):
121 123 if hasattr(repo, '_subparent'):
122 124 source = repo._subsource
123 125 if source.startswith('/') or '://' in source:
124 126 return source
125 127 parent = _abssource(repo._subparent)
126 128 if '://' in parent:
127 129 if parent[-1] == '/':
128 130 parent = parent[:-1]
129 131 return parent + '/' + source
130 132 return os.path.join(parent, repo._subsource)
131 133 if push and repo.ui.config('paths', 'default-push'):
132 134 return repo.ui.config('paths', 'default-push', repo.root)
133 135 return repo.ui.config('paths', 'default', repo.root)
134 136
135 137 def subrepo(ctx, path):
136 138 # subrepo inherently violates our import layering rules
137 139 # because it wants to make repo objects from deep inside the stack
138 140 # so we manually delay the circular imports to not break
139 141 # scripts that don't use our demand-loading
140 142 global hg
141 143 import hg as h
142 144 hg = h
143 145
144 146 util.path_auditor(ctx._repo.root)(path)
145 147 state = ctx.substate.get(path, nullstate)
146 148 if state[0].startswith('['): # future expansion
147 149 raise error.Abort('unknown subrepo source %s' % state[0])
148 150 return hgsubrepo(ctx, path, state)
149 151
150 152 class hgsubrepo(object):
151 153 def __init__(self, ctx, path, state):
152 154 self._path = path
153 155 self._state = state
154 156 r = ctx._repo
155 157 root = r.wjoin(path)
156 158 if os.path.exists(os.path.join(root, '.hg')):
157 159 self._repo = hg.repository(r.ui, root)
158 160 else:
159 161 util.makedirs(root)
160 162 self._repo = hg.repository(r.ui, root, create=True)
161 163 self._repo._subparent = r
162 164 self._repo._subsource = state[0]
163 165
164 166 def dirty(self):
165 167 r = self._state[1]
166 168 if r == '':
167 169 return True
168 170 w = self._repo[None]
169 171 if w.p1() != self._repo[r]: # version checked out changed
170 172 return True
171 173 return w.dirty() # working directory changed
172 174
173 175 def commit(self, text, user, date):
176 self._repo.ui.debug("committing subrepo %s\n" % self._path)
174 177 n = self._repo.commit(text, user, date)
175 178 if not n:
176 179 return self._repo['.'].hex() # different version checked out
177 180 return node.hex(n)
178 181
179 182 def remove(self):
180 183 # we can't fully delete the repository as it may contain
181 184 # local-only history
182 185 self._repo.ui.note(_('removing subrepo %s\n') % self._path)
183 186 hg.clean(self._repo, node.nullid, False)
184 187
185 188 def _get(self, state):
186 189 source, revision = state
187 190 try:
188 191 self._repo.lookup(revision)
189 192 except error.RepoError:
190 193 self._repo._subsource = source
191 194 self._repo.ui.status(_('pulling subrepo %s\n') % self._path)
192 195 srcurl = _abssource(self._repo)
193 196 other = hg.repository(self._repo.ui, srcurl)
194 197 self._repo.pull(other)
195 198
196 199 def get(self, state):
197 200 self._get(state)
198 201 source, revision = state
202 self._repo.ui.debug("getting subrepo %s\n" % self._path)
199 203 hg.clean(self._repo, revision, False)
200 204
201 205 def merge(self, state):
202 206 self._get(state)
203 207 cur = self._repo['.']
204 208 dst = self._repo[state[1]]
205 209 if dst.ancestor(cur) == cur:
210 self._repo.ui.debug("updating subrepo %s\n" % self._path)
206 211 hg.update(self._repo, state[1])
207 212 else:
213 self._repo.ui.debug("merging subrepo %s\n" % self._path)
208 214 hg.merge(self._repo, state[1], remind=False)
209 215
210 216 def push(self, force):
211 217 # push subrepos depth-first for coherent ordering
212 218 c = self._repo['']
213 219 subs = c.substate # only repos that are committed
214 220 for s in sorted(subs):
215 221 c.sub(s).push(force)
216 222
217 223 self._repo.ui.status(_('pushing subrepo %s\n') % self._path)
218 224 dsturl = _abssource(self._repo, True)
219 225 other = hg.repository(self._repo.ui, dsturl)
220 226 self._repo.push(other, force)
General Comments 0
You need to be logged in to leave comments. Login now