comparison mercurial/subrepo.py @ 10177:5ca0d220ae21

subrepo: add table-based dispatch for subrepo types
author Augie Fackler <durin42@gmail.com>
date Thu, 31 Dec 2009 17:10:03 -0600
parents fc32b2fc468e
children cd477be6f2fc
comparison
equal deleted inserted replaced
10176:24ce8f0c0a39 10177:5ca0d220ae21
8 import errno, os 8 import errno, os
9 from i18n import _ 9 from i18n import _
10 import config, util, node, error 10 import config, util, node, error
11 hg = None 11 hg = None
12 12
13 nullstate = ('', '') 13 nullstate = ('', '', 'empty')
14 14
15 def state(ctx): 15 def state(ctx):
16 p = config.config() 16 p = config.config()
17 def read(f, sections=None, remap=None): 17 def read(f, sections=None, remap=None):
18 if f in ctx: 18 if f in ctx:
33 if err.errno != errno.ENOENT: 33 if err.errno != errno.ENOENT:
34 raise 34 raise
35 35
36 state = {} 36 state = {}
37 for path, src in p[''].items(): 37 for path, src in p[''].items():
38 state[path] = (src, rev.get(path, '')) 38 kind = 'hg'
39 if src.startswith('['):
40 if ']' not in src:
41 raise util.Abort(_('missing ] in subrepo source'))
42 kind, src = src.split(']', 1)
43 kind = kind[1:]
44 state[path] = (src, rev.get(path, ''), kind)
39 45
40 return state 46 return state
41 47
42 def writestate(repo, state): 48 def writestate(repo, state):
43 repo.wwrite('.hgsubstate', 49 repo.wwrite('.hgsubstate',
55 61
56 repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx)) 62 repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx))
57 63
58 def debug(s, msg, r=""): 64 def debug(s, msg, r=""):
59 if r: 65 if r:
60 r = "%s:%s" % r 66 r = "%s:%s:%s" % r
61 repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r)) 67 repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r))
62 68
63 for s, l in s1.items(): 69 for s, l in s1.items():
64 if wctx != actx and wctx.sub(s).dirty(): 70 if wctx != actx and wctx.sub(s).dirty():
65 l = (l[0], l[1] + "+") 71 l = (l[0], l[1] + "+")
144 import hg as h 150 import hg as h
145 hg = h 151 hg = h
146 152
147 util.path_auditor(ctx._repo.root)(path) 153 util.path_auditor(ctx._repo.root)(path)
148 state = ctx.substate.get(path, nullstate) 154 state = ctx.substate.get(path, nullstate)
149 if state[0].startswith('['): # future expansion 155 if state[2] not in types:
150 raise error.Abort('unknown subrepo source %s' % state[0]) 156 raise util.Abort(_('unknown subrepo type %s') % t)
151 return hgsubrepo(ctx, path, state) 157 return types[state[2]](ctx, path, state[:2])
152 158
153 # subrepo classes need to implement the following methods: 159 # subrepo classes need to implement the following methods:
154 # __init__(self, ctx, path, state) 160 # __init__(self, ctx, path, state)
155 # dirty(self): returns true if the dirstate of the subrepo 161 # dirty(self): returns true if the dirstate of the subrepo
156 # does not match current stored state 162 # does not match current stored state
203 # local-only history 209 # local-only history
204 self._repo.ui.note(_('removing subrepo %s\n') % self._path) 210 self._repo.ui.note(_('removing subrepo %s\n') % self._path)
205 hg.clean(self._repo, node.nullid, False) 211 hg.clean(self._repo, node.nullid, False)
206 212
207 def _get(self, state): 213 def _get(self, state):
208 source, revision = state 214 source, revision, kind = state
209 try: 215 try:
210 self._repo.lookup(revision) 216 self._repo.lookup(revision)
211 except error.RepoError: 217 except error.RepoError:
212 self._repo._subsource = source 218 self._repo._subsource = source
213 self._repo.ui.status(_('pulling subrepo %s\n') % self._path) 219 self._repo.ui.status(_('pulling subrepo %s\n') % self._path)
215 other = hg.repository(self._repo.ui, srcurl) 221 other = hg.repository(self._repo.ui, srcurl)
216 self._repo.pull(other) 222 self._repo.pull(other)
217 223
218 def get(self, state): 224 def get(self, state):
219 self._get(state) 225 self._get(state)
220 source, revision = state 226 source, revision, kind = state
221 self._repo.ui.debug("getting subrepo %s\n" % self._path) 227 self._repo.ui.debug("getting subrepo %s\n" % self._path)
222 hg.clean(self._repo, revision, False) 228 hg.clean(self._repo, revision, False)
223 229
224 def merge(self, state): 230 def merge(self, state):
225 self._get(state) 231 self._get(state)
241 247
242 self._repo.ui.status(_('pushing subrepo %s\n') % self._path) 248 self._repo.ui.status(_('pushing subrepo %s\n') % self._path)
243 dsturl = _abssource(self._repo, True) 249 dsturl = _abssource(self._repo, True)
244 other = hg.repository(self._repo.ui, dsturl) 250 other = hg.repository(self._repo.ui, dsturl)
245 self._repo.push(other, force) 251 self._repo.push(other, force)
252
253 types = {
254 'hg': hgsubrepo,
255 }