3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2, incorporated herein by reference. |
6 # GNU General Public License version 2, incorporated herein by reference. |
7 |
7 |
8 import config, util, errno |
8 import errno, os |
|
9 import config, util, node, error |
|
10 localrepo = None |
|
11 |
|
12 nullstate = ('', '') |
9 |
13 |
10 def state(ctx): |
14 def state(ctx): |
11 p = config.config() |
15 p = config.config() |
12 def read(f, sections=None, remap=None): |
16 def read(f, sections=None, remap=None): |
13 if f in ctx: |
17 if f in ctx: |
31 state = {} |
35 state = {} |
32 for path, src in p[''].items(): |
36 for path, src in p[''].items(): |
33 state[path] = (src, rev.get(path, '')) |
37 state[path] = (src, rev.get(path, '')) |
34 |
38 |
35 return state |
39 return state |
|
40 |
|
41 def writestate(repo, state): |
|
42 repo.wwrite('.hgsubstate', |
|
43 ''.join(['%s %s\n' % (state[s][1], s) |
|
44 for s in sorted(state)]), '') |
|
45 |
|
46 def subrepo(ctx, path): |
|
47 # subrepo inherently violates our import layering rules |
|
48 # because it wants to make repo objects from deep inside the stack |
|
49 # so we manually delay the circular imports to not break |
|
50 # scripts that don't use our demand-loading |
|
51 global localrepo |
|
52 import localrepo as l |
|
53 localrepo = l |
|
54 |
|
55 state = ctx.substate.get(path, nullstate) |
|
56 if state[0].startswith('['): # future expansion |
|
57 raise error.Abort('unknown subrepo source %s' % state[0]) |
|
58 return hgsubrepo(ctx, path, state) |
|
59 |
|
60 class hgsubrepo(object): |
|
61 def __init__(self, ctx, path, state): |
|
62 self._parent = ctx |
|
63 self._path = path |
|
64 self._state = state |
|
65 r = ctx._repo |
|
66 root = r.wjoin(path) |
|
67 self._repo = localrepo.localrepository(r.ui, root) |
|
68 |
|
69 def dirty(self): |
|
70 r = self._state[1] |
|
71 if r == '': |
|
72 return True |
|
73 w = self._repo[None] |
|
74 if w.p1() != self._repo[r]: # version checked out changed |
|
75 return True |
|
76 return w.dirty() # working directory changed |
|
77 |
|
78 def commit(self, text, user, date): |
|
79 n = self._repo.commit(text, user, date) |
|
80 if not n: |
|
81 return self._repo['.'].hex() # different version checked out |
|
82 return node.hex(n) |