Show More
@@ -1,942 +1,945 b'' | |||||
1 | # merge.py - directory-level update/merge handling for Mercurial |
|
1 | # merge.py - directory-level update/merge 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 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | import struct |
|
8 | import struct | |
9 |
|
9 | |||
10 | from node import nullid, nullrev, hex, bin |
|
10 | from node import nullid, nullrev, hex, bin | |
11 | from i18n import _ |
|
11 | from i18n import _ | |
12 | from mercurial import obsolete |
|
12 | from mercurial import obsolete | |
13 | import error, util, filemerge, copies, subrepo, worker, dicthelpers |
|
13 | import error, util, filemerge, copies, subrepo, worker, dicthelpers | |
14 | import errno, os, shutil |
|
14 | import errno, os, shutil | |
15 |
|
15 | |||
16 | _pack = struct.pack |
|
16 | _pack = struct.pack | |
17 | _unpack = struct.unpack |
|
17 | _unpack = struct.unpack | |
18 |
|
18 | |||
19 | def _droponode(data): |
|
19 | def _droponode(data): | |
20 | # used for compatibility for v1 |
|
20 | # used for compatibility for v1 | |
21 | bits = data.split("\0") |
|
21 | bits = data.split("\0") | |
22 | bits = bits[:-2] + bits[-1:] |
|
22 | bits = bits[:-2] + bits[-1:] | |
23 | return "\0".join(bits) |
|
23 | return "\0".join(bits) | |
24 |
|
24 | |||
25 | class mergestate(object): |
|
25 | class mergestate(object): | |
26 | '''track 3-way merge state of individual files |
|
26 | '''track 3-way merge state of individual files | |
27 |
|
27 | |||
28 | it is stored on disk when needed. Two file are used, one with an old |
|
28 | it is stored on disk when needed. Two file are used, one with an old | |
29 | format, one with a new format. Both contains similar data, but the new |
|
29 | format, one with a new format. Both contains similar data, but the new | |
30 | format can store new kind of field. |
|
30 | format can store new kind of field. | |
31 |
|
31 | |||
32 | Current new format is a list of arbitrary record of the form: |
|
32 | Current new format is a list of arbitrary record of the form: | |
33 |
|
33 | |||
34 | [type][length][content] |
|
34 | [type][length][content] | |
35 |
|
35 | |||
36 | Type is a single character, length is a 4 bytes integer, content is an |
|
36 | Type is a single character, length is a 4 bytes integer, content is an | |
37 | arbitrary suites of bytes of length `length`. |
|
37 | arbitrary suites of bytes of length `length`. | |
38 |
|
38 | |||
39 | Type should be a letter. Capital letter are mandatory record, Mercurial |
|
39 | Type should be a letter. Capital letter are mandatory record, Mercurial | |
40 | should abort if they are unknown. lower case record can be safely ignored. |
|
40 | should abort if they are unknown. lower case record can be safely ignored. | |
41 |
|
41 | |||
42 | Currently known record: |
|
42 | Currently known record: | |
43 |
|
43 | |||
44 | L: the node of the "local" part of the merge (hexified version) |
|
44 | L: the node of the "local" part of the merge (hexified version) | |
45 | O: the node of the "other" part of the merge (hexified version) |
|
45 | O: the node of the "other" part of the merge (hexified version) | |
46 | F: a file to be merged entry |
|
46 | F: a file to be merged entry | |
47 | ''' |
|
47 | ''' | |
48 | statepathv1 = "merge/state" |
|
48 | statepathv1 = "merge/state" | |
49 | statepathv2 = "merge/state2" |
|
49 | statepathv2 = "merge/state2" | |
50 | def __init__(self, repo): |
|
50 | def __init__(self, repo): | |
51 | self._repo = repo |
|
51 | self._repo = repo | |
52 | self._dirty = False |
|
52 | self._dirty = False | |
53 | self._read() |
|
53 | self._read() | |
54 | def reset(self, node=None, other=None): |
|
54 | def reset(self, node=None, other=None): | |
55 | self._state = {} |
|
55 | self._state = {} | |
56 | if node: |
|
56 | if node: | |
57 | self._local = node |
|
57 | self._local = node | |
58 | self._other = other |
|
58 | self._other = other | |
59 | shutil.rmtree(self._repo.join("merge"), True) |
|
59 | shutil.rmtree(self._repo.join("merge"), True) | |
60 | self._dirty = False |
|
60 | self._dirty = False | |
61 | def _read(self): |
|
61 | def _read(self): | |
62 | self._state = {} |
|
62 | self._state = {} | |
63 | records = self._readrecords() |
|
63 | records = self._readrecords() | |
64 | for rtype, record in records: |
|
64 | for rtype, record in records: | |
65 | if rtype == 'L': |
|
65 | if rtype == 'L': | |
66 | self._local = bin(record) |
|
66 | self._local = bin(record) | |
67 | elif rtype == 'O': |
|
67 | elif rtype == 'O': | |
68 | self._other = bin(record) |
|
68 | self._other = bin(record) | |
69 | elif rtype == "F": |
|
69 | elif rtype == "F": | |
70 | bits = record.split("\0") |
|
70 | bits = record.split("\0") | |
71 | self._state[bits[0]] = bits[1:] |
|
71 | self._state[bits[0]] = bits[1:] | |
72 | elif not rtype.islower(): |
|
72 | elif not rtype.islower(): | |
73 | raise util.Abort(_('unsupported merge state record:' |
|
73 | raise util.Abort(_('unsupported merge state record:' | |
74 | % rtype)) |
|
74 | % rtype)) | |
75 | self._dirty = False |
|
75 | self._dirty = False | |
76 | def _readrecords(self): |
|
76 | def _readrecords(self): | |
77 | v1records = self._readrecordsv1() |
|
77 | v1records = self._readrecordsv1() | |
78 | v2records = self._readrecordsv2() |
|
78 | v2records = self._readrecordsv2() | |
79 | oldv2 = set() # old format version of v2 record |
|
79 | oldv2 = set() # old format version of v2 record | |
80 | for rec in v2records: |
|
80 | for rec in v2records: | |
81 | if rec[0] == 'L': |
|
81 | if rec[0] == 'L': | |
82 | oldv2.add(rec) |
|
82 | oldv2.add(rec) | |
83 | elif rec[0] == 'F': |
|
83 | elif rec[0] == 'F': | |
84 | # drop the onode data (not contained in v1) |
|
84 | # drop the onode data (not contained in v1) | |
85 | oldv2.add(('F', _droponode(rec[1]))) |
|
85 | oldv2.add(('F', _droponode(rec[1]))) | |
86 | for rec in v1records: |
|
86 | for rec in v1records: | |
87 | if rec not in oldv2: |
|
87 | if rec not in oldv2: | |
88 | # v1 file is newer than v2 file, use it |
|
88 | # v1 file is newer than v2 file, use it | |
89 | # we have to infer the "other" changeset of the merge |
|
89 | # we have to infer the "other" changeset of the merge | |
90 | # we cannot do better than that with v1 of the format |
|
90 | # we cannot do better than that with v1 of the format | |
91 | mctx = self._repo[None].parents()[-1] |
|
91 | mctx = self._repo[None].parents()[-1] | |
92 | v1records.append(('O', mctx.hex())) |
|
92 | v1records.append(('O', mctx.hex())) | |
93 | # add place holder "other" file node information |
|
93 | # add place holder "other" file node information | |
94 | # nobody is using it yet so we do no need to fetch the data |
|
94 | # nobody is using it yet so we do no need to fetch the data | |
95 | # if mctx was wrong `mctx[bits[-2]]` may fails. |
|
95 | # if mctx was wrong `mctx[bits[-2]]` may fails. | |
96 | for idx, r in enumerate(v1records): |
|
96 | for idx, r in enumerate(v1records): | |
97 | if r[0] == 'F': |
|
97 | if r[0] == 'F': | |
98 | bits = r[1].split("\0") |
|
98 | bits = r[1].split("\0") | |
99 | bits.insert(-2, '') |
|
99 | bits.insert(-2, '') | |
100 | v1records[idx] = (r[0], "\0".join(bits)) |
|
100 | v1records[idx] = (r[0], "\0".join(bits)) | |
101 | return v1records |
|
101 | return v1records | |
102 | else: |
|
102 | else: | |
103 | return v2records |
|
103 | return v2records | |
104 | def _readrecordsv1(self): |
|
104 | def _readrecordsv1(self): | |
105 | records = [] |
|
105 | records = [] | |
106 | try: |
|
106 | try: | |
107 | f = self._repo.opener(self.statepathv1) |
|
107 | f = self._repo.opener(self.statepathv1) | |
108 | for i, l in enumerate(f): |
|
108 | for i, l in enumerate(f): | |
109 | if i == 0: |
|
109 | if i == 0: | |
110 | records.append(('L', l[:-1])) |
|
110 | records.append(('L', l[:-1])) | |
111 | else: |
|
111 | else: | |
112 | records.append(('F', l[:-1])) |
|
112 | records.append(('F', l[:-1])) | |
113 | f.close() |
|
113 | f.close() | |
114 | except IOError, err: |
|
114 | except IOError, err: | |
115 | if err.errno != errno.ENOENT: |
|
115 | if err.errno != errno.ENOENT: | |
116 | raise |
|
116 | raise | |
117 | return records |
|
117 | return records | |
118 | def _readrecordsv2(self): |
|
118 | def _readrecordsv2(self): | |
119 | records = [] |
|
119 | records = [] | |
120 | try: |
|
120 | try: | |
121 | f = self._repo.opener(self.statepathv2) |
|
121 | f = self._repo.opener(self.statepathv2) | |
122 | data = f.read() |
|
122 | data = f.read() | |
123 | off = 0 |
|
123 | off = 0 | |
124 | end = len(data) |
|
124 | end = len(data) | |
125 | while off < end: |
|
125 | while off < end: | |
126 | rtype = data[off] |
|
126 | rtype = data[off] | |
127 | off += 1 |
|
127 | off += 1 | |
128 | length = _unpack('>I', data[off:(off + 4)])[0] |
|
128 | length = _unpack('>I', data[off:(off + 4)])[0] | |
129 | off += 4 |
|
129 | off += 4 | |
130 | record = data[off:(off + length)] |
|
130 | record = data[off:(off + length)] | |
131 | off += length |
|
131 | off += length | |
132 | records.append((rtype, record)) |
|
132 | records.append((rtype, record)) | |
133 | f.close() |
|
133 | f.close() | |
134 | except IOError, err: |
|
134 | except IOError, err: | |
135 | if err.errno != errno.ENOENT: |
|
135 | if err.errno != errno.ENOENT: | |
136 | raise |
|
136 | raise | |
137 | return records |
|
137 | return records | |
138 | def commit(self): |
|
138 | def commit(self): | |
139 | if self._dirty: |
|
139 | if self._dirty: | |
140 | records = [] |
|
140 | records = [] | |
141 | records.append(("L", hex(self._local))) |
|
141 | records.append(("L", hex(self._local))) | |
142 | records.append(("O", hex(self._other))) |
|
142 | records.append(("O", hex(self._other))) | |
143 | for d, v in self._state.iteritems(): |
|
143 | for d, v in self._state.iteritems(): | |
144 | records.append(("F", "\0".join([d] + v))) |
|
144 | records.append(("F", "\0".join([d] + v))) | |
145 | self._writerecords(records) |
|
145 | self._writerecords(records) | |
146 | self._dirty = False |
|
146 | self._dirty = False | |
147 | def _writerecords(self, records): |
|
147 | def _writerecords(self, records): | |
148 | self._writerecordsv1(records) |
|
148 | self._writerecordsv1(records) | |
149 | self._writerecordsv2(records) |
|
149 | self._writerecordsv2(records) | |
150 | def _writerecordsv1(self, records): |
|
150 | def _writerecordsv1(self, records): | |
151 | f = self._repo.opener(self.statepathv1, "w") |
|
151 | f = self._repo.opener(self.statepathv1, "w") | |
152 | irecords = iter(records) |
|
152 | irecords = iter(records) | |
153 | lrecords = irecords.next() |
|
153 | lrecords = irecords.next() | |
154 | assert lrecords[0] == 'L' |
|
154 | assert lrecords[0] == 'L' | |
155 | f.write(hex(self._local) + "\n") |
|
155 | f.write(hex(self._local) + "\n") | |
156 | for rtype, data in irecords: |
|
156 | for rtype, data in irecords: | |
157 | if rtype == "F": |
|
157 | if rtype == "F": | |
158 | f.write("%s\n" % _droponode(data)) |
|
158 | f.write("%s\n" % _droponode(data)) | |
159 | f.close() |
|
159 | f.close() | |
160 | def _writerecordsv2(self, records): |
|
160 | def _writerecordsv2(self, records): | |
161 | f = self._repo.opener(self.statepathv2, "w") |
|
161 | f = self._repo.opener(self.statepathv2, "w") | |
162 | for key, data in records: |
|
162 | for key, data in records: | |
163 | assert len(key) == 1 |
|
163 | assert len(key) == 1 | |
164 | format = ">sI%is" % len(data) |
|
164 | format = ">sI%is" % len(data) | |
165 | f.write(_pack(format, key, len(data), data)) |
|
165 | f.write(_pack(format, key, len(data), data)) | |
166 | f.close() |
|
166 | f.close() | |
167 | def add(self, fcl, fco, fca, fd): |
|
167 | def add(self, fcl, fco, fca, fd): | |
168 | hash = util.sha1(fcl.path()).hexdigest() |
|
168 | hash = util.sha1(fcl.path()).hexdigest() | |
169 | self._repo.opener.write("merge/" + hash, fcl.data()) |
|
169 | self._repo.opener.write("merge/" + hash, fcl.data()) | |
170 | self._state[fd] = ['u', hash, fcl.path(), |
|
170 | self._state[fd] = ['u', hash, fcl.path(), | |
171 | fca.path(), hex(fca.filenode()), |
|
171 | fca.path(), hex(fca.filenode()), | |
172 | fco.path(), hex(fco.filenode()), |
|
172 | fco.path(), hex(fco.filenode()), | |
173 | fcl.flags()] |
|
173 | fcl.flags()] | |
174 | self._dirty = True |
|
174 | self._dirty = True | |
175 | def __contains__(self, dfile): |
|
175 | def __contains__(self, dfile): | |
176 | return dfile in self._state |
|
176 | return dfile in self._state | |
177 | def __getitem__(self, dfile): |
|
177 | def __getitem__(self, dfile): | |
178 | return self._state[dfile][0] |
|
178 | return self._state[dfile][0] | |
179 | def __iter__(self): |
|
179 | def __iter__(self): | |
180 | l = self._state.keys() |
|
180 | l = self._state.keys() | |
181 | l.sort() |
|
181 | l.sort() | |
182 | for f in l: |
|
182 | for f in l: | |
183 | yield f |
|
183 | yield f | |
184 | def files(self): |
|
184 | def files(self): | |
185 | return self._state.keys() |
|
185 | return self._state.keys() | |
186 | def mark(self, dfile, state): |
|
186 | def mark(self, dfile, state): | |
187 | self._state[dfile][0] = state |
|
187 | self._state[dfile][0] = state | |
188 | self._dirty = True |
|
188 | self._dirty = True | |
189 | def resolve(self, dfile, wctx): |
|
189 | def resolve(self, dfile, wctx): | |
190 | if self[dfile] == 'r': |
|
190 | if self[dfile] == 'r': | |
191 | return 0 |
|
191 | return 0 | |
192 | stateentry = self._state[dfile] |
|
192 | stateentry = self._state[dfile] | |
193 | state, hash, lfile, afile, anode, ofile, onode, flags = stateentry |
|
193 | state, hash, lfile, afile, anode, ofile, onode, flags = stateentry | |
194 | octx = self._repo[self._other] |
|
194 | octx = self._repo[self._other] | |
195 | fcd = wctx[dfile] |
|
195 | fcd = wctx[dfile] | |
196 | fco = octx[ofile] |
|
196 | fco = octx[ofile] | |
197 | fca = self._repo.filectx(afile, fileid=anode) |
|
197 | fca = self._repo.filectx(afile, fileid=anode) | |
198 | # "premerge" x flags |
|
198 | # "premerge" x flags | |
199 | flo = fco.flags() |
|
199 | flo = fco.flags() | |
200 | fla = fca.flags() |
|
200 | fla = fca.flags() | |
201 | if 'x' in flags + flo + fla and 'l' not in flags + flo + fla: |
|
201 | if 'x' in flags + flo + fla and 'l' not in flags + flo + fla: | |
202 | if fca.node() == nullid: |
|
202 | if fca.node() == nullid: | |
203 | self._repo.ui.warn(_('warning: cannot merge flags for %s\n') % |
|
203 | self._repo.ui.warn(_('warning: cannot merge flags for %s\n') % | |
204 | afile) |
|
204 | afile) | |
205 | elif flags == fla: |
|
205 | elif flags == fla: | |
206 | flags = flo |
|
206 | flags = flo | |
207 | # restore local |
|
207 | # restore local | |
208 | f = self._repo.opener("merge/" + hash) |
|
208 | f = self._repo.opener("merge/" + hash) | |
209 | self._repo.wwrite(dfile, f.read(), flags) |
|
209 | self._repo.wwrite(dfile, f.read(), flags) | |
210 | f.close() |
|
210 | f.close() | |
211 | r = filemerge.filemerge(self._repo, self._local, lfile, fcd, fco, fca) |
|
211 | r = filemerge.filemerge(self._repo, self._local, lfile, fcd, fco, fca) | |
212 | if r is None: |
|
212 | if r is None: | |
213 | # no real conflict |
|
213 | # no real conflict | |
214 | del self._state[dfile] |
|
214 | del self._state[dfile] | |
215 | elif not r: |
|
215 | elif not r: | |
216 | self.mark(dfile, 'r') |
|
216 | self.mark(dfile, 'r') | |
217 | return r |
|
217 | return r | |
218 |
|
218 | |||
219 | def _checkunknownfile(repo, wctx, mctx, f): |
|
219 | def _checkunknownfile(repo, wctx, mctx, f): | |
220 | return (not repo.dirstate._ignore(f) |
|
220 | return (not repo.dirstate._ignore(f) | |
221 | and os.path.isfile(repo.wjoin(f)) |
|
221 | and os.path.isfile(repo.wjoin(f)) | |
222 | and repo.wopener.audit.check(f) |
|
222 | and repo.wopener.audit.check(f) | |
223 | and repo.dirstate.normalize(f) not in repo.dirstate |
|
223 | and repo.dirstate.normalize(f) not in repo.dirstate | |
224 | and mctx[f].cmp(wctx[f])) |
|
224 | and mctx[f].cmp(wctx[f])) | |
225 |
|
225 | |||
226 | def _checkunknown(repo, wctx, mctx): |
|
226 | def _checkunknown(repo, wctx, mctx): | |
227 | "check for collisions between unknown files and files in mctx" |
|
227 | "check for collisions between unknown files and files in mctx" | |
228 |
|
228 | |||
229 | error = False |
|
229 | error = False | |
230 | for f in mctx: |
|
230 | for f in mctx: | |
231 | if f not in wctx and _checkunknownfile(repo, wctx, mctx, f): |
|
231 | if f not in wctx and _checkunknownfile(repo, wctx, mctx, f): | |
232 | error = True |
|
232 | error = True | |
233 | wctx._repo.ui.warn(_("%s: untracked file differs\n") % f) |
|
233 | wctx._repo.ui.warn(_("%s: untracked file differs\n") % f) | |
234 | if error: |
|
234 | if error: | |
235 | raise util.Abort(_("untracked files in working directory differ " |
|
235 | raise util.Abort(_("untracked files in working directory differ " | |
236 | "from files in requested revision")) |
|
236 | "from files in requested revision")) | |
237 |
|
237 | |||
238 | def _forgetremoved(wctx, mctx, branchmerge): |
|
238 | def _forgetremoved(wctx, mctx, branchmerge): | |
239 | """ |
|
239 | """ | |
240 | Forget removed files |
|
240 | Forget removed files | |
241 |
|
241 | |||
242 | If we're jumping between revisions (as opposed to merging), and if |
|
242 | If we're jumping between revisions (as opposed to merging), and if | |
243 | neither the working directory nor the target rev has the file, |
|
243 | neither the working directory nor the target rev has the file, | |
244 | then we need to remove it from the dirstate, to prevent the |
|
244 | then we need to remove it from the dirstate, to prevent the | |
245 | dirstate from listing the file when it is no longer in the |
|
245 | dirstate from listing the file when it is no longer in the | |
246 | manifest. |
|
246 | manifest. | |
247 |
|
247 | |||
248 | If we're merging, and the other revision has removed a file |
|
248 | If we're merging, and the other revision has removed a file | |
249 | that is not present in the working directory, we need to mark it |
|
249 | that is not present in the working directory, we need to mark it | |
250 | as removed. |
|
250 | as removed. | |
251 | """ |
|
251 | """ | |
252 |
|
252 | |||
253 | actions = [] |
|
253 | actions = [] | |
254 | state = branchmerge and 'r' or 'f' |
|
254 | state = branchmerge and 'r' or 'f' | |
255 | for f in wctx.deleted(): |
|
255 | for f in wctx.deleted(): | |
256 | if f not in mctx: |
|
256 | if f not in mctx: | |
257 | actions.append((f, state, None, "forget deleted")) |
|
257 | actions.append((f, state, None, "forget deleted")) | |
258 |
|
258 | |||
259 | if not branchmerge: |
|
259 | if not branchmerge: | |
260 | for f in wctx.removed(): |
|
260 | for f in wctx.removed(): | |
261 | if f not in mctx: |
|
261 | if f not in mctx: | |
262 | actions.append((f, "f", None, "forget removed")) |
|
262 | actions.append((f, "f", None, "forget removed")) | |
263 |
|
263 | |||
264 | return actions |
|
264 | return actions | |
265 |
|
265 | |||
266 | def _checkcollision(repo, wmf, actions, prompts): |
|
266 | def _checkcollision(repo, wmf, actions, prompts): | |
267 | # build provisional merged manifest up |
|
267 | # build provisional merged manifest up | |
268 | pmmf = set(wmf) |
|
268 | pmmf = set(wmf) | |
269 |
|
269 | |||
270 | def addop(f, args): |
|
270 | def addop(f, args): | |
271 | pmmf.add(f) |
|
271 | pmmf.add(f) | |
272 | def removeop(f, args): |
|
272 | def removeop(f, args): | |
273 | pmmf.discard(f) |
|
273 | pmmf.discard(f) | |
274 | def nop(f, args): |
|
274 | def nop(f, args): | |
275 | pass |
|
275 | pass | |
276 |
|
276 | |||
277 | def renameop(f, args): |
|
277 | def renameop(f, args): | |
278 | f2, fd, flags = args |
|
278 | f2, fd, flags = args | |
279 | if f: |
|
279 | if f: | |
280 | pmmf.discard(f) |
|
280 | pmmf.discard(f) | |
281 | pmmf.add(fd) |
|
281 | pmmf.add(fd) | |
282 | def mergeop(f, args): |
|
282 | def mergeop(f, args): | |
283 | f2, fd, move = args |
|
283 | f2, fd, move = args | |
284 | if move: |
|
284 | if move: | |
285 | pmmf.discard(f) |
|
285 | pmmf.discard(f) | |
286 | pmmf.add(fd) |
|
286 | pmmf.add(fd) | |
287 |
|
287 | |||
288 | opmap = { |
|
288 | opmap = { | |
289 | "a": addop, |
|
289 | "a": addop, | |
290 | "d": renameop, |
|
290 | "d": renameop, | |
291 | "dr": nop, |
|
291 | "dr": nop, | |
292 | "e": nop, |
|
292 | "e": nop, | |
293 | "f": addop, # untracked file should be kept in working directory |
|
293 | "f": addop, # untracked file should be kept in working directory | |
294 | "g": addop, |
|
294 | "g": addop, | |
295 | "m": mergeop, |
|
295 | "m": mergeop, | |
296 | "r": removeop, |
|
296 | "r": removeop, | |
297 | "rd": nop, |
|
297 | "rd": nop, | |
298 | } |
|
298 | } | |
299 | for f, m, args, msg in actions: |
|
299 | for f, m, args, msg in actions: | |
300 | op = opmap.get(m) |
|
300 | op = opmap.get(m) | |
301 | assert op, m |
|
301 | assert op, m | |
302 | op(f, args) |
|
302 | op(f, args) | |
303 |
|
303 | |||
304 | opmap = { |
|
304 | opmap = { | |
305 | "cd": addop, |
|
305 | "cd": addop, | |
306 | "dc": addop, |
|
306 | "dc": addop, | |
307 | } |
|
307 | } | |
308 | for f, m in prompts: |
|
308 | for f, m in prompts: | |
309 | op = opmap.get(m) |
|
309 | op = opmap.get(m) | |
310 | assert op, m |
|
310 | assert op, m | |
311 | op(f, None) |
|
311 | op(f, None) | |
312 |
|
312 | |||
313 | # check case-folding collision in provisional merged manifest |
|
313 | # check case-folding collision in provisional merged manifest | |
314 | foldmap = {} |
|
314 | foldmap = {} | |
315 | for f in sorted(pmmf): |
|
315 | for f in sorted(pmmf): | |
316 | fold = util.normcase(f) |
|
316 | fold = util.normcase(f) | |
317 | if fold in foldmap: |
|
317 | if fold in foldmap: | |
318 | raise util.Abort(_("case-folding collision between %s and %s") |
|
318 | raise util.Abort(_("case-folding collision between %s and %s") | |
319 | % (f, foldmap[fold])) |
|
319 | % (f, foldmap[fold])) | |
320 | foldmap[fold] = f |
|
320 | foldmap[fold] = f | |
321 |
|
321 | |||
322 | def manifestmerge(repo, wctx, p2, pa, branchmerge, force, partial, |
|
322 | def manifestmerge(repo, wctx, p2, pa, branchmerge, force, partial, | |
323 | acceptremote=False): |
|
323 | acceptremote=False): | |
324 | """ |
|
324 | """ | |
325 | Merge p1 and p2 with ancestor pa and generate merge action list |
|
325 | Merge p1 and p2 with ancestor pa and generate merge action list | |
326 |
|
326 | |||
327 | branchmerge and force are as passed in to update |
|
327 | branchmerge and force are as passed in to update | |
328 | partial = function to filter file lists |
|
328 | partial = function to filter file lists | |
329 | acceptremote = accept the incoming changes without prompting |
|
329 | acceptremote = accept the incoming changes without prompting | |
330 | """ |
|
330 | """ | |
331 |
|
331 | |||
332 | overwrite = force and not branchmerge |
|
332 | overwrite = force and not branchmerge | |
333 | actions, copy, movewithdir = [], {}, {} |
|
333 | actions, copy, movewithdir = [], {}, {} | |
334 |
|
334 | |||
335 | followcopies = False |
|
335 | followcopies = False | |
336 | if overwrite: |
|
336 | if overwrite: | |
337 | pa = wctx |
|
337 | pa = wctx | |
338 | elif pa == p2: # backwards |
|
338 | elif pa == p2: # backwards | |
339 | pa = wctx.p1() |
|
339 | pa = wctx.p1() | |
340 | elif not branchmerge and not wctx.dirty(missing=True): |
|
340 | elif not branchmerge and not wctx.dirty(missing=True): | |
341 | pass |
|
341 | pass | |
342 | elif pa and repo.ui.configbool("merge", "followcopies", True): |
|
342 | elif pa and repo.ui.configbool("merge", "followcopies", True): | |
343 | followcopies = True |
|
343 | followcopies = True | |
344 |
|
344 | |||
345 | # manifests fetched in order are going to be faster, so prime the caches |
|
345 | # manifests fetched in order are going to be faster, so prime the caches | |
346 | [x.manifest() for x in |
|
346 | [x.manifest() for x in | |
347 | sorted(wctx.parents() + [p2, pa], key=lambda x: x.rev())] |
|
347 | sorted(wctx.parents() + [p2, pa], key=lambda x: x.rev())] | |
348 |
|
348 | |||
349 | if followcopies: |
|
349 | if followcopies: | |
350 | ret = copies.mergecopies(repo, wctx, p2, pa) |
|
350 | ret = copies.mergecopies(repo, wctx, p2, pa) | |
351 | copy, movewithdir, diverge, renamedelete = ret |
|
351 | copy, movewithdir, diverge, renamedelete = ret | |
352 | for of, fl in diverge.iteritems(): |
|
352 | for of, fl in diverge.iteritems(): | |
353 | actions.append((of, "dr", (fl,), "divergent renames")) |
|
353 | actions.append((of, "dr", (fl,), "divergent renames")) | |
354 | for of, fl in renamedelete.iteritems(): |
|
354 | for of, fl in renamedelete.iteritems(): | |
355 | actions.append((of, "rd", (fl,), "rename and delete")) |
|
355 | actions.append((of, "rd", (fl,), "rename and delete")) | |
356 |
|
356 | |||
357 | repo.ui.note(_("resolving manifests\n")) |
|
357 | repo.ui.note(_("resolving manifests\n")) | |
358 | repo.ui.debug(" branchmerge: %s, force: %s, partial: %s\n" |
|
358 | repo.ui.debug(" branchmerge: %s, force: %s, partial: %s\n" | |
359 | % (bool(branchmerge), bool(force), bool(partial))) |
|
359 | % (bool(branchmerge), bool(force), bool(partial))) | |
360 | repo.ui.debug(" ancestor: %s, local: %s, remote: %s\n" % (pa, wctx, p2)) |
|
360 | repo.ui.debug(" ancestor: %s, local: %s, remote: %s\n" % (pa, wctx, p2)) | |
361 |
|
361 | |||
362 | m1, m2, ma = wctx.manifest(), p2.manifest(), pa.manifest() |
|
362 | m1, m2, ma = wctx.manifest(), p2.manifest(), pa.manifest() | |
363 | copied = set(copy.values()) |
|
363 | copied = set(copy.values()) | |
364 | copied.update(movewithdir.values()) |
|
364 | copied.update(movewithdir.values()) | |
365 |
|
365 | |||
366 | if '.hgsubstate' in m1: |
|
366 | if '.hgsubstate' in m1: | |
367 | # check whether sub state is modified |
|
367 | # check whether sub state is modified | |
368 | for s in sorted(wctx.substate): |
|
368 | for s in sorted(wctx.substate): | |
369 | if wctx.sub(s).dirty(): |
|
369 | if wctx.sub(s).dirty(): | |
370 | m1['.hgsubstate'] += "+" |
|
370 | m1['.hgsubstate'] += "+" | |
371 | break |
|
371 | break | |
372 |
|
372 | |||
373 | aborts, prompts = [], [] |
|
373 | aborts, prompts = [], [] | |
374 | # Compare manifests |
|
374 | # Compare manifests | |
375 | fdiff = dicthelpers.diff(m1, m2) |
|
375 | fdiff = dicthelpers.diff(m1, m2) | |
376 | flagsdiff = m1.flagsdiff(m2) |
|
376 | flagsdiff = m1.flagsdiff(m2) | |
377 | diff12 = dicthelpers.join(fdiff, flagsdiff) |
|
377 | diff12 = dicthelpers.join(fdiff, flagsdiff) | |
378 |
|
378 | |||
379 | for f, (n12, fl12) in diff12.iteritems(): |
|
379 | for f, (n12, fl12) in diff12.iteritems(): | |
380 | if n12: |
|
380 | if n12: | |
381 | n1, n2 = n12 |
|
381 | n1, n2 = n12 | |
382 | else: # file contents didn't change, but flags did |
|
382 | else: # file contents didn't change, but flags did | |
383 | n1 = n2 = m1.get(f, None) |
|
383 | n1 = n2 = m1.get(f, None) | |
384 | if n1 is None: |
|
384 | if n1 is None: | |
385 | # Since n1 == n2, the file isn't present in m2 either. This |
|
385 | # Since n1 == n2, the file isn't present in m2 either. This | |
386 | # means that the file was removed or deleted locally and |
|
386 | # means that the file was removed or deleted locally and | |
387 | # removed remotely, but that residual entries remain in flags. |
|
387 | # removed remotely, but that residual entries remain in flags. | |
388 | # This can happen in manifests generated by workingctx. |
|
388 | # This can happen in manifests generated by workingctx. | |
389 | continue |
|
389 | continue | |
390 | if fl12: |
|
390 | if fl12: | |
391 | fl1, fl2 = fl12 |
|
391 | fl1, fl2 = fl12 | |
392 | else: # flags didn't change, file contents did |
|
392 | else: # flags didn't change, file contents did | |
393 | fl1 = fl2 = m1.flags(f) |
|
393 | fl1 = fl2 = m1.flags(f) | |
394 |
|
394 | |||
395 | if partial and not partial(f): |
|
395 | if partial and not partial(f): | |
396 | continue |
|
396 | continue | |
397 | if n1 and n2: |
|
397 | if n1 and n2: | |
398 | fla = ma.flags(f) |
|
398 | fla = ma.flags(f) | |
399 | nol = 'l' not in fl1 + fl2 + fla |
|
399 | nol = 'l' not in fl1 + fl2 + fla | |
400 | a = ma.get(f, nullid) |
|
400 | a = ma.get(f, nullid) | |
401 | if n2 == a and fl2 == fla: |
|
401 | if n2 == a and fl2 == fla: | |
402 | pass # remote unchanged - keep local |
|
402 | pass # remote unchanged - keep local | |
403 | elif n1 == a and fl1 == fla: # local unchanged - use remote |
|
403 | elif n1 == a and fl1 == fla: # local unchanged - use remote | |
404 | if n1 == n2: # optimization: keep local content |
|
404 | if n1 == n2: # optimization: keep local content | |
405 | actions.append((f, "e", (fl2,), "update permissions")) |
|
405 | actions.append((f, "e", (fl2,), "update permissions")) | |
406 | else: |
|
406 | else: | |
407 | actions.append((f, "g", (fl2,), "remote is newer")) |
|
407 | actions.append((f, "g", (fl2,), "remote is newer")) | |
408 | elif nol and n2 == a: # remote only changed 'x' |
|
408 | elif nol and n2 == a: # remote only changed 'x' | |
409 | actions.append((f, "e", (fl2,), "update permissions")) |
|
409 | actions.append((f, "e", (fl2,), "update permissions")) | |
410 | elif nol and n1 == a: # local only changed 'x' |
|
410 | elif nol and n1 == a: # local only changed 'x' | |
411 | actions.append((f, "g", (fl1,), "remote is newer")) |
|
411 | actions.append((f, "g", (fl1,), "remote is newer")) | |
412 | else: # both changed something |
|
412 | else: # both changed something | |
413 | actions.append((f, "m", (f, f, False), "versions differ")) |
|
413 | actions.append((f, "m", (f, f, False), "versions differ")) | |
414 | elif f in copied: # files we'll deal with on m2 side |
|
414 | elif f in copied: # files we'll deal with on m2 side | |
415 | pass |
|
415 | pass | |
416 | elif n1 and f in movewithdir: # directory rename |
|
416 | elif n1 and f in movewithdir: # directory rename | |
417 | f2 = movewithdir[f] |
|
417 | f2 = movewithdir[f] | |
418 | actions.append((f, "d", (None, f2, fl1), |
|
418 | actions.append((f, "d", (None, f2, fl1), | |
419 | "remote renamed directory to " + f2)) |
|
419 | "remote renamed directory to " + f2)) | |
420 | elif n1 and f in copy: |
|
420 | elif n1 and f in copy: | |
421 | f2 = copy[f] |
|
421 | f2 = copy[f] | |
422 | actions.append((f, "m", (f2, f, False), |
|
422 | actions.append((f, "m", (f2, f, False), | |
423 | "local copied/moved to " + f2)) |
|
423 | "local copied/moved to " + f2)) | |
424 | elif n1 and f in ma: # clean, a different, no remote |
|
424 | elif n1 and f in ma: # clean, a different, no remote | |
425 | if n1 != ma[f]: |
|
425 | if n1 != ma[f]: | |
426 | prompts.append((f, "cd")) # prompt changed/deleted |
|
426 | if acceptremote: | |
|
427 | actions.append((f, "r", None, "remote delete")) | |||
|
428 | else: | |||
|
429 | prompts.append((f, "cd")) # prompt changed/deleted | |||
427 | elif n1[20:] == "a": # added, no remote |
|
430 | elif n1[20:] == "a": # added, no remote | |
428 | actions.append((f, "f", None, "remote deleted")) |
|
431 | actions.append((f, "f", None, "remote deleted")) | |
429 | else: |
|
432 | else: | |
430 | actions.append((f, "r", None, "other deleted")) |
|
433 | actions.append((f, "r", None, "other deleted")) | |
431 | elif n2 and f in movewithdir: |
|
434 | elif n2 and f in movewithdir: | |
432 | f2 = movewithdir[f] |
|
435 | f2 = movewithdir[f] | |
433 | actions.append((None, "d", (f, f2, fl2), |
|
436 | actions.append((None, "d", (f, f2, fl2), | |
434 | "local renamed directory to " + f2)) |
|
437 | "local renamed directory to " + f2)) | |
435 | elif n2 and f in copy: |
|
438 | elif n2 and f in copy: | |
436 | f2 = copy[f] |
|
439 | f2 = copy[f] | |
437 | if f2 in m2: |
|
440 | if f2 in m2: | |
438 | actions.append((f2, "m", (f, f, False), |
|
441 | actions.append((f2, "m", (f, f, False), | |
439 | "remote copied to " + f)) |
|
442 | "remote copied to " + f)) | |
440 | else: |
|
443 | else: | |
441 | actions.append((f2, "m", (f, f, True), |
|
444 | actions.append((f2, "m", (f, f, True), | |
442 | "remote moved to " + f)) |
|
445 | "remote moved to " + f)) | |
443 | elif n2 and f not in ma: |
|
446 | elif n2 and f not in ma: | |
444 | # local unknown, remote created: the logic is described by the |
|
447 | # local unknown, remote created: the logic is described by the | |
445 | # following table: |
|
448 | # following table: | |
446 | # |
|
449 | # | |
447 | # force branchmerge different | action |
|
450 | # force branchmerge different | action | |
448 | # n * n | get |
|
451 | # n * n | get | |
449 | # n * y | abort |
|
452 | # n * y | abort | |
450 | # y n * | get |
|
453 | # y n * | get | |
451 | # y y n | get |
|
454 | # y y n | get | |
452 | # y y y | merge |
|
455 | # y y y | merge | |
453 | # |
|
456 | # | |
454 | # Checking whether the files are different is expensive, so we |
|
457 | # Checking whether the files are different is expensive, so we | |
455 | # don't do that when we can avoid it. |
|
458 | # don't do that when we can avoid it. | |
456 | if force and not branchmerge: |
|
459 | if force and not branchmerge: | |
457 | actions.append((f, "g", (fl2,), "remote created")) |
|
460 | actions.append((f, "g", (fl2,), "remote created")) | |
458 | else: |
|
461 | else: | |
459 | different = _checkunknownfile(repo, wctx, p2, f) |
|
462 | different = _checkunknownfile(repo, wctx, p2, f) | |
460 | if force and branchmerge and different: |
|
463 | if force and branchmerge and different: | |
461 | actions.append((f, "m", (f, f, False), |
|
464 | actions.append((f, "m", (f, f, False), | |
462 | "remote differs from untracked local")) |
|
465 | "remote differs from untracked local")) | |
463 | elif not force and different: |
|
466 | elif not force and different: | |
464 | aborts.append((f, "ud")) |
|
467 | aborts.append((f, "ud")) | |
465 | else: |
|
468 | else: | |
466 | actions.append((f, "g", (fl2,), "remote created")) |
|
469 | actions.append((f, "g", (fl2,), "remote created")) | |
467 | elif n2 and n2 != ma[f]: |
|
470 | elif n2 and n2 != ma[f]: | |
468 | different = _checkunknownfile(repo, wctx, p2, f) |
|
471 | different = _checkunknownfile(repo, wctx, p2, f) | |
469 | if not force and different: |
|
472 | if not force and different: | |
470 | aborts.append((f, "ud")) |
|
473 | aborts.append((f, "ud")) | |
471 | else: |
|
474 | else: | |
472 | # if different: old untracked f may be overwritten and lost |
|
475 | # if different: old untracked f may be overwritten and lost | |
473 | prompts.append((f, "dc")) # prompt deleted/changed |
|
476 | if acceptremote: | |
|
477 | actions.append((f, "g", (m2.flags(f),), | |||
|
478 | "remote recreating")) | |||
|
479 | else: | |||
|
480 | prompts.append((f, "dc")) # prompt deleted/changed | |||
474 |
|
481 | |||
475 | for f, m in sorted(aborts): |
|
482 | for f, m in sorted(aborts): | |
476 | if m == "ud": |
|
483 | if m == "ud": | |
477 | repo.ui.warn(_("%s: untracked file differs\n") % f) |
|
484 | repo.ui.warn(_("%s: untracked file differs\n") % f) | |
478 | else: assert False, m |
|
485 | else: assert False, m | |
479 | if aborts: |
|
486 | if aborts: | |
480 | raise util.Abort(_("untracked files in working directory differ " |
|
487 | raise util.Abort(_("untracked files in working directory differ " | |
481 | "from files in requested revision")) |
|
488 | "from files in requested revision")) | |
482 |
|
489 | |||
483 | if not util.checkcase(repo.path): |
|
490 | if not util.checkcase(repo.path): | |
484 | # check collision between files only in p2 for clean update |
|
491 | # check collision between files only in p2 for clean update | |
485 | if (not branchmerge and |
|
492 | if (not branchmerge and | |
486 | (force or not wctx.dirty(missing=True, branch=False))): |
|
493 | (force or not wctx.dirty(missing=True, branch=False))): | |
487 | _checkcollision(repo, m2, [], []) |
|
494 | _checkcollision(repo, m2, [], []) | |
488 | else: |
|
495 | else: | |
489 | _checkcollision(repo, m1, actions, prompts) |
|
496 | _checkcollision(repo, m1, actions, prompts) | |
490 |
|
497 | |||
491 | for f, m in sorted(prompts): |
|
498 | for f, m in sorted(prompts): | |
492 | if m == "cd": |
|
499 | if m == "cd": | |
493 | if acceptremote: |
|
500 | if repo.ui.promptchoice( | |
494 | actions.append((f, "r", None, "remote delete")) |
|
|||
495 | elif repo.ui.promptchoice( |
|
|||
496 | _("local changed %s which remote deleted\n" |
|
501 | _("local changed %s which remote deleted\n" | |
497 | "use (c)hanged version or (d)elete?" |
|
502 | "use (c)hanged version or (d)elete?" | |
498 | "$$ &Changed $$ &Delete") % f, 0): |
|
503 | "$$ &Changed $$ &Delete") % f, 0): | |
499 | actions.append((f, "r", None, "prompt delete")) |
|
504 | actions.append((f, "r", None, "prompt delete")) | |
500 | else: |
|
505 | else: | |
501 | actions.append((f, "a", None, "prompt keep")) |
|
506 | actions.append((f, "a", None, "prompt keep")) | |
502 | elif m == "dc": |
|
507 | elif m == "dc": | |
503 | if acceptremote: |
|
508 | if repo.ui.promptchoice( | |
504 | actions.append((f, "g", (m2.flags(f),), "remote recreating")) |
|
|||
505 | elif repo.ui.promptchoice( |
|
|||
506 | _("remote changed %s which local deleted\n" |
|
509 | _("remote changed %s which local deleted\n" | |
507 | "use (c)hanged version or leave (d)eleted?" |
|
510 | "use (c)hanged version or leave (d)eleted?" | |
508 | "$$ &Changed $$ &Deleted") % f, 0) == 0: |
|
511 | "$$ &Changed $$ &Deleted") % f, 0) == 0: | |
509 | actions.append((f, "g", (m2.flags(f),), "prompt recreating")) |
|
512 | actions.append((f, "g", (m2.flags(f),), "prompt recreating")) | |
510 | else: assert False, m |
|
513 | else: assert False, m | |
511 | return actions |
|
514 | return actions | |
512 |
|
515 | |||
513 | def actionkey(a): |
|
516 | def actionkey(a): | |
514 | return a[1] in "rf" and -1 or 0, a |
|
517 | return a[1] in "rf" and -1 or 0, a | |
515 |
|
518 | |||
516 | def getremove(repo, mctx, overwrite, args): |
|
519 | def getremove(repo, mctx, overwrite, args): | |
517 | """apply usually-non-interactive updates to the working directory |
|
520 | """apply usually-non-interactive updates to the working directory | |
518 |
|
521 | |||
519 | mctx is the context to be merged into the working copy |
|
522 | mctx is the context to be merged into the working copy | |
520 |
|
523 | |||
521 | yields tuples for progress updates |
|
524 | yields tuples for progress updates | |
522 | """ |
|
525 | """ | |
523 | verbose = repo.ui.verbose |
|
526 | verbose = repo.ui.verbose | |
524 | unlink = util.unlinkpath |
|
527 | unlink = util.unlinkpath | |
525 | wjoin = repo.wjoin |
|
528 | wjoin = repo.wjoin | |
526 | fctx = mctx.filectx |
|
529 | fctx = mctx.filectx | |
527 | wwrite = repo.wwrite |
|
530 | wwrite = repo.wwrite | |
528 | audit = repo.wopener.audit |
|
531 | audit = repo.wopener.audit | |
529 | i = 0 |
|
532 | i = 0 | |
530 | for arg in args: |
|
533 | for arg in args: | |
531 | f = arg[0] |
|
534 | f = arg[0] | |
532 | if arg[1] == 'r': |
|
535 | if arg[1] == 'r': | |
533 | if verbose: |
|
536 | if verbose: | |
534 | repo.ui.note(_("removing %s\n") % f) |
|
537 | repo.ui.note(_("removing %s\n") % f) | |
535 | audit(f) |
|
538 | audit(f) | |
536 | try: |
|
539 | try: | |
537 | unlink(wjoin(f), ignoremissing=True) |
|
540 | unlink(wjoin(f), ignoremissing=True) | |
538 | except OSError, inst: |
|
541 | except OSError, inst: | |
539 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
542 | repo.ui.warn(_("update failed to remove %s: %s!\n") % | |
540 | (f, inst.strerror)) |
|
543 | (f, inst.strerror)) | |
541 | else: |
|
544 | else: | |
542 | if verbose: |
|
545 | if verbose: | |
543 | repo.ui.note(_("getting %s\n") % f) |
|
546 | repo.ui.note(_("getting %s\n") % f) | |
544 | wwrite(f, fctx(f).data(), arg[2][0]) |
|
547 | wwrite(f, fctx(f).data(), arg[2][0]) | |
545 | if i == 100: |
|
548 | if i == 100: | |
546 | yield i, f |
|
549 | yield i, f | |
547 | i = 0 |
|
550 | i = 0 | |
548 | i += 1 |
|
551 | i += 1 | |
549 | if i > 0: |
|
552 | if i > 0: | |
550 | yield i, f |
|
553 | yield i, f | |
551 |
|
554 | |||
552 | def applyupdates(repo, actions, wctx, mctx, actx, overwrite): |
|
555 | def applyupdates(repo, actions, wctx, mctx, actx, overwrite): | |
553 | """apply the merge action list to the working directory |
|
556 | """apply the merge action list to the working directory | |
554 |
|
557 | |||
555 | wctx is the working copy context |
|
558 | wctx is the working copy context | |
556 | mctx is the context to be merged into the working copy |
|
559 | mctx is the context to be merged into the working copy | |
557 | actx is the context of the common ancestor |
|
560 | actx is the context of the common ancestor | |
558 |
|
561 | |||
559 | Return a tuple of counts (updated, merged, removed, unresolved) that |
|
562 | Return a tuple of counts (updated, merged, removed, unresolved) that | |
560 | describes how many files were affected by the update. |
|
563 | describes how many files were affected by the update. | |
561 | """ |
|
564 | """ | |
562 |
|
565 | |||
563 | updated, merged, removed, unresolved = 0, 0, 0, 0 |
|
566 | updated, merged, removed, unresolved = 0, 0, 0, 0 | |
564 | ms = mergestate(repo) |
|
567 | ms = mergestate(repo) | |
565 | ms.reset(wctx.p1().node(), mctx.node()) |
|
568 | ms.reset(wctx.p1().node(), mctx.node()) | |
566 | moves = [] |
|
569 | moves = [] | |
567 | actions.sort(key=actionkey) |
|
570 | actions.sort(key=actionkey) | |
568 |
|
571 | |||
569 | # prescan for merges |
|
572 | # prescan for merges | |
570 | for a in actions: |
|
573 | for a in actions: | |
571 | f, m, args, msg = a |
|
574 | f, m, args, msg = a | |
572 | repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m)) |
|
575 | repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m)) | |
573 | if m == "m": # merge |
|
576 | if m == "m": # merge | |
574 | f2, fd, move = args |
|
577 | f2, fd, move = args | |
575 | if fd == '.hgsubstate': # merged internally |
|
578 | if fd == '.hgsubstate': # merged internally | |
576 | continue |
|
579 | continue | |
577 | repo.ui.debug(" preserving %s for resolve of %s\n" % (f, fd)) |
|
580 | repo.ui.debug(" preserving %s for resolve of %s\n" % (f, fd)) | |
578 | fcl = wctx[f] |
|
581 | fcl = wctx[f] | |
579 | fco = mctx[f2] |
|
582 | fco = mctx[f2] | |
580 | if mctx == actx: # backwards, use working dir parent as ancestor |
|
583 | if mctx == actx: # backwards, use working dir parent as ancestor | |
581 | if fcl.parents(): |
|
584 | if fcl.parents(): | |
582 | fca = fcl.p1() |
|
585 | fca = fcl.p1() | |
583 | else: |
|
586 | else: | |
584 | fca = repo.filectx(f, fileid=nullrev) |
|
587 | fca = repo.filectx(f, fileid=nullrev) | |
585 | else: |
|
588 | else: | |
586 | fca = fcl.ancestor(fco, actx) |
|
589 | fca = fcl.ancestor(fco, actx) | |
587 | if not fca: |
|
590 | if not fca: | |
588 | fca = repo.filectx(f, fileid=nullrev) |
|
591 | fca = repo.filectx(f, fileid=nullrev) | |
589 | ms.add(fcl, fco, fca, fd) |
|
592 | ms.add(fcl, fco, fca, fd) | |
590 | if f != fd and move: |
|
593 | if f != fd and move: | |
591 | moves.append(f) |
|
594 | moves.append(f) | |
592 |
|
595 | |||
593 | audit = repo.wopener.audit |
|
596 | audit = repo.wopener.audit | |
594 |
|
597 | |||
595 | # remove renamed files after safely stored |
|
598 | # remove renamed files after safely stored | |
596 | for f in moves: |
|
599 | for f in moves: | |
597 | if os.path.lexists(repo.wjoin(f)): |
|
600 | if os.path.lexists(repo.wjoin(f)): | |
598 | repo.ui.debug("removing %s\n" % f) |
|
601 | repo.ui.debug("removing %s\n" % f) | |
599 | audit(f) |
|
602 | audit(f) | |
600 | util.unlinkpath(repo.wjoin(f)) |
|
603 | util.unlinkpath(repo.wjoin(f)) | |
601 |
|
604 | |||
602 | numupdates = len(actions) |
|
605 | numupdates = len(actions) | |
603 | workeractions = [a for a in actions if a[1] in 'gr'] |
|
606 | workeractions = [a for a in actions if a[1] in 'gr'] | |
604 | updateactions = [a for a in workeractions if a[1] == 'g'] |
|
607 | updateactions = [a for a in workeractions if a[1] == 'g'] | |
605 | updated = len(updateactions) |
|
608 | updated = len(updateactions) | |
606 | removeactions = [a for a in workeractions if a[1] == 'r'] |
|
609 | removeactions = [a for a in workeractions if a[1] == 'r'] | |
607 | removed = len(removeactions) |
|
610 | removed = len(removeactions) | |
608 | actions = [a for a in actions if a[1] not in 'gr'] |
|
611 | actions = [a for a in actions if a[1] not in 'gr'] | |
609 |
|
612 | |||
610 | hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate'] |
|
613 | hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate'] | |
611 | if hgsub and hgsub[0] == 'r': |
|
614 | if hgsub and hgsub[0] == 'r': | |
612 | subrepo.submerge(repo, wctx, mctx, wctx, overwrite) |
|
615 | subrepo.submerge(repo, wctx, mctx, wctx, overwrite) | |
613 |
|
616 | |||
614 | z = 0 |
|
617 | z = 0 | |
615 | prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), |
|
618 | prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), | |
616 | removeactions) |
|
619 | removeactions) | |
617 | for i, item in prog: |
|
620 | for i, item in prog: | |
618 | z += i |
|
621 | z += i | |
619 | repo.ui.progress(_('updating'), z, item=item, total=numupdates, |
|
622 | repo.ui.progress(_('updating'), z, item=item, total=numupdates, | |
620 | unit=_('files')) |
|
623 | unit=_('files')) | |
621 | prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), |
|
624 | prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), | |
622 | updateactions) |
|
625 | updateactions) | |
623 | for i, item in prog: |
|
626 | for i, item in prog: | |
624 | z += i |
|
627 | z += i | |
625 | repo.ui.progress(_('updating'), z, item=item, total=numupdates, |
|
628 | repo.ui.progress(_('updating'), z, item=item, total=numupdates, | |
626 | unit=_('files')) |
|
629 | unit=_('files')) | |
627 |
|
630 | |||
628 | if hgsub and hgsub[0] == 'g': |
|
631 | if hgsub and hgsub[0] == 'g': | |
629 | subrepo.submerge(repo, wctx, mctx, wctx, overwrite) |
|
632 | subrepo.submerge(repo, wctx, mctx, wctx, overwrite) | |
630 |
|
633 | |||
631 | _updating = _('updating') |
|
634 | _updating = _('updating') | |
632 | _files = _('files') |
|
635 | _files = _('files') | |
633 | progress = repo.ui.progress |
|
636 | progress = repo.ui.progress | |
634 |
|
637 | |||
635 | for i, a in enumerate(actions): |
|
638 | for i, a in enumerate(actions): | |
636 | f, m, args, msg = a |
|
639 | f, m, args, msg = a | |
637 | progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files) |
|
640 | progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files) | |
638 | if m == "m": # merge |
|
641 | if m == "m": # merge | |
639 | f2, fd, move = args |
|
642 | f2, fd, move = args | |
640 | if fd == '.hgsubstate': # subrepo states need updating |
|
643 | if fd == '.hgsubstate': # subrepo states need updating | |
641 | subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), |
|
644 | subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), | |
642 | overwrite) |
|
645 | overwrite) | |
643 | continue |
|
646 | continue | |
644 | audit(fd) |
|
647 | audit(fd) | |
645 | r = ms.resolve(fd, wctx) |
|
648 | r = ms.resolve(fd, wctx) | |
646 | if r is not None and r > 0: |
|
649 | if r is not None and r > 0: | |
647 | unresolved += 1 |
|
650 | unresolved += 1 | |
648 | else: |
|
651 | else: | |
649 | if r is None: |
|
652 | if r is None: | |
650 | updated += 1 |
|
653 | updated += 1 | |
651 | else: |
|
654 | else: | |
652 | merged += 1 |
|
655 | merged += 1 | |
653 | elif m == "d": # directory rename |
|
656 | elif m == "d": # directory rename | |
654 | f2, fd, flags = args |
|
657 | f2, fd, flags = args | |
655 | if f: |
|
658 | if f: | |
656 | repo.ui.note(_("moving %s to %s\n") % (f, fd)) |
|
659 | repo.ui.note(_("moving %s to %s\n") % (f, fd)) | |
657 | audit(fd) |
|
660 | audit(fd) | |
658 | repo.wwrite(fd, wctx.filectx(f).data(), flags) |
|
661 | repo.wwrite(fd, wctx.filectx(f).data(), flags) | |
659 | util.unlinkpath(repo.wjoin(f)) |
|
662 | util.unlinkpath(repo.wjoin(f)) | |
660 | if f2: |
|
663 | if f2: | |
661 | repo.ui.note(_("getting %s to %s\n") % (f2, fd)) |
|
664 | repo.ui.note(_("getting %s to %s\n") % (f2, fd)) | |
662 | repo.wwrite(fd, mctx.filectx(f2).data(), flags) |
|
665 | repo.wwrite(fd, mctx.filectx(f2).data(), flags) | |
663 | updated += 1 |
|
666 | updated += 1 | |
664 | elif m == "dr": # divergent renames |
|
667 | elif m == "dr": # divergent renames | |
665 | fl, = args |
|
668 | fl, = args | |
666 | repo.ui.warn(_("note: possible conflict - %s was renamed " |
|
669 | repo.ui.warn(_("note: possible conflict - %s was renamed " | |
667 | "multiple times to:\n") % f) |
|
670 | "multiple times to:\n") % f) | |
668 | for nf in fl: |
|
671 | for nf in fl: | |
669 | repo.ui.warn(" %s\n" % nf) |
|
672 | repo.ui.warn(" %s\n" % nf) | |
670 | elif m == "rd": # rename and delete |
|
673 | elif m == "rd": # rename and delete | |
671 | fl, = args |
|
674 | fl, = args | |
672 | repo.ui.warn(_("note: possible conflict - %s was deleted " |
|
675 | repo.ui.warn(_("note: possible conflict - %s was deleted " | |
673 | "and renamed to:\n") % f) |
|
676 | "and renamed to:\n") % f) | |
674 | for nf in fl: |
|
677 | for nf in fl: | |
675 | repo.ui.warn(" %s\n" % nf) |
|
678 | repo.ui.warn(" %s\n" % nf) | |
676 | elif m == "e": # exec |
|
679 | elif m == "e": # exec | |
677 | flags, = args |
|
680 | flags, = args | |
678 | audit(f) |
|
681 | audit(f) | |
679 | util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags) |
|
682 | util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags) | |
680 | updated += 1 |
|
683 | updated += 1 | |
681 | ms.commit() |
|
684 | ms.commit() | |
682 | progress(_updating, None, total=numupdates, unit=_files) |
|
685 | progress(_updating, None, total=numupdates, unit=_files) | |
683 |
|
686 | |||
684 | return updated, merged, removed, unresolved |
|
687 | return updated, merged, removed, unresolved | |
685 |
|
688 | |||
686 | def calculateupdates(repo, tctx, mctx, ancestor, branchmerge, force, partial, |
|
689 | def calculateupdates(repo, tctx, mctx, ancestor, branchmerge, force, partial, | |
687 | acceptremote=False): |
|
690 | acceptremote=False): | |
688 | "Calculate the actions needed to merge mctx into tctx" |
|
691 | "Calculate the actions needed to merge mctx into tctx" | |
689 | actions = [] |
|
692 | actions = [] | |
690 | actions += manifestmerge(repo, tctx, mctx, |
|
693 | actions += manifestmerge(repo, tctx, mctx, | |
691 | ancestor, |
|
694 | ancestor, | |
692 | branchmerge, force, |
|
695 | branchmerge, force, | |
693 | partial, acceptremote) |
|
696 | partial, acceptremote) | |
694 | if tctx.rev() is None: |
|
697 | if tctx.rev() is None: | |
695 | actions += _forgetremoved(tctx, mctx, branchmerge) |
|
698 | actions += _forgetremoved(tctx, mctx, branchmerge) | |
696 | return actions |
|
699 | return actions | |
697 |
|
700 | |||
698 | def recordupdates(repo, actions, branchmerge): |
|
701 | def recordupdates(repo, actions, branchmerge): | |
699 | "record merge actions to the dirstate" |
|
702 | "record merge actions to the dirstate" | |
700 |
|
703 | |||
701 | for a in actions: |
|
704 | for a in actions: | |
702 | f, m, args, msg = a |
|
705 | f, m, args, msg = a | |
703 | if m == "r": # remove |
|
706 | if m == "r": # remove | |
704 | if branchmerge: |
|
707 | if branchmerge: | |
705 | repo.dirstate.remove(f) |
|
708 | repo.dirstate.remove(f) | |
706 | else: |
|
709 | else: | |
707 | repo.dirstate.drop(f) |
|
710 | repo.dirstate.drop(f) | |
708 | elif m == "a": # re-add |
|
711 | elif m == "a": # re-add | |
709 | if not branchmerge: |
|
712 | if not branchmerge: | |
710 | repo.dirstate.add(f) |
|
713 | repo.dirstate.add(f) | |
711 | elif m == "f": # forget |
|
714 | elif m == "f": # forget | |
712 | repo.dirstate.drop(f) |
|
715 | repo.dirstate.drop(f) | |
713 | elif m == "e": # exec change |
|
716 | elif m == "e": # exec change | |
714 | repo.dirstate.normallookup(f) |
|
717 | repo.dirstate.normallookup(f) | |
715 | elif m == "g": # get |
|
718 | elif m == "g": # get | |
716 | if branchmerge: |
|
719 | if branchmerge: | |
717 | repo.dirstate.otherparent(f) |
|
720 | repo.dirstate.otherparent(f) | |
718 | else: |
|
721 | else: | |
719 | repo.dirstate.normal(f) |
|
722 | repo.dirstate.normal(f) | |
720 | elif m == "m": # merge |
|
723 | elif m == "m": # merge | |
721 | f2, fd, move = args |
|
724 | f2, fd, move = args | |
722 | if branchmerge: |
|
725 | if branchmerge: | |
723 | # We've done a branch merge, mark this file as merged |
|
726 | # We've done a branch merge, mark this file as merged | |
724 | # so that we properly record the merger later |
|
727 | # so that we properly record the merger later | |
725 | repo.dirstate.merge(fd) |
|
728 | repo.dirstate.merge(fd) | |
726 | if f != f2: # copy/rename |
|
729 | if f != f2: # copy/rename | |
727 | if move: |
|
730 | if move: | |
728 | repo.dirstate.remove(f) |
|
731 | repo.dirstate.remove(f) | |
729 | if f != fd: |
|
732 | if f != fd: | |
730 | repo.dirstate.copy(f, fd) |
|
733 | repo.dirstate.copy(f, fd) | |
731 | else: |
|
734 | else: | |
732 | repo.dirstate.copy(f2, fd) |
|
735 | repo.dirstate.copy(f2, fd) | |
733 | else: |
|
736 | else: | |
734 | # We've update-merged a locally modified file, so |
|
737 | # We've update-merged a locally modified file, so | |
735 | # we set the dirstate to emulate a normal checkout |
|
738 | # we set the dirstate to emulate a normal checkout | |
736 | # of that file some time in the past. Thus our |
|
739 | # of that file some time in the past. Thus our | |
737 | # merge will appear as a normal local file |
|
740 | # merge will appear as a normal local file | |
738 | # modification. |
|
741 | # modification. | |
739 | if f2 == fd: # file not locally copied/moved |
|
742 | if f2 == fd: # file not locally copied/moved | |
740 | repo.dirstate.normallookup(fd) |
|
743 | repo.dirstate.normallookup(fd) | |
741 | if move: |
|
744 | if move: | |
742 | repo.dirstate.drop(f) |
|
745 | repo.dirstate.drop(f) | |
743 | elif m == "d": # directory rename |
|
746 | elif m == "d": # directory rename | |
744 | f2, fd, flag = args |
|
747 | f2, fd, flag = args | |
745 | if not f2 and f not in repo.dirstate: |
|
748 | if not f2 and f not in repo.dirstate: | |
746 | # untracked file moved |
|
749 | # untracked file moved | |
747 | continue |
|
750 | continue | |
748 | if branchmerge: |
|
751 | if branchmerge: | |
749 | repo.dirstate.add(fd) |
|
752 | repo.dirstate.add(fd) | |
750 | if f: |
|
753 | if f: | |
751 | repo.dirstate.remove(f) |
|
754 | repo.dirstate.remove(f) | |
752 | repo.dirstate.copy(f, fd) |
|
755 | repo.dirstate.copy(f, fd) | |
753 | if f2: |
|
756 | if f2: | |
754 | repo.dirstate.copy(f2, fd) |
|
757 | repo.dirstate.copy(f2, fd) | |
755 | else: |
|
758 | else: | |
756 | repo.dirstate.normal(fd) |
|
759 | repo.dirstate.normal(fd) | |
757 | if f: |
|
760 | if f: | |
758 | repo.dirstate.drop(f) |
|
761 | repo.dirstate.drop(f) | |
759 |
|
762 | |||
760 | def update(repo, node, branchmerge, force, partial, ancestor=None, |
|
763 | def update(repo, node, branchmerge, force, partial, ancestor=None, | |
761 | mergeancestor=False): |
|
764 | mergeancestor=False): | |
762 | """ |
|
765 | """ | |
763 | Perform a merge between the working directory and the given node |
|
766 | Perform a merge between the working directory and the given node | |
764 |
|
767 | |||
765 | node = the node to update to, or None if unspecified |
|
768 | node = the node to update to, or None if unspecified | |
766 | branchmerge = whether to merge between branches |
|
769 | branchmerge = whether to merge between branches | |
767 | force = whether to force branch merging or file overwriting |
|
770 | force = whether to force branch merging or file overwriting | |
768 | partial = a function to filter file lists (dirstate not updated) |
|
771 | partial = a function to filter file lists (dirstate not updated) | |
769 | mergeancestor = whether it is merging with an ancestor. If true, |
|
772 | mergeancestor = whether it is merging with an ancestor. If true, | |
770 | we should accept the incoming changes for any prompts that occur. |
|
773 | we should accept the incoming changes for any prompts that occur. | |
771 | If false, merging with an ancestor (fast-forward) is only allowed |
|
774 | If false, merging with an ancestor (fast-forward) is only allowed | |
772 | between different named branches. This flag is used by rebase extension |
|
775 | between different named branches. This flag is used by rebase extension | |
773 | as a temporary fix and should be avoided in general. |
|
776 | as a temporary fix and should be avoided in general. | |
774 |
|
777 | |||
775 | The table below shows all the behaviors of the update command |
|
778 | The table below shows all the behaviors of the update command | |
776 | given the -c and -C or no options, whether the working directory |
|
779 | given the -c and -C or no options, whether the working directory | |
777 | is dirty, whether a revision is specified, and the relationship of |
|
780 | is dirty, whether a revision is specified, and the relationship of | |
778 | the parent rev to the target rev (linear, on the same named |
|
781 | the parent rev to the target rev (linear, on the same named | |
779 | branch, or on another named branch). |
|
782 | branch, or on another named branch). | |
780 |
|
783 | |||
781 | This logic is tested by test-update-branches.t. |
|
784 | This logic is tested by test-update-branches.t. | |
782 |
|
785 | |||
783 | -c -C dirty rev | linear same cross |
|
786 | -c -C dirty rev | linear same cross | |
784 | n n n n | ok (1) x |
|
787 | n n n n | ok (1) x | |
785 | n n n y | ok ok ok |
|
788 | n n n y | ok ok ok | |
786 | n n y n | merge (2) (2) |
|
789 | n n y n | merge (2) (2) | |
787 | n n y y | merge (3) (3) |
|
790 | n n y y | merge (3) (3) | |
788 | n y * * | --- discard --- |
|
791 | n y * * | --- discard --- | |
789 | y n y * | --- (4) --- |
|
792 | y n y * | --- (4) --- | |
790 | y n n * | --- ok --- |
|
793 | y n n * | --- ok --- | |
791 | y y * * | --- (5) --- |
|
794 | y y * * | --- (5) --- | |
792 |
|
795 | |||
793 | x = can't happen |
|
796 | x = can't happen | |
794 | * = don't-care |
|
797 | * = don't-care | |
795 | 1 = abort: not a linear update (merge or update --check to force update) |
|
798 | 1 = abort: not a linear update (merge or update --check to force update) | |
796 | 2 = abort: uncommitted changes (commit and merge, or update --clean to |
|
799 | 2 = abort: uncommitted changes (commit and merge, or update --clean to | |
797 | discard changes) |
|
800 | discard changes) | |
798 | 3 = abort: uncommitted changes (commit or update --clean to discard changes) |
|
801 | 3 = abort: uncommitted changes (commit or update --clean to discard changes) | |
799 | 4 = abort: uncommitted changes (checked in commands.py) |
|
802 | 4 = abort: uncommitted changes (checked in commands.py) | |
800 | 5 = incompatible options (checked in commands.py) |
|
803 | 5 = incompatible options (checked in commands.py) | |
801 |
|
804 | |||
802 | Return the same tuple as applyupdates(). |
|
805 | Return the same tuple as applyupdates(). | |
803 | """ |
|
806 | """ | |
804 |
|
807 | |||
805 | onode = node |
|
808 | onode = node | |
806 | wlock = repo.wlock() |
|
809 | wlock = repo.wlock() | |
807 | try: |
|
810 | try: | |
808 | wc = repo[None] |
|
811 | wc = repo[None] | |
809 | pl = wc.parents() |
|
812 | pl = wc.parents() | |
810 | p1 = pl[0] |
|
813 | p1 = pl[0] | |
811 | pa = None |
|
814 | pa = None | |
812 | if ancestor: |
|
815 | if ancestor: | |
813 | pa = repo[ancestor] |
|
816 | pa = repo[ancestor] | |
814 |
|
817 | |||
815 | if node is None: |
|
818 | if node is None: | |
816 | # Here is where we should consider bookmarks, divergent bookmarks, |
|
819 | # Here is where we should consider bookmarks, divergent bookmarks, | |
817 | # foreground changesets (successors), and tip of current branch; |
|
820 | # foreground changesets (successors), and tip of current branch; | |
818 | # but currently we are only checking the branch tips. |
|
821 | # but currently we are only checking the branch tips. | |
819 | try: |
|
822 | try: | |
820 | node = repo.branchtip(wc.branch()) |
|
823 | node = repo.branchtip(wc.branch()) | |
821 | except error.RepoLookupError: |
|
824 | except error.RepoLookupError: | |
822 | if wc.branch() == "default": # no default branch! |
|
825 | if wc.branch() == "default": # no default branch! | |
823 | node = repo.lookup("tip") # update to tip |
|
826 | node = repo.lookup("tip") # update to tip | |
824 | else: |
|
827 | else: | |
825 | raise util.Abort(_("branch %s not found") % wc.branch()) |
|
828 | raise util.Abort(_("branch %s not found") % wc.branch()) | |
826 |
|
829 | |||
827 | if p1.obsolete() and not p1.children(): |
|
830 | if p1.obsolete() and not p1.children(): | |
828 | # allow updating to successors |
|
831 | # allow updating to successors | |
829 | successors = obsolete.successorssets(repo, p1.node()) |
|
832 | successors = obsolete.successorssets(repo, p1.node()) | |
830 |
|
833 | |||
831 | # behavior of certain cases is as follows, |
|
834 | # behavior of certain cases is as follows, | |
832 | # |
|
835 | # | |
833 | # divergent changesets: update to highest rev, similar to what |
|
836 | # divergent changesets: update to highest rev, similar to what | |
834 | # is currently done when there are more than one head |
|
837 | # is currently done when there are more than one head | |
835 | # (i.e. 'tip') |
|
838 | # (i.e. 'tip') | |
836 | # |
|
839 | # | |
837 | # replaced changesets: same as divergent except we know there |
|
840 | # replaced changesets: same as divergent except we know there | |
838 | # is no conflict |
|
841 | # is no conflict | |
839 | # |
|
842 | # | |
840 | # pruned changeset: no update is done; though, we could |
|
843 | # pruned changeset: no update is done; though, we could | |
841 | # consider updating to the first non-obsolete parent, |
|
844 | # consider updating to the first non-obsolete parent, | |
842 | # similar to what is current done for 'hg prune' |
|
845 | # similar to what is current done for 'hg prune' | |
843 |
|
846 | |||
844 | if successors: |
|
847 | if successors: | |
845 | # flatten the list here handles both divergent (len > 1) |
|
848 | # flatten the list here handles both divergent (len > 1) | |
846 | # and the usual case (len = 1) |
|
849 | # and the usual case (len = 1) | |
847 | successors = [n for sub in successors for n in sub] |
|
850 | successors = [n for sub in successors for n in sub] | |
848 |
|
851 | |||
849 | # get the max revision for the given successors set, |
|
852 | # get the max revision for the given successors set, | |
850 | # i.e. the 'tip' of a set |
|
853 | # i.e. the 'tip' of a set | |
851 | node = repo.revs("max(%ln)", successors)[0] |
|
854 | node = repo.revs("max(%ln)", successors)[0] | |
852 | pa = p1 |
|
855 | pa = p1 | |
853 |
|
856 | |||
854 | overwrite = force and not branchmerge |
|
857 | overwrite = force and not branchmerge | |
855 |
|
858 | |||
856 | p2 = repo[node] |
|
859 | p2 = repo[node] | |
857 | if pa is None: |
|
860 | if pa is None: | |
858 | pa = p1.ancestor(p2) |
|
861 | pa = p1.ancestor(p2) | |
859 |
|
862 | |||
860 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) |
|
863 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) | |
861 |
|
864 | |||
862 | ### check phase |
|
865 | ### check phase | |
863 | if not overwrite and len(pl) > 1: |
|
866 | if not overwrite and len(pl) > 1: | |
864 | raise util.Abort(_("outstanding uncommitted merges")) |
|
867 | raise util.Abort(_("outstanding uncommitted merges")) | |
865 | if branchmerge: |
|
868 | if branchmerge: | |
866 | if pa == p2: |
|
869 | if pa == p2: | |
867 | raise util.Abort(_("merging with a working directory ancestor" |
|
870 | raise util.Abort(_("merging with a working directory ancestor" | |
868 | " has no effect")) |
|
871 | " has no effect")) | |
869 | elif pa == p1: |
|
872 | elif pa == p1: | |
870 | if not mergeancestor and p1.branch() == p2.branch(): |
|
873 | if not mergeancestor and p1.branch() == p2.branch(): | |
871 | raise util.Abort(_("nothing to merge"), |
|
874 | raise util.Abort(_("nothing to merge"), | |
872 | hint=_("use 'hg update' " |
|
875 | hint=_("use 'hg update' " | |
873 | "or check 'hg heads'")) |
|
876 | "or check 'hg heads'")) | |
874 | if not force and (wc.files() or wc.deleted()): |
|
877 | if not force and (wc.files() or wc.deleted()): | |
875 | raise util.Abort(_("uncommitted changes"), |
|
878 | raise util.Abort(_("uncommitted changes"), | |
876 | hint=_("use 'hg status' to list changes")) |
|
879 | hint=_("use 'hg status' to list changes")) | |
877 | for s in sorted(wc.substate): |
|
880 | for s in sorted(wc.substate): | |
878 | if wc.sub(s).dirty(): |
|
881 | if wc.sub(s).dirty(): | |
879 | raise util.Abort(_("uncommitted changes in " |
|
882 | raise util.Abort(_("uncommitted changes in " | |
880 | "subrepository '%s'") % s) |
|
883 | "subrepository '%s'") % s) | |
881 |
|
884 | |||
882 | elif not overwrite: |
|
885 | elif not overwrite: | |
883 | if p1 == p2: # no-op update |
|
886 | if p1 == p2: # no-op update | |
884 | # call the hooks and exit early |
|
887 | # call the hooks and exit early | |
885 | repo.hook('preupdate', throw=True, parent1=xp2, parent2='') |
|
888 | repo.hook('preupdate', throw=True, parent1=xp2, parent2='') | |
886 | repo.hook('update', parent1=xp2, parent2='', error=0) |
|
889 | repo.hook('update', parent1=xp2, parent2='', error=0) | |
887 | return 0, 0, 0, 0 |
|
890 | return 0, 0, 0, 0 | |
888 |
|
891 | |||
889 | if pa not in (p1, p2): # nonlinear |
|
892 | if pa not in (p1, p2): # nonlinear | |
890 | dirty = wc.dirty(missing=True) |
|
893 | dirty = wc.dirty(missing=True) | |
891 | if dirty or onode is None: |
|
894 | if dirty or onode is None: | |
892 | # Branching is a bit strange to ensure we do the minimal |
|
895 | # Branching is a bit strange to ensure we do the minimal | |
893 | # amount of call to obsolete.background. |
|
896 | # amount of call to obsolete.background. | |
894 | foreground = obsolete.foreground(repo, [p1.node()]) |
|
897 | foreground = obsolete.foreground(repo, [p1.node()]) | |
895 | # note: the <node> variable contains a random identifier |
|
898 | # note: the <node> variable contains a random identifier | |
896 | if repo[node].node() in foreground: |
|
899 | if repo[node].node() in foreground: | |
897 | pa = p1 # allow updating to successors |
|
900 | pa = p1 # allow updating to successors | |
898 | elif dirty: |
|
901 | elif dirty: | |
899 | msg = _("uncommitted changes") |
|
902 | msg = _("uncommitted changes") | |
900 | if onode is None: |
|
903 | if onode is None: | |
901 | hint = _("commit and merge, or update --clean to" |
|
904 | hint = _("commit and merge, or update --clean to" | |
902 | " discard changes") |
|
905 | " discard changes") | |
903 | else: |
|
906 | else: | |
904 | hint = _("commit or update --clean to discard" |
|
907 | hint = _("commit or update --clean to discard" | |
905 | " changes") |
|
908 | " changes") | |
906 | raise util.Abort(msg, hint=hint) |
|
909 | raise util.Abort(msg, hint=hint) | |
907 | else: # node is none |
|
910 | else: # node is none | |
908 | msg = _("not a linear update") |
|
911 | msg = _("not a linear update") | |
909 | hint = _("merge or update --check to force update") |
|
912 | hint = _("merge or update --check to force update") | |
910 | raise util.Abort(msg, hint=hint) |
|
913 | raise util.Abort(msg, hint=hint) | |
911 | else: |
|
914 | else: | |
912 | # Allow jumping branches if clean and specific rev given |
|
915 | # Allow jumping branches if clean and specific rev given | |
913 | pa = p1 |
|
916 | pa = p1 | |
914 |
|
917 | |||
915 | ### calculate phase |
|
918 | ### calculate phase | |
916 | actions = calculateupdates(repo, wc, p2, pa, |
|
919 | actions = calculateupdates(repo, wc, p2, pa, | |
917 | branchmerge, force, partial, mergeancestor) |
|
920 | branchmerge, force, partial, mergeancestor) | |
918 |
|
921 | |||
919 | ### apply phase |
|
922 | ### apply phase | |
920 | if not branchmerge: # just jump to the new rev |
|
923 | if not branchmerge: # just jump to the new rev | |
921 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' |
|
924 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' | |
922 | if not partial: |
|
925 | if not partial: | |
923 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) |
|
926 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) | |
924 | # note that we're in the middle of an update |
|
927 | # note that we're in the middle of an update | |
925 | repo.vfs.write('updatestate', p2.hex()) |
|
928 | repo.vfs.write('updatestate', p2.hex()) | |
926 |
|
929 | |||
927 | stats = applyupdates(repo, actions, wc, p2, pa, overwrite) |
|
930 | stats = applyupdates(repo, actions, wc, p2, pa, overwrite) | |
928 |
|
931 | |||
929 | if not partial: |
|
932 | if not partial: | |
930 | repo.setparents(fp1, fp2) |
|
933 | repo.setparents(fp1, fp2) | |
931 | recordupdates(repo, actions, branchmerge) |
|
934 | recordupdates(repo, actions, branchmerge) | |
932 | # update completed, clear state |
|
935 | # update completed, clear state | |
933 | util.unlink(repo.join('updatestate')) |
|
936 | util.unlink(repo.join('updatestate')) | |
934 |
|
937 | |||
935 | if not branchmerge: |
|
938 | if not branchmerge: | |
936 | repo.dirstate.setbranch(p2.branch()) |
|
939 | repo.dirstate.setbranch(p2.branch()) | |
937 | finally: |
|
940 | finally: | |
938 | wlock.release() |
|
941 | wlock.release() | |
939 |
|
942 | |||
940 | if not partial: |
|
943 | if not partial: | |
941 | repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) |
|
944 | repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) | |
942 | return stats |
|
945 | return stats |
General Comments 0
You need to be logged in to leave comments.
Login now