comparison mercurial/subrepo.py @ 8815:e87b0fc4750b

subrepo: basic push support
author Matt Mackall <mpm@selenic.com>
date Mon, 15 Jun 2009 02:46:20 -0500
parents ab668c92a036
children 105343f9f744
comparison
equal deleted inserted replaced
8814:ab668c92a036 8815:e87b0fc4750b
100 sm[s] = r 100 sm[s] = r
101 101
102 # record merged .hgsubstate 102 # record merged .hgsubstate
103 writestate(repo, sm) 103 writestate(repo, sm)
104 104
105 def _abssource(repo): 105 def _abssource(repo, push=False):
106 if hasattr(repo, '_subparent'): 106 if hasattr(repo, '_subparent'):
107 source = repo._subsource 107 source = repo._subsource
108 if source.startswith('/') or '://' in source: 108 if source.startswith('/') or '://' in source:
109 return source 109 return source
110 return os.path.join(_abssource(repo._subparent), repo._subsource) 110 return os.path.join(_abssource(repo._subparent), repo._subsource)
111 if push and repo.ui.config('paths', 'default-push'):
112 return repo.ui.config('paths', 'default-push', repo.root)
111 return repo.ui.config('paths', 'default', repo.root) 113 return repo.ui.config('paths', 'default', repo.root)
112 114
113 def subrepo(ctx, path): 115 def subrepo(ctx, path):
114 # subrepo inherently violates our import layering rules 116 # subrepo inherently violates our import layering rules
115 # because it wants to make repo objects from deep inside the stack 117 # because it wants to make repo objects from deep inside the stack
125 raise error.Abort('unknown subrepo source %s' % state[0]) 127 raise error.Abort('unknown subrepo source %s' % state[0])
126 return hgsubrepo(ctx, path, state) 128 return hgsubrepo(ctx, path, state)
127 129
128 class hgsubrepo(object): 130 class hgsubrepo(object):
129 def __init__(self, ctx, path, state): 131 def __init__(self, ctx, path, state):
130 self._parent = ctx
131 self._path = path 132 self._path = path
132 self._state = state 133 self._state = state
133 r = ctx._repo 134 r = ctx._repo
134 root = r.wjoin(path) 135 root = r.wjoin(path)
135 if os.path.exists(os.path.join(root, '.hg')): 136 if os.path.exists(os.path.join(root, '.hg')):
174 175
175 hg.clean(self._repo, revision, False) 176 hg.clean(self._repo, revision, False)
176 177
177 def merge(self, state): 178 def merge(self, state):
178 hg.merge(self._repo, state[1], remind=False) 179 hg.merge(self._repo, state[1], remind=False)
180
181 def push(self, force):
182 # push subrepos depth-first for coherent ordering
183 c = self._repo['']
184 subs = c.substate # only repos that are committed
185 for s in sorted(subs):
186 c.sub(s).push(force)
187
188 self._repo.ui.status(_('pushing subrepo %s\n') % self._path)
189 dsturl = _abssource(self._repo, True)
190 other = hg.repository(self._repo.ui, dsturl)
191 self._repo.push(other, force)
192