Show More
@@ -1,352 +1,345 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 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from node import * |
|
8 | from node import * | |
9 | from i18n import gettext as _ |
|
9 | from i18n import gettext as _ | |
10 | from demandload import * |
|
10 | from demandload import * | |
11 | demandload(globals(), "errno util os tempfile") |
|
11 | demandload(globals(), "errno util os tempfile") | |
12 |
|
12 | |||
13 | def merge3(repo, fn, my, other, p1, p2): |
|
13 | def merge3(repo, fn, my, other, p1, p2): | |
14 | """perform a 3-way merge in the working directory""" |
|
14 | """perform a 3-way merge in the working directory""" | |
15 |
|
15 | |||
16 | def temp(prefix, node): |
|
16 | def temp(prefix, node): | |
17 | pre = "%s~%s." % (os.path.basename(fn), prefix) |
|
17 | pre = "%s~%s." % (os.path.basename(fn), prefix) | |
18 | (fd, name) = tempfile.mkstemp(prefix=pre) |
|
18 | (fd, name) = tempfile.mkstemp(prefix=pre) | |
19 | f = os.fdopen(fd, "wb") |
|
19 | f = os.fdopen(fd, "wb") | |
20 | repo.wwrite(fn, fl.read(node), f) |
|
20 | repo.wwrite(fn, fl.read(node), f) | |
21 | f.close() |
|
21 | f.close() | |
22 | return name |
|
22 | return name | |
23 |
|
23 | |||
24 | fl = repo.file(fn) |
|
24 | fl = repo.file(fn) | |
25 | base = fl.ancestor(my, other) |
|
25 | base = fl.ancestor(my, other) | |
26 | a = repo.wjoin(fn) |
|
26 | a = repo.wjoin(fn) | |
27 | b = temp("base", base) |
|
27 | b = temp("base", base) | |
28 | c = temp("other", other) |
|
28 | c = temp("other", other) | |
29 |
|
29 | |||
30 | repo.ui.note(_("resolving %s\n") % fn) |
|
30 | repo.ui.note(_("resolving %s\n") % fn) | |
31 | repo.ui.debug(_("file %s: my %s other %s ancestor %s\n") % |
|
31 | repo.ui.debug(_("file %s: my %s other %s ancestor %s\n") % | |
32 | (fn, short(my), short(other), short(base))) |
|
32 | (fn, short(my), short(other), short(base))) | |
33 |
|
33 | |||
34 | cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge") |
|
34 | cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge") | |
35 | or "hgmerge") |
|
35 | or "hgmerge") | |
36 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root, |
|
36 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root, | |
37 | environ={'HG_FILE': fn, |
|
37 | environ={'HG_FILE': fn, | |
38 | 'HG_MY_NODE': p1, |
|
38 | 'HG_MY_NODE': p1, | |
39 | 'HG_OTHER_NODE': p2, |
|
39 | 'HG_OTHER_NODE': p2, | |
40 | 'HG_FILE_MY_NODE': hex(my), |
|
40 | 'HG_FILE_MY_NODE': hex(my), | |
41 | 'HG_FILE_OTHER_NODE': hex(other), |
|
41 | 'HG_FILE_OTHER_NODE': hex(other), | |
42 | 'HG_FILE_BASE_NODE': hex(base)}) |
|
42 | 'HG_FILE_BASE_NODE': hex(base)}) | |
43 | if r: |
|
43 | if r: | |
44 | repo.ui.warn(_("merging %s failed!\n") % fn) |
|
44 | repo.ui.warn(_("merging %s failed!\n") % fn) | |
45 |
|
45 | |||
46 | os.unlink(b) |
|
46 | os.unlink(b) | |
47 | os.unlink(c) |
|
47 | os.unlink(c) | |
48 | return r |
|
48 | return r | |
49 |
|
49 | |||
50 | def checkunknown(repo, m2, status): |
|
50 | def checkunknown(repo, m2, status): | |
51 | """ |
|
51 | """ | |
52 | check for collisions between unknown files and files in m2 |
|
52 | check for collisions between unknown files and files in m2 | |
53 | """ |
|
53 | """ | |
54 | modified, added, removed, deleted, unknown = status[:5] |
|
54 | modified, added, removed, deleted, unknown = status[:5] | |
55 | for f in unknown: |
|
55 | for f in unknown: | |
56 | if f in m2: |
|
56 | if f in m2: | |
57 | if repo.file(f).cmp(m2[f], repo.wread(f)): |
|
57 | if repo.file(f).cmp(m2[f], repo.wread(f)): | |
58 | raise util.Abort(_("'%s' already exists in the working" |
|
58 | raise util.Abort(_("'%s' already exists in the working" | |
59 | " dir and differs from remote") % f) |
|
59 | " dir and differs from remote") % f) | |
60 |
|
60 | |||
61 | def workingmanifest(repo, man, status): |
|
61 | def workingmanifest(repo, man, status): | |
62 | """ |
|
62 | """ | |
63 | Update manifest to correspond to the working directory |
|
63 | Update manifest to correspond to the working directory | |
64 | """ |
|
64 | """ | |
65 |
|
65 | |||
66 | modified, added, removed, deleted, unknown = status[:5] |
|
66 | modified, added, removed, deleted, unknown = status[:5] | |
67 | for i,l in (("a", added), ("m", modified), ("u", unknown)): |
|
67 | for i,l in (("a", added), ("m", modified), ("u", unknown)): | |
68 | for f in l: |
|
68 | for f in l: | |
69 | man[f] = man.get(f, nullid) + i |
|
69 | man[f] = man.get(f, nullid) + i | |
70 | man.set(f, util.is_exec(repo.wjoin(f), man.execf(f))) |
|
70 | man.set(f, util.is_exec(repo.wjoin(f), man.execf(f))) | |
71 |
|
71 | |||
72 | for f in deleted + removed: |
|
72 | for f in deleted + removed: | |
73 | del man[f] |
|
73 | del man[f] | |
74 |
|
74 | |||
75 | return man |
|
75 | return man | |
76 |
|
76 | |||
77 | def forgetremoved(m2, status): |
|
77 | def forgetremoved(m2, status): | |
78 | """ |
|
78 | """ | |
79 | Forget removed files |
|
79 | Forget removed files | |
80 |
|
80 | |||
81 | If we're jumping between revisions (as opposed to merging), and if |
|
81 | If we're jumping between revisions (as opposed to merging), and if | |
82 | neither the working directory nor the target rev has the file, |
|
82 | neither the working directory nor the target rev has the file, | |
83 | then we need to remove it from the dirstate, to prevent the |
|
83 | then we need to remove it from the dirstate, to prevent the | |
84 | dirstate from listing the file when it is no longer in the |
|
84 | dirstate from listing the file when it is no longer in the | |
85 | manifest. |
|
85 | manifest. | |
86 | """ |
|
86 | """ | |
87 |
|
87 | |||
88 | modified, added, removed, deleted, unknown = status[:5] |
|
88 | modified, added, removed, deleted, unknown = status[:5] | |
89 | action = [] |
|
89 | action = [] | |
90 |
|
90 | |||
91 | for f in deleted + removed: |
|
91 | for f in deleted + removed: | |
92 | if f not in m2: |
|
92 | if f not in m2: | |
93 | action.append((f, "f")) |
|
93 | action.append((f, "f")) | |
94 |
|
94 | |||
95 | return action |
|
95 | return action | |
96 |
|
96 | |||
97 | def manifestmerge(ui, m1, m2, ma, overwrite, backwards, partial): |
|
97 | def manifestmerge(ui, m1, m2, ma, overwrite, backwards, partial): | |
98 | """ |
|
98 | """ | |
99 | Merge manifest m1 with m2 using ancestor ma and generate merge action list |
|
99 | Merge manifest m1 with m2 using ancestor ma and generate merge action list | |
100 | """ |
|
100 | """ | |
101 |
|
101 | |||
102 | def fmerge(f): |
|
102 | def fmerge(f): | |
103 | """merge executable flags""" |
|
103 | """merge executable flags""" | |
104 | a, b, c = ma.execf(f), m1.execf(f), m2.execf(f) |
|
104 | a, b, c = ma.execf(f), m1.execf(f), m2.execf(f) | |
105 | return ((a^b) | (a^c)) ^ a |
|
105 | return ((a^b) | (a^c)) ^ a | |
106 |
|
106 | |||
107 | action = [] |
|
107 | action = [] | |
108 |
|
108 | |||
109 | # Filter manifests |
|
109 | # Filter manifests | |
110 | if partial: |
|
110 | if partial: | |
111 | for f in m1.keys(): |
|
111 | for f in m1.keys(): | |
112 | if not partial(f): del m1[f] |
|
112 | if not partial(f): del m1[f] | |
113 | for f in m2.keys(): |
|
113 | for f in m2.keys(): | |
114 | if not partial(f): del m2[f] |
|
114 | if not partial(f): del m2[f] | |
115 |
|
115 | |||
116 | # Compare manifests |
|
116 | # Compare manifests | |
117 | for f, n in m1.iteritems(): |
|
117 | for f, n in m1.iteritems(): | |
118 | if f in m2: |
|
118 | if f in m2: | |
119 | # are files different? |
|
119 | # are files different? | |
120 | if n != m2[f]: |
|
120 | if n != m2[f]: | |
121 | a = ma.get(f, nullid) |
|
121 | a = ma.get(f, nullid) | |
122 | # are both different from the ancestor? |
|
122 | # are both different from the ancestor? | |
123 | if not overwrite and n != a and m2[f] != a: |
|
123 | if not overwrite and n != a and m2[f] != a: | |
124 | ui.debug(_(" %s versions differ, resolve\n") % f) |
|
124 | ui.debug(_(" %s versions differ, resolve\n") % f) | |
125 | action.append((f, "m", fmerge(f), n[:20], m2[f])) |
|
125 | action.append((f, "m", fmerge(f), n[:20], m2[f])) | |
126 | # are we clobbering? |
|
126 | # are we clobbering? | |
127 | # is remote's version newer? |
|
127 | # is remote's version newer? | |
128 | # or are we going back in time and clean? |
|
128 | # or are we going back in time and clean? | |
129 | elif overwrite or m2[f] != a or (backwards and not n[20:]): |
|
129 | elif overwrite or m2[f] != a or (backwards and not n[20:]): | |
130 | ui.debug(_(" remote %s is newer, get\n") % f) |
|
130 | ui.debug(_(" remote %s is newer, get\n") % f) | |
131 | action.append((f, "g", m2.execf(f), m2[f])) |
|
131 | action.append((f, "g", m2.execf(f), m2[f])) | |
132 | # local is newer, not overwrite, check mode bits |
|
132 | # local is newer, not overwrite, check mode bits | |
133 | elif fmerge(f) != m1.execf(f): |
|
133 | elif fmerge(f) != m1.execf(f): | |
134 | ui.debug(_(" updating permissions for %s\n") % f) |
|
134 | ui.debug(_(" updating permissions for %s\n") % f) | |
135 | action.append((f, "e", m2.execf(f))) |
|
135 | action.append((f, "e", m2.execf(f))) | |
136 |
|
||||
137 | # contents same, check mode bits |
|
136 | # contents same, check mode bits | |
138 | elif m1.execf(f) != m2.execf(f): |
|
137 | elif m1.execf(f) != m2.execf(f): | |
139 | if overwrite or fmerge(f) != m1.execf(f) |
|
138 | if overwrite or fmerge(f) != m1.execf(f): | |
140 | ui.debug(_(" updating permissions for %s\n") % f) |
|
139 | ui.debug(_(" updating permissions for %s\n") % f) | |
141 | action.append((f, "e", m2.execf(f))) |
|
140 | action.append((f, "e", m2.execf(f))) | |
142 | del m2[f] |
|
141 | del m2[f] | |
143 | elif f in ma: |
|
142 | elif f in ma: | |
144 | if n != ma[f] and not overwrite: |
|
143 | if n != ma[f] and not overwrite: | |
145 | if ui.prompt( |
|
144 | if ui.prompt( | |
146 | (_(" local changed %s which remote deleted\n") % f) + |
|
145 | (_(" local changed %s which remote deleted\n") % f) + | |
147 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): |
|
146 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): | |
148 | action.append((f, "r")) |
|
147 | action.append((f, "r")) | |
149 | else: |
|
148 | else: | |
150 | ui.debug(_("other deleted %s\n") % f) |
|
149 | ui.debug(_("other deleted %s\n") % f) | |
151 | action.append((f, "r")) |
|
150 | action.append((f, "r")) | |
152 | else: |
|
151 | else: | |
153 | # file is created on branch or in working directory |
|
152 | # file is created on branch or in working directory | |
154 | if overwrite and n[20:] != "u": |
|
153 | if (overwrite and n[20:] != "u") or (backwards and not n[20:]): | |
155 | ui.debug(_("remote deleted %s, clobbering\n") % f) |
|
154 | ui.debug(_("remote deleted %s, clobbering\n") % f) | |
156 | action.append((f, "r")) |
|
155 | action.append((f, "r")) | |
157 | elif not n[20:]: # same as parent |
|
|||
158 | if backwards: |
|
|||
159 | ui.debug(_("remote deleted %s\n") % f) |
|
|||
160 | action.append((f, "r")) |
|
|||
161 | else: |
|
|||
162 | ui.debug(_("local modified %s, keeping\n") % f) |
|
|||
163 | else: |
|
156 | else: | |
164 |
ui.debug(_(" |
|
157 | ui.debug(_("local created %s, keeping\n") % f) | |
165 |
|
158 | |||
166 | for f, n in m2.iteritems(): |
|
159 | for f, n in m2.iteritems(): | |
167 | if f in ma: |
|
160 | if f in ma: | |
168 | if overwrite or backwards: |
|
161 | if overwrite or backwards: | |
169 | ui.debug(_("local deleted %s, recreating\n") % f) |
|
162 | ui.debug(_("local deleted %s, recreating\n") % f) | |
170 | action.append((f, "g", m2.execf(f), n)) |
|
163 | action.append((f, "g", m2.execf(f), n)) | |
171 | elif n != ma[f]: |
|
164 | elif n != ma[f]: | |
172 | if ui.prompt( |
|
165 | if ui.prompt( | |
173 | (_("remote changed %s which local deleted\n") % f) + |
|
166 | (_("remote changed %s which local deleted\n") % f) + | |
174 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): |
|
167 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): | |
175 | action.append((f, "g", m2.execf(f), n)) |
|
168 | action.append((f, "g", m2.execf(f), n)) | |
176 | else: |
|
169 | else: | |
177 | ui.debug(_("local deleted %s\n") % f) |
|
170 | ui.debug(_("local deleted %s\n") % f) | |
178 | else: |
|
171 | else: | |
179 | ui.debug(_("remote created %s\n") % f) |
|
172 | ui.debug(_("remote created %s\n") % f) | |
180 | action.append((f, "g", m2.execf(f), n)) |
|
173 | action.append((f, "g", m2.execf(f), n)) | |
181 |
|
174 | |||
182 | return action |
|
175 | return action | |
183 |
|
176 | |||
184 | def applyupdates(repo, action, xp1, xp2): |
|
177 | def applyupdates(repo, action, xp1, xp2): | |
185 | updated, merged, removed, unresolved = 0, 0, 0, 0 |
|
178 | updated, merged, removed, unresolved = 0, 0, 0, 0 | |
186 | action.sort() |
|
179 | action.sort() | |
187 | for a in action: |
|
180 | for a in action: | |
188 | f, m = a[:2] |
|
181 | f, m = a[:2] | |
189 | if f[0] == "/": |
|
182 | if f[0] == "/": | |
190 | continue |
|
183 | continue | |
191 | if m == "r": # remove |
|
184 | if m == "r": # remove | |
192 | repo.ui.note(_("removing %s\n") % f) |
|
185 | repo.ui.note(_("removing %s\n") % f) | |
193 | util.audit_path(f) |
|
186 | util.audit_path(f) | |
194 | try: |
|
187 | try: | |
195 | util.unlink(repo.wjoin(f)) |
|
188 | util.unlink(repo.wjoin(f)) | |
196 | except OSError, inst: |
|
189 | except OSError, inst: | |
197 | if inst.errno != errno.ENOENT: |
|
190 | if inst.errno != errno.ENOENT: | |
198 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
191 | repo.ui.warn(_("update failed to remove %s: %s!\n") % | |
199 | (f, inst.strerror)) |
|
192 | (f, inst.strerror)) | |
200 | removed +=1 |
|
193 | removed +=1 | |
201 | elif m == "m": # merge |
|
194 | elif m == "m": # merge | |
202 | flag, my, other = a[2:] |
|
195 | flag, my, other = a[2:] | |
203 | repo.ui.status(_("merging %s\n") % f) |
|
196 | repo.ui.status(_("merging %s\n") % f) | |
204 | if merge3(repo, f, my, other, xp1, xp2): |
|
197 | if merge3(repo, f, my, other, xp1, xp2): | |
205 | unresolved += 1 |
|
198 | unresolved += 1 | |
206 | util.set_exec(repo.wjoin(f), flag) |
|
199 | util.set_exec(repo.wjoin(f), flag) | |
207 | merged += 1 |
|
200 | merged += 1 | |
208 | elif m == "g": # get |
|
201 | elif m == "g": # get | |
209 | flag, node = a[2:] |
|
202 | flag, node = a[2:] | |
210 | repo.ui.note(_("getting %s\n") % f) |
|
203 | repo.ui.note(_("getting %s\n") % f) | |
211 | t = repo.file(f).read(node) |
|
204 | t = repo.file(f).read(node) | |
212 | repo.wwrite(f, t) |
|
205 | repo.wwrite(f, t) | |
213 | util.set_exec(repo.wjoin(f), flag) |
|
206 | util.set_exec(repo.wjoin(f), flag) | |
214 | updated += 1 |
|
207 | updated += 1 | |
215 | elif m == "e": # exec |
|
208 | elif m == "e": # exec | |
216 | flag = a[2:] |
|
209 | flag = a[2:] | |
217 | util.set_exec(repo.wjoin(f), flag) |
|
210 | util.set_exec(repo.wjoin(f), flag) | |
218 |
|
211 | |||
219 | return updated, merged, removed, unresolved |
|
212 | return updated, merged, removed, unresolved | |
220 |
|
213 | |||
221 | def recordupdates(repo, action, branchmerge): |
|
214 | def recordupdates(repo, action, branchmerge): | |
222 | for a in action: |
|
215 | for a in action: | |
223 | f, m = a[:2] |
|
216 | f, m = a[:2] | |
224 | if m == "r": # remove |
|
217 | if m == "r": # remove | |
225 | if branchmerge: |
|
218 | if branchmerge: | |
226 | repo.dirstate.update([f], 'r') |
|
219 | repo.dirstate.update([f], 'r') | |
227 | else: |
|
220 | else: | |
228 | repo.dirstate.forget([f]) |
|
221 | repo.dirstate.forget([f]) | |
229 | elif m == "f": # forget |
|
222 | elif m == "f": # forget | |
230 | repo.dirstate.forget([f]) |
|
223 | repo.dirstate.forget([f]) | |
231 | elif m == "g": # get |
|
224 | elif m == "g": # get | |
232 | if branchmerge: |
|
225 | if branchmerge: | |
233 | repo.dirstate.update([f], 'n', st_mtime=-1) |
|
226 | repo.dirstate.update([f], 'n', st_mtime=-1) | |
234 | else: |
|
227 | else: | |
235 | repo.dirstate.update([f], 'n') |
|
228 | repo.dirstate.update([f], 'n') | |
236 | elif m == "m": # merge |
|
229 | elif m == "m": # merge | |
237 | flag, my, other = a[2:] |
|
230 | flag, my, other = a[2:] | |
238 | if branchmerge: |
|
231 | if branchmerge: | |
239 | # We've done a branch merge, mark this file as merged |
|
232 | # We've done a branch merge, mark this file as merged | |
240 | # so that we properly record the merger later |
|
233 | # so that we properly record the merger later | |
241 | repo.dirstate.update([f], 'm') |
|
234 | repo.dirstate.update([f], 'm') | |
242 | else: |
|
235 | else: | |
243 | # We've update-merged a locally modified file, so |
|
236 | # We've update-merged a locally modified file, so | |
244 | # we set the dirstate to emulate a normal checkout |
|
237 | # we set the dirstate to emulate a normal checkout | |
245 | # of that file some time in the past. Thus our |
|
238 | # of that file some time in the past. Thus our | |
246 | # merge will appear as a normal local file |
|
239 | # merge will appear as a normal local file | |
247 | # modification. |
|
240 | # modification. | |
248 | fl = repo.file(f) |
|
241 | fl = repo.file(f) | |
249 | f_len = fl.size(fl.rev(other)) |
|
242 | f_len = fl.size(fl.rev(other)) | |
250 | repo.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) |
|
243 | repo.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) | |
251 |
|
244 | |||
252 | def update(repo, node, branchmerge=False, force=False, partial=None, |
|
245 | def update(repo, node, branchmerge=False, force=False, partial=None, | |
253 | wlock=None, show_stats=True, remind=True): |
|
246 | wlock=None, show_stats=True, remind=True): | |
254 |
|
247 | |||
255 | overwrite = force and not branchmerge |
|
248 | overwrite = force and not branchmerge | |
256 | forcemerge = force and branchmerge |
|
249 | forcemerge = force and branchmerge | |
257 |
|
250 | |||
258 | if not wlock: |
|
251 | if not wlock: | |
259 | wlock = repo.wlock() |
|
252 | wlock = repo.wlock() | |
260 |
|
253 | |||
261 | ### check phase |
|
254 | ### check phase | |
262 |
|
255 | |||
263 | pl = repo.dirstate.parents() |
|
256 | pl = repo.dirstate.parents() | |
264 | if not overwrite and pl[1] != nullid: |
|
257 | if not overwrite and pl[1] != nullid: | |
265 | raise util.Abort(_("outstanding uncommitted merges")) |
|
258 | raise util.Abort(_("outstanding uncommitted merges")) | |
266 |
|
259 | |||
267 | p1, p2 = pl[0], node |
|
260 | p1, p2 = pl[0], node | |
268 | pa = repo.changelog.ancestor(p1, p2) |
|
261 | pa = repo.changelog.ancestor(p1, p2) | |
269 |
|
262 | |||
270 | # are we going backwards? |
|
263 | # are we going backwards? | |
271 | backwards = (pa == p2) |
|
264 | backwards = (pa == p2) | |
272 |
|
265 | |||
273 | # is there a linear path from p1 to p2? |
|
266 | # is there a linear path from p1 to p2? | |
274 | if pa == p1 or pa == p2: |
|
267 | if pa == p1 or pa == p2: | |
275 | if branchmerge: |
|
268 | if branchmerge: | |
276 | raise util.Abort(_("there is nothing to merge, just use " |
|
269 | raise util.Abort(_("there is nothing to merge, just use " | |
277 | "'hg update' or look at 'hg heads'")) |
|
270 | "'hg update' or look at 'hg heads'")) | |
278 | elif not (overwrite or branchmerge): |
|
271 | elif not (overwrite or branchmerge): | |
279 | raise util.Abort(_("update spans branches, use 'hg merge' " |
|
272 | raise util.Abort(_("update spans branches, use 'hg merge' " | |
280 | "or 'hg update -C' to lose changes")) |
|
273 | "or 'hg update -C' to lose changes")) | |
281 |
|
274 | |||
282 | status = repo.status() |
|
275 | status = repo.status() | |
283 | modified, added, removed, deleted, unknown = status[:5] |
|
276 | modified, added, removed, deleted, unknown = status[:5] | |
284 | if branchmerge and not forcemerge: |
|
277 | if branchmerge and not forcemerge: | |
285 | if modified or added or removed: |
|
278 | if modified or added or removed: | |
286 | raise util.Abort(_("outstanding uncommitted changes")) |
|
279 | raise util.Abort(_("outstanding uncommitted changes")) | |
287 |
|
280 | |||
288 | m1 = repo.changectx(p1).manifest().copy() |
|
281 | m1 = repo.changectx(p1).manifest().copy() | |
289 | m2 = repo.changectx(p2).manifest().copy() |
|
282 | m2 = repo.changectx(p2).manifest().copy() | |
290 | ma = repo.changectx(pa).manifest() |
|
283 | ma = repo.changectx(pa).manifest() | |
291 |
|
284 | |||
292 | # resolve the manifest to determine which files |
|
285 | # resolve the manifest to determine which files | |
293 | # we care about merging |
|
286 | # we care about merging | |
294 | repo.ui.note(_("resolving manifests\n")) |
|
287 | repo.ui.note(_("resolving manifests\n")) | |
295 | repo.ui.debug(_(" overwrite %s branchmerge %s partial %s\n") % |
|
288 | repo.ui.debug(_(" overwrite %s branchmerge %s partial %s\n") % | |
296 | (overwrite, branchmerge, bool(partial))) |
|
289 | (overwrite, branchmerge, bool(partial))) | |
297 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % |
|
290 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % | |
298 | (short(p1), short(p2), short(pa))) |
|
291 | (short(p1), short(p2), short(pa))) | |
299 |
|
292 | |||
300 | action = [] |
|
293 | action = [] | |
301 | m1 = workingmanifest(repo, m1, status) |
|
294 | m1 = workingmanifest(repo, m1, status) | |
302 |
|
295 | |||
303 | if not force: |
|
296 | if not force: | |
304 | checkunknown(repo, m2, status) |
|
297 | checkunknown(repo, m2, status) | |
305 | if not branchmerge: |
|
298 | if not branchmerge: | |
306 | action += forgetremoved(m2, status) |
|
299 | action += forgetremoved(m2, status) | |
307 | action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards, partial) |
|
300 | action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards, partial) | |
308 | del m1, m2, ma |
|
301 | del m1, m2, ma | |
309 |
|
302 | |||
310 | ### apply phase |
|
303 | ### apply phase | |
311 |
|
304 | |||
312 | if not branchmerge: |
|
305 | if not branchmerge: | |
313 | # we don't need to do any magic, just jump to the new rev |
|
306 | # we don't need to do any magic, just jump to the new rev | |
314 | p1, p2 = p2, nullid |
|
307 | p1, p2 = p2, nullid | |
315 |
|
308 | |||
316 | xp1, xp2 = hex(p1), hex(p2) |
|
309 | xp1, xp2 = hex(p1), hex(p2) | |
317 | if p2 == nullid: xp2 = '' |
|
310 | if p2 == nullid: xp2 = '' | |
318 |
|
311 | |||
319 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) |
|
312 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) | |
320 |
|
313 | |||
321 | updated, merged, removed, unresolved = applyupdates(repo, action, xp1, xp2) |
|
314 | updated, merged, removed, unresolved = applyupdates(repo, action, xp1, xp2) | |
322 |
|
315 | |||
323 | # update dirstate |
|
316 | # update dirstate | |
324 | if not partial: |
|
317 | if not partial: | |
325 | repo.dirstate.setparents(p1, p2) |
|
318 | repo.dirstate.setparents(p1, p2) | |
326 | recordupdates(repo, action, branchmerge) |
|
319 | recordupdates(repo, action, branchmerge) | |
327 |
|
320 | |||
328 | if show_stats: |
|
321 | if show_stats: | |
329 | stats = ((updated, _("updated")), |
|
322 | stats = ((updated, _("updated")), | |
330 | (merged - unresolved, _("merged")), |
|
323 | (merged - unresolved, _("merged")), | |
331 | (removed, _("removed")), |
|
324 | (removed, _("removed")), | |
332 | (unresolved, _("unresolved"))) |
|
325 | (unresolved, _("unresolved"))) | |
333 | note = ", ".join([_("%d files %s") % s for s in stats]) |
|
326 | note = ", ".join([_("%d files %s") % s for s in stats]) | |
334 | repo.ui.status("%s\n" % note) |
|
327 | repo.ui.status("%s\n" % note) | |
335 | if not partial: |
|
328 | if not partial: | |
336 | if branchmerge: |
|
329 | if branchmerge: | |
337 | if unresolved: |
|
330 | if unresolved: | |
338 | repo.ui.status(_("There are unresolved merges," |
|
331 | repo.ui.status(_("There are unresolved merges," | |
339 | " you can redo the full merge using:\n" |
|
332 | " you can redo the full merge using:\n" | |
340 | " hg update -C %s\n" |
|
333 | " hg update -C %s\n" | |
341 | " hg merge %s\n" |
|
334 | " hg merge %s\n" | |
342 | % (repo.changelog.rev(p1), |
|
335 | % (repo.changelog.rev(p1), | |
343 | repo.changelog.rev(p2)))) |
|
336 | repo.changelog.rev(p2)))) | |
344 | elif remind: |
|
337 | elif remind: | |
345 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
|
338 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) | |
346 | elif unresolved: |
|
339 | elif unresolved: | |
347 | repo.ui.status(_("There are unresolved merges with" |
|
340 | repo.ui.status(_("There are unresolved merges with" | |
348 | " locally modified files.\n")) |
|
341 | " locally modified files.\n")) | |
349 |
|
342 | |||
350 | repo.hook('update', parent1=xp1, parent2=xp2, error=unresolved) |
|
343 | repo.hook('update', parent1=xp1, parent2=xp2, error=unresolved) | |
351 | return unresolved |
|
344 | return unresolved | |
352 |
|
345 |
@@ -1,141 +1,141 b'' | |||||
1 | adding a |
|
1 | adding a | |
2 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
2 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
3 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
3 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
4 | diff -r 33aaa84a386b a |
|
4 | diff -r 33aaa84a386b a | |
5 | --- a/a |
|
5 | --- a/a | |
6 | +++ b/a |
|
6 | +++ b/a | |
7 | @@ -1,1 +1,1 @@ a |
|
7 | @@ -1,1 +1,1 @@ a | |
8 | -a |
|
8 | -a | |
9 | +abc |
|
9 | +abc | |
10 | adding b |
|
10 | adding b | |
11 | M a |
|
11 | M a | |
12 | changeset: 0:33aaa84a386b |
|
12 | changeset: 0:33aaa84a386b | |
13 | user: test |
|
13 | user: test | |
14 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
14 | date: Mon Jan 12 13:46:40 1970 +0000 | |
15 | summary: 1 |
|
15 | summary: 1 | |
16 |
|
16 | |||
17 | resolving manifests |
|
17 | resolving manifests | |
18 | overwrite False branchmerge False partial False |
|
18 | overwrite False branchmerge False partial False | |
19 | ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b |
|
19 | ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b | |
20 | a versions differ, resolve |
|
20 | a versions differ, resolve | |
21 | remote created b |
|
21 | remote created b | |
22 | merging a |
|
22 | merging a | |
23 | resolving a |
|
23 | resolving a | |
24 | file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 |
|
24 | file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 | |
25 | getting b |
|
25 | getting b | |
26 | 1 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
26 | 1 files updated, 1 files merged, 0 files removed, 0 files unresolved | |
27 | changeset: 1:802f095af299 |
|
27 | changeset: 1:802f095af299 | |
28 | tag: tip |
|
28 | tag: tip | |
29 | user: test |
|
29 | user: test | |
30 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
30 | date: Mon Jan 12 13:46:40 1970 +0000 | |
31 | summary: 2 |
|
31 | summary: 2 | |
32 |
|
32 | |||
33 | resolving manifests |
|
33 | resolving manifests | |
34 | overwrite False branchmerge False partial False |
|
34 | overwrite False branchmerge False partial False | |
35 | ancestor 802f095af299 local 33aaa84a386b remote 33aaa84a386b |
|
35 | ancestor 802f095af299 local 33aaa84a386b remote 33aaa84a386b | |
36 | remote deleted b |
|
36 | remote deleted b, clobbering | |
37 | removing b |
|
37 | removing b | |
38 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
38 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
39 | changeset: 0:33aaa84a386b |
|
39 | changeset: 0:33aaa84a386b | |
40 | user: test |
|
40 | user: test | |
41 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
41 | date: Mon Jan 12 13:46:40 1970 +0000 | |
42 | summary: 1 |
|
42 | summary: 1 | |
43 |
|
43 | |||
44 | abort: there is nothing to merge - use "hg update" instead |
|
44 | abort: there is nothing to merge - use "hg update" instead | |
45 | failed |
|
45 | failed | |
46 | changeset: 0:33aaa84a386b |
|
46 | changeset: 0:33aaa84a386b | |
47 | user: test |
|
47 | user: test | |
48 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
48 | date: Mon Jan 12 13:46:40 1970 +0000 | |
49 | summary: 1 |
|
49 | summary: 1 | |
50 |
|
50 | |||
51 | resolving manifests |
|
51 | resolving manifests | |
52 | overwrite False branchmerge False partial False |
|
52 | overwrite False branchmerge False partial False | |
53 | ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b |
|
53 | ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b | |
54 | a versions differ, resolve |
|
54 | a versions differ, resolve | |
55 | remote created b |
|
55 | remote created b | |
56 | merging a |
|
56 | merging a | |
57 | resolving a |
|
57 | resolving a | |
58 | file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 |
|
58 | file a: my b789fdd96dc2 other d730145abbf9 ancestor b789fdd96dc2 | |
59 | getting b |
|
59 | getting b | |
60 | 1 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
60 | 1 files updated, 1 files merged, 0 files removed, 0 files unresolved | |
61 | changeset: 1:802f095af299 |
|
61 | changeset: 1:802f095af299 | |
62 | tag: tip |
|
62 | tag: tip | |
63 | user: test |
|
63 | user: test | |
64 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
64 | date: Mon Jan 12 13:46:40 1970 +0000 | |
65 | summary: 2 |
|
65 | summary: 2 | |
66 |
|
66 | |||
67 | changeset: 1:802f095af299 |
|
67 | changeset: 1:802f095af299 | |
68 | tag: tip |
|
68 | tag: tip | |
69 | user: test |
|
69 | user: test | |
70 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
70 | date: Mon Jan 12 13:46:40 1970 +0000 | |
71 | files: a b |
|
71 | files: a b | |
72 | description: |
|
72 | description: | |
73 | 2 |
|
73 | 2 | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | changeset: 0:33aaa84a386b |
|
76 | changeset: 0:33aaa84a386b | |
77 | user: test |
|
77 | user: test | |
78 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
78 | date: Mon Jan 12 13:46:40 1970 +0000 | |
79 | files: a |
|
79 | files: a | |
80 | description: |
|
80 | description: | |
81 | 1 |
|
81 | 1 | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | diff -r 802f095af299 a |
|
84 | diff -r 802f095af299 a | |
85 | --- a/a |
|
85 | --- a/a | |
86 | +++ b/a |
|
86 | +++ b/a | |
87 | @@ -1,1 +1,1 @@ a2 |
|
87 | @@ -1,1 +1,1 @@ a2 | |
88 | -a2 |
|
88 | -a2 | |
89 | +abc |
|
89 | +abc | |
90 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
90 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
91 | adding b |
|
91 | adding b | |
92 | M a |
|
92 | M a | |
93 | changeset: 1:802f095af299 |
|
93 | changeset: 1:802f095af299 | |
94 | user: test |
|
94 | user: test | |
95 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
95 | date: Mon Jan 12 13:46:40 1970 +0000 | |
96 | summary: 2 |
|
96 | summary: 2 | |
97 |
|
97 | |||
98 | abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes |
|
98 | abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes | |
99 | failed |
|
99 | failed | |
100 | abort: outstanding uncommitted changes |
|
100 | abort: outstanding uncommitted changes | |
101 | failed |
|
101 | failed | |
102 | resolving manifests |
|
102 | resolving manifests | |
103 | overwrite False branchmerge True partial False |
|
103 | overwrite False branchmerge True partial False | |
104 | ancestor 802f095af299 local 030602aee63d remote 33aaa84a386b |
|
104 | ancestor 802f095af299 local 030602aee63d remote 33aaa84a386b | |
105 | a versions differ, resolve |
|
105 | a versions differ, resolve | |
106 | b versions differ, resolve |
|
106 | b versions differ, resolve | |
107 | merging a |
|
107 | merging a | |
108 | resolving a |
|
108 | resolving a | |
109 | file a: my d730145abbf9 other 13e0d5f949fa ancestor b789fdd96dc2 |
|
109 | file a: my d730145abbf9 other 13e0d5f949fa ancestor b789fdd96dc2 | |
110 | merging b |
|
110 | merging b | |
111 | resolving b |
|
111 | resolving b | |
112 | file b: my 1e88685f5dde other 61de8c7723ca ancestor 000000000000 |
|
112 | file b: my 1e88685f5dde other 61de8c7723ca ancestor 000000000000 | |
113 | 0 files updated, 2 files merged, 0 files removed, 0 files unresolved |
|
113 | 0 files updated, 2 files merged, 0 files removed, 0 files unresolved | |
114 | (branch merge, don't forget to commit) |
|
114 | (branch merge, don't forget to commit) | |
115 | changeset: 1:802f095af299 |
|
115 | changeset: 1:802f095af299 | |
116 | user: test |
|
116 | user: test | |
117 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
117 | date: Mon Jan 12 13:46:40 1970 +0000 | |
118 | summary: 2 |
|
118 | summary: 2 | |
119 |
|
119 | |||
120 | changeset: 2:030602aee63d |
|
120 | changeset: 2:030602aee63d | |
121 | tag: tip |
|
121 | tag: tip | |
122 | parent: 0:33aaa84a386b |
|
122 | parent: 0:33aaa84a386b | |
123 | user: test |
|
123 | user: test | |
124 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
124 | date: Mon Jan 12 13:46:40 1970 +0000 | |
125 | summary: 3 |
|
125 | summary: 3 | |
126 |
|
126 | |||
127 | diff -r 802f095af299 a |
|
127 | diff -r 802f095af299 a | |
128 | --- a/a |
|
128 | --- a/a | |
129 | +++ b/a |
|
129 | +++ b/a | |
130 | @@ -1,1 +1,1 @@ a2 |
|
130 | @@ -1,1 +1,1 @@ a2 | |
131 | -a2 |
|
131 | -a2 | |
132 | +abc |
|
132 | +abc | |
133 | adding a |
|
133 | adding a | |
134 | pulling from ../a |
|
134 | pulling from ../a | |
135 | requesting all changes |
|
135 | requesting all changes | |
136 | adding changesets |
|
136 | adding changesets | |
137 | adding manifests |
|
137 | adding manifests | |
138 | adding file changes |
|
138 | adding file changes | |
139 | added 1 changesets with 1 changes to 1 files |
|
139 | added 1 changesets with 1 changes to 1 files | |
140 | merging a |
|
140 | merging a | |
141 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
141 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
General Comments 0
You need to be logged in to leave comments.
Login now