Show More
@@ -1,193 +1,192 b'' | |||||
1 | # subrepo.py - sub-repository handling for Mercurial |
|
1 | # subrepo.py - sub-repository handling for Mercurial | |
2 | # |
|
2 | # | |
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 errno, os |
|
8 | import errno, os | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import config, util, node, error |
|
10 | import config, util, node, error | |
11 |
|
|
11 | hg = None | |
12 |
|
12 | |||
13 | nullstate = ('', '') |
|
13 | nullstate = ('', '') | |
14 |
|
14 | |||
15 | def state(ctx): |
|
15 | def state(ctx): | |
16 | p = config.config() |
|
16 | p = config.config() | |
17 | def read(f, sections=None, remap=None): |
|
17 | def read(f, sections=None, remap=None): | |
18 | if f in ctx: |
|
18 | if f in ctx: | |
19 | try: |
|
19 | try: | |
20 | p.parse(f, ctx[f].data(), sections, remap) |
|
20 | p.parse(f, ctx[f].data(), sections, remap) | |
21 | except IOError, err: |
|
21 | except IOError, err: | |
22 | if err.errno != errno.ENOENT: |
|
22 | if err.errno != errno.ENOENT: | |
23 | raise |
|
23 | raise | |
24 | read('.hgsub') |
|
24 | read('.hgsub') | |
25 |
|
25 | |||
26 | rev = {} |
|
26 | rev = {} | |
27 | if '.hgsubstate' in ctx: |
|
27 | if '.hgsubstate' in ctx: | |
28 | try: |
|
28 | try: | |
29 | for l in ctx['.hgsubstate'].data().splitlines(): |
|
29 | for l in ctx['.hgsubstate'].data().splitlines(): | |
30 | revision, path = l.split() |
|
30 | revision, path = l.split() | |
31 | rev[path] = revision |
|
31 | rev[path] = revision | |
32 | except IOError, err: |
|
32 | except IOError, err: | |
33 | if err.errno != errno.ENOENT: |
|
33 | if err.errno != errno.ENOENT: | |
34 | raise |
|
34 | raise | |
35 |
|
35 | |||
36 | state = {} |
|
36 | state = {} | |
37 | for path, src in p[''].items(): |
|
37 | for path, src in p[''].items(): | |
38 | state[path] = (src, rev.get(path, '')) |
|
38 | state[path] = (src, rev.get(path, '')) | |
39 |
|
39 | |||
40 | return state |
|
40 | return state | |
41 |
|
41 | |||
42 | def writestate(repo, state): |
|
42 | def writestate(repo, state): | |
43 | repo.wwrite('.hgsubstate', |
|
43 | repo.wwrite('.hgsubstate', | |
44 | ''.join(['%s %s\n' % (state[s][1], s) |
|
44 | ''.join(['%s %s\n' % (state[s][1], s) | |
45 | for s in sorted(state)]), '') |
|
45 | for s in sorted(state)]), '') | |
46 |
|
46 | |||
47 | def submerge(repo, wctx, mctx, actx): |
|
47 | def submerge(repo, wctx, mctx, actx): | |
48 | if mctx == actx: # backwards? |
|
48 | if mctx == actx: # backwards? | |
49 | actx = wctx.p1() |
|
49 | actx = wctx.p1() | |
50 | s1 = wctx.substate |
|
50 | s1 = wctx.substate | |
51 | s2 = mctx.substate |
|
51 | s2 = mctx.substate | |
52 | sa = actx.substate |
|
52 | sa = actx.substate | |
53 | sm = {} |
|
53 | sm = {} | |
54 |
|
54 | |||
55 | for s, l in s1.items(): |
|
55 | for s, l in s1.items(): | |
56 | a = sa.get(s, nullstate) |
|
56 | a = sa.get(s, nullstate) | |
57 | if s in s2: |
|
57 | if s in s2: | |
58 | r = s2[s] |
|
58 | r = s2[s] | |
59 | if l == r or r == a: # no change or local is newer |
|
59 | if l == r or r == a: # no change or local is newer | |
60 | sm[s] = l |
|
60 | sm[s] = l | |
61 | continue |
|
61 | continue | |
62 | elif l == a: # other side changed |
|
62 | elif l == a: # other side changed | |
63 | wctx.sub(s).get(r) |
|
63 | wctx.sub(s).get(r) | |
64 | sm[s] = r |
|
64 | sm[s] = r | |
65 | elif l[0] != r[0]: # sources differ |
|
65 | elif l[0] != r[0]: # sources differ | |
66 | if repo.ui.promptchoice( |
|
66 | if repo.ui.promptchoice( | |
67 | _(' subrepository sources for %s differ\n' |
|
67 | _(' subrepository sources for %s differ\n' | |
68 | 'use (l)ocal source (%s) or (r)emote source (%s)?') |
|
68 | 'use (l)ocal source (%s) or (r)emote source (%s)?') | |
69 | % (s, l[0], r[0]), |
|
69 | % (s, l[0], r[0]), | |
70 | (_('&Local'), _('&Remote')), 0): |
|
70 | (_('&Local'), _('&Remote')), 0): | |
71 | wctx.sub(s).get(r) |
|
71 | wctx.sub(s).get(r) | |
72 | sm[s] = r |
|
72 | sm[s] = r | |
73 | elif l[1] == a[1]: # local side is unchanged |
|
73 | elif l[1] == a[1]: # local side is unchanged | |
74 | wctx.sub(s).get(r) |
|
74 | wctx.sub(s).get(r) | |
75 | sm[s] = r |
|
75 | sm[s] = r | |
76 | else: |
|
76 | else: | |
77 | wctx.sub(s).merge(r) |
|
77 | wctx.sub(s).merge(r) | |
78 | sm[s] = l |
|
78 | sm[s] = l | |
79 | elif l == a: # remote removed, local unchanged |
|
79 | elif l == a: # remote removed, local unchanged | |
80 | wctx.sub(s).remove() |
|
80 | wctx.sub(s).remove() | |
81 | else: |
|
81 | else: | |
82 | if repo.ui.promptchoice( |
|
82 | if repo.ui.promptchoice( | |
83 | _(' local changed subrepository %s which remote removed\n' |
|
83 | _(' local changed subrepository %s which remote removed\n' | |
84 | 'use (c)hanged version or (d)elete?') % s, |
|
84 | 'use (c)hanged version or (d)elete?') % s, | |
85 | (_('&Changed'), _('&Delete')), 0): |
|
85 | (_('&Changed'), _('&Delete')), 0): | |
86 | wctx.sub(s).remove() |
|
86 | wctx.sub(s).remove() | |
87 |
|
87 | |||
88 | for s, r in s2.items(): |
|
88 | for s, r in s2.items(): | |
89 | if s in s1: |
|
89 | if s in s1: | |
90 | continue |
|
90 | continue | |
91 | elif s not in sa: |
|
91 | elif s not in sa: | |
92 | wctx.sub(s).get(r) |
|
92 | wctx.sub(s).get(r) | |
93 | sm[s] = r |
|
93 | sm[s] = r | |
94 | elif r != sa[s]: |
|
94 | elif r != sa[s]: | |
95 | if repo.ui.promptchoice( |
|
95 | if repo.ui.promptchoice( | |
96 | _(' remote changed subrepository %s which local removed\n' |
|
96 | _(' remote changed subrepository %s which local removed\n' | |
97 | 'use (c)hanged version or (d)elete?') % s, |
|
97 | 'use (c)hanged version or (d)elete?') % s, | |
98 | (_('&Changed'), _('&Delete')), 0) == 0: |
|
98 | (_('&Changed'), _('&Delete')), 0) == 0: | |
99 | wctx.sub(s).get(r) |
|
99 | wctx.sub(s).get(r) | |
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, push=False): |
|
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'): |
|
111 | if push and repo.ui.config('paths', 'default-push'): | |
112 | return repo.ui.config('paths', 'default-push', repo.root) |
|
112 | return repo.ui.config('paths', 'default-push', repo.root) | |
113 | return repo.ui.config('paths', 'default', repo.root) |
|
113 | return repo.ui.config('paths', 'default', repo.root) | |
114 |
|
114 | |||
115 | def subrepo(ctx, path): |
|
115 | def subrepo(ctx, path): | |
116 | # subrepo inherently violates our import layering rules |
|
116 | # subrepo inherently violates our import layering rules | |
117 | # 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 | |
118 | # so we manually delay the circular imports to not break |
|
118 | # so we manually delay the circular imports to not break | |
119 | # scripts that don't use our demand-loading |
|
119 | # scripts that don't use our demand-loading | |
120 |
global |
|
120 | global hg | |
121 |
import |
|
121 | import hg as h | |
122 | localrepo = l |
|
|||
123 | hg = h |
|
122 | hg = h | |
124 |
|
123 | |||
125 | util.path_auditor(ctx._repo.root)(path) |
|
124 | util.path_auditor(ctx._repo.root)(path) | |
126 | state = ctx.substate.get(path, nullstate) |
|
125 | state = ctx.substate.get(path, nullstate) | |
127 | if state[0].startswith('['): # future expansion |
|
126 | if state[0].startswith('['): # future expansion | |
128 | raise error.Abort('unknown subrepo source %s' % state[0]) |
|
127 | raise error.Abort('unknown subrepo source %s' % state[0]) | |
129 | return hgsubrepo(ctx, path, state) |
|
128 | return hgsubrepo(ctx, path, state) | |
130 |
|
129 | |||
131 | class hgsubrepo(object): |
|
130 | class hgsubrepo(object): | |
132 | def __init__(self, ctx, path, state): |
|
131 | def __init__(self, ctx, path, state): | |
133 | self._path = path |
|
132 | self._path = path | |
134 | self._state = state |
|
133 | self._state = state | |
135 | r = ctx._repo |
|
134 | r = ctx._repo | |
136 | root = r.wjoin(path) |
|
135 | root = r.wjoin(path) | |
137 | if os.path.exists(os.path.join(root, '.hg')): |
|
136 | if os.path.exists(os.path.join(root, '.hg')): | |
138 |
self._repo = |
|
137 | self._repo = hg.repository(r.ui, root) | |
139 | else: |
|
138 | else: | |
140 | util.makedirs(root) |
|
139 | util.makedirs(root) | |
141 |
self._repo = |
|
140 | self._repo = hg.repository(r.ui, root, create=True) | |
142 | self._repo._subparent = r |
|
141 | self._repo._subparent = r | |
143 | self._repo._subsource = state[0] |
|
142 | self._repo._subsource = state[0] | |
144 |
|
143 | |||
145 | def dirty(self): |
|
144 | def dirty(self): | |
146 | r = self._state[1] |
|
145 | r = self._state[1] | |
147 | if r == '': |
|
146 | if r == '': | |
148 | return True |
|
147 | return True | |
149 | w = self._repo[None] |
|
148 | w = self._repo[None] | |
150 | if w.p1() != self._repo[r]: # version checked out changed |
|
149 | if w.p1() != self._repo[r]: # version checked out changed | |
151 | return True |
|
150 | return True | |
152 | return w.dirty() # working directory changed |
|
151 | return w.dirty() # working directory changed | |
153 |
|
152 | |||
154 | def commit(self, text, user, date): |
|
153 | def commit(self, text, user, date): | |
155 | n = self._repo.commit(text, user, date) |
|
154 | n = self._repo.commit(text, user, date) | |
156 | if not n: |
|
155 | if not n: | |
157 | return self._repo['.'].hex() # different version checked out |
|
156 | return self._repo['.'].hex() # different version checked out | |
158 | return node.hex(n) |
|
157 | return node.hex(n) | |
159 |
|
158 | |||
160 | def remove(self): |
|
159 | def remove(self): | |
161 | # we can't fully delete the repository as it may contain |
|
160 | # we can't fully delete the repository as it may contain | |
162 | # local-only history |
|
161 | # local-only history | |
163 | self._repo.ui.note(_('removing subrepo %s\n') % self._path) |
|
162 | self._repo.ui.note(_('removing subrepo %s\n') % self._path) | |
164 | hg.clean(self._repo, node.nullid, False) |
|
163 | hg.clean(self._repo, node.nullid, False) | |
165 |
|
164 | |||
166 | def get(self, state): |
|
165 | def get(self, state): | |
167 | source, revision = state |
|
166 | source, revision = state | |
168 | try: |
|
167 | try: | |
169 | self._repo.lookup(revision) |
|
168 | self._repo.lookup(revision) | |
170 | except error.RepoError: |
|
169 | except error.RepoError: | |
171 | self._repo._subsource = source |
|
170 | self._repo._subsource = source | |
172 | self._repo.ui.status(_('pulling subrepo %s\n') % self._path) |
|
171 | self._repo.ui.status(_('pulling subrepo %s\n') % self._path) | |
173 | srcurl = _abssource(self._repo) |
|
172 | srcurl = _abssource(self._repo) | |
174 | other = hg.repository(self._repo.ui, srcurl) |
|
173 | other = hg.repository(self._repo.ui, srcurl) | |
175 | self._repo.pull(other) |
|
174 | self._repo.pull(other) | |
176 |
|
175 | |||
177 | hg.clean(self._repo, revision, False) |
|
176 | hg.clean(self._repo, revision, False) | |
178 |
|
177 | |||
179 | def merge(self, state): |
|
178 | def merge(self, state): | |
180 | hg.merge(self._repo, state[1], remind=False) |
|
179 | hg.merge(self._repo, state[1], remind=False) | |
181 |
|
180 | |||
182 | def push(self, force): |
|
181 | def push(self, force): | |
183 | # push subrepos depth-first for coherent ordering |
|
182 | # push subrepos depth-first for coherent ordering | |
184 | c = self._repo[''] |
|
183 | c = self._repo[''] | |
185 | subs = c.substate # only repos that are committed |
|
184 | subs = c.substate # only repos that are committed | |
186 | for s in sorted(subs): |
|
185 | for s in sorted(subs): | |
187 | c.sub(s).push(force) |
|
186 | c.sub(s).push(force) | |
188 |
|
187 | |||
189 | self._repo.ui.status(_('pushing subrepo %s\n') % self._path) |
|
188 | self._repo.ui.status(_('pushing subrepo %s\n') % self._path) | |
190 | dsturl = _abssource(self._repo, True) |
|
189 | dsturl = _abssource(self._repo, True) | |
191 | other = hg.repository(self._repo.ui, dsturl) |
|
190 | other = hg.repository(self._repo.ui, dsturl) | |
192 | self._repo.push(other, force) |
|
191 | self._repo.push(other, force) | |
193 |
|
192 |
General Comments 0
You need to be logged in to leave comments.
Login now