Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 11571:636554d58665 stable
subrepo: docstrings
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 15 Jul 2010 13:24:02 +0200 |
parents | 34e33d50c26b |
children | 324bad1dc230 |
comparison
equal
deleted
inserted
replaced
11562:efbc09fdefd8 | 11571:636554d58665 |
---|---|
11 hg = None | 11 hg = None |
12 | 12 |
13 nullstate = ('', '', 'empty') | 13 nullstate = ('', '', 'empty') |
14 | 14 |
15 def state(ctx): | 15 def state(ctx): |
16 """return a state dict, mapping subrepo paths configured in .hgsub | |
17 to tuple: (source from .hgsub, revision from .hgsubstate, kind | |
18 (key in types dict)) | |
19 """ | |
16 p = config.config() | 20 p = config.config() |
17 def read(f, sections=None, remap=None): | 21 def read(f, sections=None, remap=None): |
18 if f in ctx: | 22 if f in ctx: |
19 p.parse(f, ctx[f].data(), sections, remap, read) | 23 p.parse(f, ctx[f].data(), sections, remap, read) |
20 else: | 24 else: |
44 state[path] = (src.strip(), rev.get(path, ''), kind) | 48 state[path] = (src.strip(), rev.get(path, ''), kind) |
45 | 49 |
46 return state | 50 return state |
47 | 51 |
48 def writestate(repo, state): | 52 def writestate(repo, state): |
53 """rewrite .hgsubstate in (outer) repo with these subrepo states""" | |
49 repo.wwrite('.hgsubstate', | 54 repo.wwrite('.hgsubstate', |
50 ''.join(['%s %s\n' % (state[s][1], s) | 55 ''.join(['%s %s\n' % (state[s][1], s) |
51 for s in sorted(state)]), '') | 56 for s in sorted(state)]), '') |
52 | 57 |
53 def submerge(repo, wctx, mctx, actx): | 58 def submerge(repo, wctx, mctx, actx): |
54 # working context, merging context, ancestor context | 59 """delegated from merge.applyupdates: merging of .hgsubstate file |
60 in working context, merging context and ancestor context""" | |
55 if mctx == actx: # backwards? | 61 if mctx == actx: # backwards? |
56 actx = wctx.p1() | 62 actx = wctx.p1() |
57 s1 = wctx.substate | 63 s1 = wctx.substate |
58 s2 = mctx.substate | 64 s2 = mctx.substate |
59 sa = actx.substate | 65 sa = actx.substate |
129 | 135 |
130 # record merged .hgsubstate | 136 # record merged .hgsubstate |
131 writestate(repo, sm) | 137 writestate(repo, sm) |
132 | 138 |
133 def relpath(sub): | 139 def relpath(sub): |
140 """return path to this subrepo as seen from outermost repo""" | |
134 if not hasattr(sub, '_repo'): | 141 if not hasattr(sub, '_repo'): |
135 return sub._path | 142 return sub._path |
136 parent = sub._repo | 143 parent = sub._repo |
137 while hasattr(parent, '_subparent'): | 144 while hasattr(parent, '_subparent'): |
138 parent = parent._subparent | 145 parent = parent._subparent |
139 return sub._repo.root[len(parent.root)+1:] | 146 return sub._repo.root[len(parent.root)+1:] |
140 | 147 |
141 def _abssource(repo, push=False): | 148 def _abssource(repo, push=False): |
149 """return pull/push path of repo - either based on parent repo | |
150 .hgsub info or on the subrepos own config""" | |
142 if hasattr(repo, '_subparent'): | 151 if hasattr(repo, '_subparent'): |
143 source = repo._subsource | 152 source = repo._subsource |
144 if source.startswith('/') or '://' in source: | 153 if source.startswith('/') or '://' in source: |
145 return source | 154 return source |
146 parent = _abssource(repo._subparent, push) | 155 parent = _abssource(repo._subparent, push) |
156 if push and repo.ui.config('paths', 'default-push'): | 165 if push and repo.ui.config('paths', 'default-push'): |
157 return repo.ui.config('paths', 'default-push', repo.root) | 166 return repo.ui.config('paths', 'default-push', repo.root) |
158 return repo.ui.config('paths', 'default', repo.root) | 167 return repo.ui.config('paths', 'default', repo.root) |
159 | 168 |
160 def subrepo(ctx, path): | 169 def subrepo(ctx, path): |
170 """return instance of the right subrepo class for subrepo in path""" | |
161 # subrepo inherently violates our import layering rules | 171 # subrepo inherently violates our import layering rules |
162 # because it wants to make repo objects from deep inside the stack | 172 # because it wants to make repo objects from deep inside the stack |
163 # so we manually delay the circular imports to not break | 173 # so we manually delay the circular imports to not break |
164 # scripts that don't use our demand-loading | 174 # scripts that don't use our demand-loading |
165 global hg | 175 global hg |
182 # remove(self): remove the subrepo (should verify the dirstate | 192 # remove(self): remove the subrepo (should verify the dirstate |
183 # is not dirty first) | 193 # is not dirty first) |
184 # get(self, state): run whatever commands are needed to put the | 194 # get(self, state): run whatever commands are needed to put the |
185 # subrepo into this state | 195 # subrepo into this state |
186 # merge(self, state): merge currently-saved state with the new state. | 196 # merge(self, state): merge currently-saved state with the new state. |
187 # push(self, force): perform whatever action is analagous to 'hg push' | 197 # push(self, force): perform whatever action is analogous to 'hg push' |
188 # This may be a no-op on some systems. | 198 # This may be a no-op on some systems. |
189 | 199 |
190 class hgsubrepo(object): | 200 class hgsubrepo(object): |
191 def __init__(self, ctx, path, state): | 201 def __init__(self, ctx, path, state): |
192 self._path = path | 202 self._path = path |