Show More
@@ -27,8 +27,29 b' from .utils import stringutil' | |||||
27 |
|
27 | |||
28 | nullstate = (b'', b'', b'empty') |
|
28 | nullstate = (b'', b'', b'empty') | |
29 |
|
29 | |||
|
30 | if pycompat.TYPE_CHECKING: | |||
|
31 | from typing import ( | |||
|
32 | Any, | |||
|
33 | Dict, | |||
|
34 | List, | |||
|
35 | Optional, | |||
|
36 | Set, | |||
|
37 | Tuple, | |||
|
38 | ) | |||
|
39 | from . import ( | |||
|
40 | context, | |||
|
41 | localrepo, | |||
|
42 | match as matchmod, | |||
|
43 | scmutil, | |||
|
44 | subrepo, | |||
|
45 | ui as uimod, | |||
|
46 | ) | |||
|
47 | ||||
|
48 | Substate = Dict[bytes, Tuple[bytes, bytes, bytes]] | |||
|
49 | ||||
30 |
|
50 | |||
31 | def state(ctx, ui): |
|
51 | def state(ctx, ui): | |
|
52 | # type: (context.changectx, uimod.ui) -> Substate | |||
32 | """return a state dict, mapping subrepo paths configured in .hgsub |
|
53 | """return a state dict, mapping subrepo paths configured in .hgsub | |
33 | to tuple: (source from .hgsub, revision from .hgsubstate, kind |
|
54 | to tuple: (source from .hgsub, revision from .hgsubstate, kind | |
34 | (key in types dict)) |
|
55 | (key in types dict)) | |
@@ -84,6 +105,7 b' def state(ctx, ui):' | |||||
84 | raise |
|
105 | raise | |
85 |
|
106 | |||
86 | def remap(src): |
|
107 | def remap(src): | |
|
108 | # type: (bytes) -> bytes | |||
87 | for pattern, repl in p.items(b'subpaths'): |
|
109 | for pattern, repl in p.items(b'subpaths'): | |
88 | # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub |
|
110 | # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub | |
89 | # does a string decode. |
|
111 | # does a string decode. | |
@@ -105,7 +127,7 b' def state(ctx, ui):' | |||||
105 | return src |
|
127 | return src | |
106 |
|
128 | |||
107 | state = {} |
|
129 | state = {} | |
108 | for path, src in p.items(b''): |
|
130 | for path, src in p.items(b''): # type: bytes | |
109 | kind = b'hg' |
|
131 | kind = b'hg' | |
110 | if src.startswith(b'['): |
|
132 | if src.startswith(b'['): | |
111 | if b']' not in src: |
|
133 | if b']' not in src: | |
@@ -136,6 +158,7 b' def state(ctx, ui):' | |||||
136 |
|
158 | |||
137 |
|
159 | |||
138 | def writestate(repo, state): |
|
160 | def writestate(repo, state): | |
|
161 | # type: (localrepo.localrepository, Substate) -> None | |||
139 | """rewrite .hgsubstate in (outer) repo with these subrepo states""" |
|
162 | """rewrite .hgsubstate in (outer) repo with these subrepo states""" | |
140 | lines = [ |
|
163 | lines = [ | |
141 | b'%s %s\n' % (state[s][1], s) |
|
164 | b'%s %s\n' % (state[s][1], s) | |
@@ -146,6 +169,8 b' def writestate(repo, state):' | |||||
146 |
|
169 | |||
147 |
|
170 | |||
148 | def submerge(repo, wctx, mctx, actx, overwrite, labels=None): |
|
171 | def submerge(repo, wctx, mctx, actx, overwrite, labels=None): | |
|
172 | # type: (localrepo.localrepository, context.workingctx, context.changectx, context.changectx, bool, Optional[Any]) -> Substate | |||
|
173 | # TODO: type the `labels` arg | |||
149 | """delegated from merge.applyupdates: merging of .hgsubstate file |
|
174 | """delegated from merge.applyupdates: merging of .hgsubstate file | |
150 | in working context, merging context and ancestor context""" |
|
175 | in working context, merging context and ancestor context""" | |
151 | if mctx == actx: # backwards? |
|
176 | if mctx == actx: # backwards? | |
@@ -285,6 +310,7 b' def submerge(repo, wctx, mctx, actx, ove' | |||||
285 |
|
310 | |||
286 |
|
311 | |||
287 | def precommit(ui, wctx, status, match, force=False): |
|
312 | def precommit(ui, wctx, status, match, force=False): | |
|
313 | # type: (uimod.ui, context.workingcommitctx, scmutil.status, matchmod.basematcher, bool) -> Tuple[List[bytes], Set[bytes], Substate] | |||
288 | """Calculate .hgsubstate changes that should be applied before committing |
|
314 | """Calculate .hgsubstate changes that should be applied before committing | |
289 |
|
315 | |||
290 | Returns (subs, commitsubs, newstate) where |
|
316 | Returns (subs, commitsubs, newstate) where | |
@@ -355,6 +381,7 b' def precommit(ui, wctx, status, match, f' | |||||
355 |
|
381 | |||
356 |
|
382 | |||
357 | def reporelpath(repo): |
|
383 | def reporelpath(repo): | |
|
384 | # type: (localrepo.localrepository) -> bytes | |||
358 | """return path to this (sub)repo as seen from outermost repo""" |
|
385 | """return path to this (sub)repo as seen from outermost repo""" | |
359 | parent = repo |
|
386 | parent = repo | |
360 | while util.safehasattr(parent, b'_subparent'): |
|
387 | while util.safehasattr(parent, b'_subparent'): | |
@@ -363,11 +390,13 b' def reporelpath(repo):' | |||||
363 |
|
390 | |||
364 |
|
391 | |||
365 | def subrelpath(sub): |
|
392 | def subrelpath(sub): | |
|
393 | # type: (subrepo.abstractsubrepo) -> bytes | |||
366 | """return path to this subrepo as seen from outermost repo""" |
|
394 | """return path to this subrepo as seen from outermost repo""" | |
367 | return sub._relpath |
|
395 | return sub._relpath | |
368 |
|
396 | |||
369 |
|
397 | |||
370 | def _abssource(repo, push=False, abort=True): |
|
398 | def _abssource(repo, push=False, abort=True): | |
|
399 | # type: (localrepo.localrepository, bool, bool) -> Optional[bytes] | |||
371 | """return pull/push path of repo - either based on parent repo .hgsub info |
|
400 | """return pull/push path of repo - either based on parent repo .hgsub info | |
372 | or on the top repo config. Abort or return None if no source found.""" |
|
401 | or on the top repo config. Abort or return None if no source found.""" | |
373 | if util.safehasattr(repo, b'_subparent'): |
|
402 | if util.safehasattr(repo, b'_subparent'): | |
@@ -416,6 +445,7 b' def _abssource(repo, push=False, abort=T' | |||||
416 |
|
445 | |||
417 |
|
446 | |||
418 | def newcommitphase(ui, ctx): |
|
447 | def newcommitphase(ui, ctx): | |
|
448 | # type: (uimod.ui, context.changectx) -> int | |||
419 | commitphase = phases.newcommitphase(ui) |
|
449 | commitphase = phases.newcommitphase(ui) | |
420 | substate = getattr(ctx, "substate", None) |
|
450 | substate = getattr(ctx, "substate", None) | |
421 | if not substate: |
|
451 | if not substate: |
General Comments 0
You need to be logged in to leave comments.
Login now