mercurial/subrepo.py
changeset 11572 324bad1dc230
parent 11560 ea2cdee9a1fe
parent 11571 636554d58665
child 11775 a8614c5a5e9a
equal deleted inserted replaced
11570:2d88369a27bf 11572:324bad1dc230
    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
   205     def merge(self, state):
   215     def merge(self, state):
   206         """merge currently-saved state with the new state."""
   216         """merge currently-saved state with the new state."""
   207         raise NotImplementedError
   217         raise NotImplementedError
   208 
   218 
   209     def push(self, force):
   219     def push(self, force):
   210         """perform whatever action is analagous to 'hg push'
   220         """perform whatever action is analogous to 'hg push'
   211 
   221 
   212         This may be a no-op on some systems.
   222         This may be a no-op on some systems.
   213         """
   223         """
   214         raise NotImplementedError
   224         raise NotImplementedError
   215 
   225