Show More
@@ -1,417 +1,408 | |||||
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 filemerge(repo, fw, fo, wctx, mctx): |
|
13 | def filemerge(repo, fw, fo, wctx, mctx): | |
14 | """perform a 3-way merge in the working directory |
|
14 | """perform a 3-way merge in the working directory | |
15 |
|
15 | |||
16 | fw = filename in the working directory |
|
16 | fw = filename in the working directory | |
17 | fo = filename in other parent |
|
17 | fo = filename in other parent | |
18 | wctx, mctx = working and merge changecontexts |
|
18 | wctx, mctx = working and merge changecontexts | |
19 | """ |
|
19 | """ | |
20 |
|
20 | |||
21 | def temp(prefix, ctx): |
|
21 | def temp(prefix, ctx): | |
22 | pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) |
|
22 | pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) | |
23 | (fd, name) = tempfile.mkstemp(prefix=pre) |
|
23 | (fd, name) = tempfile.mkstemp(prefix=pre) | |
24 | f = os.fdopen(fd, "wb") |
|
24 | f = os.fdopen(fd, "wb") | |
25 | repo.wwrite(ctx.path(), ctx.data(), f) |
|
25 | repo.wwrite(ctx.path(), ctx.data(), f) | |
26 | f.close() |
|
26 | f.close() | |
27 | return name |
|
27 | return name | |
28 |
|
28 | |||
29 | fcm = wctx.filectx(fw) |
|
29 | fcm = wctx.filectx(fw) | |
30 | fco = mctx.filectx(fo) |
|
30 | fco = mctx.filectx(fo) | |
31 |
|
31 | |||
32 | if not fco.cmp(fcm.data()): # files identical? |
|
32 | if not fco.cmp(fcm.data()): # files identical? | |
33 | return None |
|
33 | return None | |
34 |
|
34 | |||
35 | fca = fcm.ancestor(fco) |
|
35 | fca = fcm.ancestor(fco) | |
36 | if not fca: |
|
36 | if not fca: | |
37 | fca = repo.filectx(fw, fileid=nullrev) |
|
37 | fca = repo.filectx(fw, fileid=nullrev) | |
38 | a = repo.wjoin(fw) |
|
38 | a = repo.wjoin(fw) | |
39 | b = temp("base", fca) |
|
39 | b = temp("base", fca) | |
40 | c = temp("other", fco) |
|
40 | c = temp("other", fco) | |
41 |
|
41 | |||
42 | if fw != fo: |
|
42 | if fw != fo: | |
43 | repo.ui.status(_("merging %s and %s\n") % (fw, fo)) |
|
43 | repo.ui.status(_("merging %s and %s\n") % (fw, fo)) | |
44 | else: |
|
44 | else: | |
45 | repo.ui.status(_("merging %s\n") % fw) |
|
45 | repo.ui.status(_("merging %s\n") % fw) | |
46 |
|
46 | |||
47 | repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca)) |
|
47 | repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca)) | |
48 |
|
48 | |||
49 | cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge") |
|
49 | cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge") | |
50 | or "hgmerge") |
|
50 | or "hgmerge") | |
51 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root, |
|
51 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root, | |
52 | environ={'HG_FILE': fw, |
|
52 | environ={'HG_FILE': fw, | |
53 | 'HG_MY_NODE': str(wctx.parents()[0]), |
|
53 | 'HG_MY_NODE': str(wctx.parents()[0]), | |
54 | 'HG_OTHER_NODE': str(mctx)}) |
|
54 | 'HG_OTHER_NODE': str(mctx)}) | |
55 | if r: |
|
55 | if r: | |
56 | repo.ui.warn(_("merging %s failed!\n") % fw) |
|
56 | repo.ui.warn(_("merging %s failed!\n") % fw) | |
57 |
|
57 | |||
58 | os.unlink(b) |
|
58 | os.unlink(b) | |
59 | os.unlink(c) |
|
59 | os.unlink(c) | |
60 | return r |
|
60 | return r | |
61 |
|
61 | |||
62 | def checkunknown(wctx, mctx): |
|
62 | def checkunknown(wctx, mctx): | |
63 | "check for collisions between unknown files and files in mctx" |
|
63 | "check for collisions between unknown files and files in mctx" | |
64 | man = mctx.manifest() |
|
64 | man = mctx.manifest() | |
65 | for f in wctx.unknown(): |
|
65 | for f in wctx.unknown(): | |
66 | if f in man: |
|
66 | if f in man: | |
67 | if mctx.filectx(f).cmp(wctx.filectx(f).data()): |
|
67 | if mctx.filectx(f).cmp(wctx.filectx(f).data()): | |
68 | raise util.Abort(_("untracked local file '%s' differs"\ |
|
68 | raise util.Abort(_("untracked local file '%s' differs"\ | |
69 | " from remote version") % f) |
|
69 | " from remote version") % f) | |
70 |
|
70 | |||
71 | def forgetremoved(wctx, mctx): |
|
71 | def forgetremoved(wctx, mctx): | |
72 | """ |
|
72 | """ | |
73 | Forget removed files |
|
73 | Forget removed files | |
74 |
|
74 | |||
75 | If we're jumping between revisions (as opposed to merging), and if |
|
75 | If we're jumping between revisions (as opposed to merging), and if | |
76 | neither the working directory nor the target rev has the file, |
|
76 | neither the working directory nor the target rev has the file, | |
77 | then we need to remove it from the dirstate, to prevent the |
|
77 | then we need to remove it from the dirstate, to prevent the | |
78 | dirstate from listing the file when it is no longer in the |
|
78 | dirstate from listing the file when it is no longer in the | |
79 | manifest. |
|
79 | manifest. | |
80 | """ |
|
80 | """ | |
81 |
|
81 | |||
82 | action = [] |
|
82 | action = [] | |
83 | man = mctx.manifest() |
|
83 | man = mctx.manifest() | |
84 | for f in wctx.deleted() + wctx.removed(): |
|
84 | for f in wctx.deleted() + wctx.removed(): | |
85 | if f not in man: |
|
85 | if f not in man: | |
86 | action.append((f, "f")) |
|
86 | action.append((f, "f")) | |
87 |
|
87 | |||
88 | return action |
|
88 | return action | |
89 |
|
89 | |||
90 | def nonoverlap(d1, d2, d3): |
|
90 | def findcopies(repo, m1, m2, ma, limit): | |
91 | "Return list of elements in d1 not in d2 or d3" |
|
91 | """ | |
|
92 | Find moves and copies between m1 and m2 back to limit linkrev | |||
|
93 | """ | |||
92 |
|
94 | |||
93 | l = [] |
|
95 | def findold(fctx): | |
94 | for d in d1: |
|
|||
95 | if d not in d3 and d not in d2: |
|
|||
96 | l.append(d) |
|
|||
97 |
|
||||
98 | l.sort() |
|
|||
99 | return l |
|
|||
100 |
|
||||
101 | def findold(fctx, limit): |
|
|||
102 | "find files that path was copied from, back to linkrev limit" |
|
96 | "find files that path was copied from, back to linkrev limit" | |
103 |
|
||||
104 | old = {} |
|
97 | old = {} | |
105 | orig = fctx.path() |
|
98 | orig = fctx.path() | |
106 | visit = [fctx] |
|
99 | visit = [fctx] | |
107 | while visit: |
|
100 | while visit: | |
108 | fc = visit.pop() |
|
101 | fc = visit.pop() | |
109 | if fc.rev() < limit: |
|
102 | if fc.rev() < limit: | |
110 | continue |
|
103 | continue | |
111 | if fc.path() != orig and fc.path() not in old: |
|
104 | if fc.path() != orig and fc.path() not in old: | |
112 | old[fc.path()] = 1 |
|
105 | old[fc.path()] = 1 | |
113 | visit += fc.parents() |
|
106 | visit += fc.parents() | |
114 |
|
107 | |||
115 | old = old.keys() |
|
108 | old = old.keys() | |
116 | old.sort() |
|
109 | old.sort() | |
117 | return old |
|
110 | return old | |
118 |
|
111 | |||
119 | def findcopies(repo, m1, m2, ma, limit): |
|
112 | def nonoverlap(d1, d2, d3): | |
120 | """ |
|
113 | "Return list of elements in d1 not in d2 or d3" | |
121 | Find moves and copies between m1 and m2 back to limit linkrev |
|
114 | l = [d for d in d1 if d not in d3 and d not in d2] | |
122 | """ |
|
115 | l.sort() | |
|
116 | return l | |||
|
117 | ||||
|
118 | def checkcopies(c, man): | |||
|
119 | '''check possible copies for filectx c''' | |||
|
120 | for of in findold(c): | |||
|
121 | if of not in man: | |||
|
122 | return | |||
|
123 | c2 = ctx(of, man[of]) | |||
|
124 | ca = c.ancestor(c2) | |||
|
125 | if not ca or c == ca or c2 == ca: | |||
|
126 | return | |||
|
127 | if ca.path() == c.path() or ca.path() == c2.path(): | |||
|
128 | copy[c.path()] = of | |||
123 |
|
129 | |||
124 | if not repo.ui.configbool("merge", "followcopies", True): |
|
130 | if not repo.ui.configbool("merge", "followcopies", True): | |
125 | return {} |
|
131 | return {} | |
126 |
|
132 | |||
127 | # avoid silly behavior for update from empty dir |
|
133 | # avoid silly behavior for update from empty dir | |
128 | if not m1 or not m2 or not ma: |
|
134 | if not m1 or not m2 or not ma: | |
129 | return {} |
|
135 | return {} | |
130 |
|
136 | |||
131 | dcopies = repo.dirstate.copies() |
|
137 | dcopies = repo.dirstate.copies() | |
132 | copy = {} |
|
138 | copy = {} | |
133 | u1 = nonoverlap(m1, m2, ma) |
|
139 | u1 = nonoverlap(m1, m2, ma) | |
134 | u2 = nonoverlap(m2, m1, ma) |
|
140 | u2 = nonoverlap(m2, m1, ma) | |
135 | ctx = util.cachefunc(lambda f, n: repo.filectx(f, fileid=n[:20])) |
|
141 | ctx = util.cachefunc(lambda f, n: repo.filectx(f, fileid=n[:20])) | |
136 |
|
142 | |||
137 | def checkpair(c, f2, man): |
|
|||
138 | ''' check if an apparent pair actually matches ''' |
|
|||
139 | if f2 not in man: |
|
|||
140 | return |
|
|||
141 | c2 = ctx(f2, man[f2]) |
|
|||
142 | ca = c.ancestor(c2) |
|
|||
143 | if not ca or c == ca or c2 == ca: |
|
|||
144 | return |
|
|||
145 | if ca.path() == c.path() or ca.path() == c2.path(): |
|
|||
146 | copy[c.path()] = f2 |
|
|||
147 |
|
||||
148 | for f in u1: |
|
143 | for f in u1: | |
149 |
c |
|
144 | checkcopies(ctx(dcopies.get(f, f), m1[f]), m2) | |
150 | for of in findold(c, limit): |
|
|||
151 | checkpair(c, of, m2) |
|
|||
152 |
|
145 | |||
153 | for f in u2: |
|
146 | for f in u2: | |
154 |
c |
|
147 | checkcopies(ctx(f, m2[f]), m1) | |
155 | for of in findold(c, limit): |
|
|||
156 | checkpair(c, of, m1) |
|
|||
157 |
|
148 | |||
158 | return copy |
|
149 | return copy | |
159 |
|
150 | |||
160 | def manifestmerge(repo, p1, p2, pa, overwrite, partial): |
|
151 | def manifestmerge(repo, p1, p2, pa, overwrite, partial): | |
161 | """ |
|
152 | """ | |
162 | Merge p1 and p2 with ancestor ma and generate merge action list |
|
153 | Merge p1 and p2 with ancestor ma and generate merge action list | |
163 |
|
154 | |||
164 | overwrite = whether we clobber working files |
|
155 | overwrite = whether we clobber working files | |
165 | partial = function to filter file lists |
|
156 | partial = function to filter file lists | |
166 | """ |
|
157 | """ | |
167 |
|
158 | |||
168 | repo.ui.note(_("resolving manifests\n")) |
|
159 | repo.ui.note(_("resolving manifests\n")) | |
169 | repo.ui.debug(_(" overwrite %s partial %s\n") % (overwrite, bool(partial))) |
|
160 | repo.ui.debug(_(" overwrite %s partial %s\n") % (overwrite, bool(partial))) | |
170 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (pa, p1, p2)) |
|
161 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (pa, p1, p2)) | |
171 |
|
162 | |||
172 | m1 = p1.manifest() |
|
163 | m1 = p1.manifest() | |
173 | m2 = p2.manifest() |
|
164 | m2 = p2.manifest() | |
174 | ma = pa.manifest() |
|
165 | ma = pa.manifest() | |
175 | backwards = (pa == p2) |
|
166 | backwards = (pa == p2) | |
176 | action = [] |
|
167 | action = [] | |
177 | copy = {} |
|
168 | copy = {} | |
178 |
|
169 | |||
179 | def fmerge(f, f2=None, fa=None): |
|
170 | def fmerge(f, f2=None, fa=None): | |
180 | """merge executable flags""" |
|
171 | """merge executable flags""" | |
181 | if not f2: |
|
172 | if not f2: | |
182 | f2 = f |
|
173 | f2 = f | |
183 | fa = f |
|
174 | fa = f | |
184 | a, b, c = ma.execf(fa), m1.execf(f), m2.execf(f2) |
|
175 | a, b, c = ma.execf(fa), m1.execf(f), m2.execf(f2) | |
185 | return ((a^b) | (a^c)) ^ a |
|
176 | return ((a^b) | (a^c)) ^ a | |
186 |
|
177 | |||
187 | def act(msg, m, f, *args): |
|
178 | def act(msg, m, f, *args): | |
188 | repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m)) |
|
179 | repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m)) | |
189 | action.append((f, m) + args) |
|
180 | action.append((f, m) + args) | |
190 |
|
181 | |||
191 | if not (backwards or overwrite): |
|
182 | if not (backwards or overwrite): | |
192 | copy = findcopies(repo, m1, m2, ma, pa.rev()) |
|
183 | copy = findcopies(repo, m1, m2, ma, pa.rev()) | |
193 | copied = dict.fromkeys(copy.values()) |
|
184 | copied = dict.fromkeys(copy.values()) | |
194 |
|
185 | |||
195 | # Compare manifests |
|
186 | # Compare manifests | |
196 | for f, n in m1.iteritems(): |
|
187 | for f, n in m1.iteritems(): | |
197 | if partial and not partial(f): |
|
188 | if partial and not partial(f): | |
198 | continue |
|
189 | continue | |
199 | if f in m2: |
|
190 | if f in m2: | |
200 | # are files different? |
|
191 | # are files different? | |
201 | if n != m2[f]: |
|
192 | if n != m2[f]: | |
202 | a = ma.get(f, nullid) |
|
193 | a = ma.get(f, nullid) | |
203 | # are both different from the ancestor? |
|
194 | # are both different from the ancestor? | |
204 | if not overwrite and n != a and m2[f] != a: |
|
195 | if not overwrite and n != a and m2[f] != a: | |
205 | act("versions differ", "m", f, f, f, fmerge(f), False) |
|
196 | act("versions differ", "m", f, f, f, fmerge(f), False) | |
206 | # are we clobbering? |
|
197 | # are we clobbering? | |
207 | # is remote's version newer? |
|
198 | # is remote's version newer? | |
208 | # or are we going back in time and clean? |
|
199 | # or are we going back in time and clean? | |
209 | elif overwrite or m2[f] != a or (backwards and not n[20:]): |
|
200 | elif overwrite or m2[f] != a or (backwards and not n[20:]): | |
210 | act("remote is newer", "g", f, m2.execf(f)) |
|
201 | act("remote is newer", "g", f, m2.execf(f)) | |
211 | # local is newer, not overwrite, check mode bits |
|
202 | # local is newer, not overwrite, check mode bits | |
212 | elif fmerge(f) != m1.execf(f): |
|
203 | elif fmerge(f) != m1.execf(f): | |
213 | act("update permissions", "e", f, m2.execf(f)) |
|
204 | act("update permissions", "e", f, m2.execf(f)) | |
214 | # contents same, check mode bits |
|
205 | # contents same, check mode bits | |
215 | elif m1.execf(f) != m2.execf(f): |
|
206 | elif m1.execf(f) != m2.execf(f): | |
216 | if overwrite or fmerge(f) != m1.execf(f): |
|
207 | if overwrite or fmerge(f) != m1.execf(f): | |
217 | act("update permissions", "e", f, m2.execf(f)) |
|
208 | act("update permissions", "e", f, m2.execf(f)) | |
218 | elif f in copied: |
|
209 | elif f in copied: | |
219 | continue |
|
210 | continue | |
220 | elif f in copy: |
|
211 | elif f in copy: | |
221 | f2 = copy[f] |
|
212 | f2 = copy[f] | |
222 | if f2 in m1: # case 2 A,B/B/B |
|
213 | if f2 in m1: # case 2 A,B/B/B | |
223 | act("local copied to " + f2, "m", |
|
214 | act("local copied to " + f2, "m", | |
224 | f, f2, f, fmerge(f, f2, f2), False) |
|
215 | f, f2, f, fmerge(f, f2, f2), False) | |
225 | else: # case 4,21 A/B/B |
|
216 | else: # case 4,21 A/B/B | |
226 | act("local moved to " + f2, "m", |
|
217 | act("local moved to " + f2, "m", | |
227 | f, f2, f, fmerge(f, f2, f2), False) |
|
218 | f, f2, f, fmerge(f, f2, f2), False) | |
228 | elif f in ma: |
|
219 | elif f in ma: | |
229 | if n != ma[f] and not overwrite: |
|
220 | if n != ma[f] and not overwrite: | |
230 | if repo.ui.prompt( |
|
221 | if repo.ui.prompt( | |
231 | (_(" local changed %s which remote deleted\n") % f) + |
|
222 | (_(" local changed %s which remote deleted\n") % f) + | |
232 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): |
|
223 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): | |
233 | act("prompt delete", "r", f) |
|
224 | act("prompt delete", "r", f) | |
234 | else: |
|
225 | else: | |
235 | act("other deleted", "r", f) |
|
226 | act("other deleted", "r", f) | |
236 | else: |
|
227 | else: | |
237 | # file is created on branch or in working directory |
|
228 | # file is created on branch or in working directory | |
238 | if (overwrite and n[20:] != "u") or (backwards and not n[20:]): |
|
229 | if (overwrite and n[20:] != "u") or (backwards and not n[20:]): | |
239 | act("remote deleted", "r", f) |
|
230 | act("remote deleted", "r", f) | |
240 |
|
231 | |||
241 | for f, n in m2.iteritems(): |
|
232 | for f, n in m2.iteritems(): | |
242 | if partial and not partial(f): |
|
233 | if partial and not partial(f): | |
243 | continue |
|
234 | continue | |
244 | if f in m1: |
|
235 | if f in m1: | |
245 | continue |
|
236 | continue | |
246 | if f in copied: |
|
237 | if f in copied: | |
247 | continue |
|
238 | continue | |
248 | if f in copy: |
|
239 | if f in copy: | |
249 | f2 = copy[f] |
|
240 | f2 = copy[f] | |
250 | if f2 in m2: # rename case 1, A/A,B/A |
|
241 | if f2 in m2: # rename case 1, A/A,B/A | |
251 | act("remote copied to " + f, "m", |
|
242 | act("remote copied to " + f, "m", | |
252 | f2, f, f, fmerge(f2, f, f2), False) |
|
243 | f2, f, f, fmerge(f2, f, f2), False) | |
253 | else: # case 3,20 A/B/A |
|
244 | else: # case 3,20 A/B/A | |
254 | act("remote moved to " + f, "m", |
|
245 | act("remote moved to " + f, "m", | |
255 | f2, f, f, fmerge(f2, f, f2), True) |
|
246 | f2, f, f, fmerge(f2, f, f2), True) | |
256 | elif f in ma: |
|
247 | elif f in ma: | |
257 | if overwrite or backwards: |
|
248 | if overwrite or backwards: | |
258 | act("recreating", "g", f, m2.execf(f)) |
|
249 | act("recreating", "g", f, m2.execf(f)) | |
259 | elif n != ma[f]: |
|
250 | elif n != ma[f]: | |
260 | if repo.ui.prompt( |
|
251 | if repo.ui.prompt( | |
261 | (_("remote changed %s which local deleted\n") % f) + |
|
252 | (_("remote changed %s which local deleted\n") % f) + | |
262 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): |
|
253 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): | |
263 | act("prompt recreating", "g", f, m2.execf(f)) |
|
254 | act("prompt recreating", "g", f, m2.execf(f)) | |
264 | else: |
|
255 | else: | |
265 | act("remote created", "g", f, m2.execf(f)) |
|
256 | act("remote created", "g", f, m2.execf(f)) | |
266 |
|
257 | |||
267 | return action |
|
258 | return action | |
268 |
|
259 | |||
269 | def applyupdates(repo, action, wctx, mctx): |
|
260 | def applyupdates(repo, action, wctx, mctx): | |
270 | "apply the merge action list to the working directory" |
|
261 | "apply the merge action list to the working directory" | |
271 |
|
262 | |||
272 | updated, merged, removed, unresolved = 0, 0, 0, 0 |
|
263 | updated, merged, removed, unresolved = 0, 0, 0, 0 | |
273 | action.sort() |
|
264 | action.sort() | |
274 | for a in action: |
|
265 | for a in action: | |
275 | f, m = a[:2] |
|
266 | f, m = a[:2] | |
276 | if f[0] == "/": |
|
267 | if f[0] == "/": | |
277 | continue |
|
268 | continue | |
278 | if m == "r": # remove |
|
269 | if m == "r": # remove | |
279 | repo.ui.note(_("removing %s\n") % f) |
|
270 | repo.ui.note(_("removing %s\n") % f) | |
280 | util.audit_path(f) |
|
271 | util.audit_path(f) | |
281 | try: |
|
272 | try: | |
282 | util.unlink(repo.wjoin(f)) |
|
273 | util.unlink(repo.wjoin(f)) | |
283 | except OSError, inst: |
|
274 | except OSError, inst: | |
284 | if inst.errno != errno.ENOENT: |
|
275 | if inst.errno != errno.ENOENT: | |
285 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
276 | repo.ui.warn(_("update failed to remove %s: %s!\n") % | |
286 | (f, inst.strerror)) |
|
277 | (f, inst.strerror)) | |
287 | removed += 1 |
|
278 | removed += 1 | |
288 | elif m == "m": # merge |
|
279 | elif m == "m": # merge | |
289 | f2, fd, flag, move = a[2:] |
|
280 | f2, fd, flag, move = a[2:] | |
290 | r = filemerge(repo, f, f2, wctx, mctx) |
|
281 | r = filemerge(repo, f, f2, wctx, mctx) | |
291 | if r > 0: |
|
282 | if r > 0: | |
292 | unresolved += 1 |
|
283 | unresolved += 1 | |
293 | else: |
|
284 | else: | |
294 | if r is None: |
|
285 | if r is None: | |
295 | updated += 1 |
|
286 | updated += 1 | |
296 | else: |
|
287 | else: | |
297 | merged += 1 |
|
288 | merged += 1 | |
298 | if f != fd: |
|
289 | if f != fd: | |
299 | repo.ui.debug(_("copying %s to %s\n") % (f, fd)) |
|
290 | repo.ui.debug(_("copying %s to %s\n") % (f, fd)) | |
300 | repo.wwrite(fd, repo.wread(f)) |
|
291 | repo.wwrite(fd, repo.wread(f)) | |
301 | if move: |
|
292 | if move: | |
302 | repo.ui.debug(_("removing %s\n") % f) |
|
293 | repo.ui.debug(_("removing %s\n") % f) | |
303 | os.unlink(repo.wjoin(f)) |
|
294 | os.unlink(repo.wjoin(f)) | |
304 | util.set_exec(repo.wjoin(fd), flag) |
|
295 | util.set_exec(repo.wjoin(fd), flag) | |
305 | elif m == "g": # get |
|
296 | elif m == "g": # get | |
306 | flag = a[2] |
|
297 | flag = a[2] | |
307 | repo.ui.note(_("getting %s\n") % f) |
|
298 | repo.ui.note(_("getting %s\n") % f) | |
308 | t = mctx.filectx(f).data() |
|
299 | t = mctx.filectx(f).data() | |
309 | repo.wwrite(f, t) |
|
300 | repo.wwrite(f, t) | |
310 | util.set_exec(repo.wjoin(f), flag) |
|
301 | util.set_exec(repo.wjoin(f), flag) | |
311 | updated += 1 |
|
302 | updated += 1 | |
312 | elif m == "e": # exec |
|
303 | elif m == "e": # exec | |
313 | flag = a[2] |
|
304 | flag = a[2] | |
314 | util.set_exec(repo.wjoin(f), flag) |
|
305 | util.set_exec(repo.wjoin(f), flag) | |
315 |
|
306 | |||
316 | return updated, merged, removed, unresolved |
|
307 | return updated, merged, removed, unresolved | |
317 |
|
308 | |||
318 | def recordupdates(repo, action, branchmerge): |
|
309 | def recordupdates(repo, action, branchmerge): | |
319 | "record merge actions to the dirstate" |
|
310 | "record merge actions to the dirstate" | |
320 |
|
311 | |||
321 | for a in action: |
|
312 | for a in action: | |
322 | f, m = a[:2] |
|
313 | f, m = a[:2] | |
323 | if m == "r": # remove |
|
314 | if m == "r": # remove | |
324 | if branchmerge: |
|
315 | if branchmerge: | |
325 | repo.dirstate.update([f], 'r') |
|
316 | repo.dirstate.update([f], 'r') | |
326 | else: |
|
317 | else: | |
327 | repo.dirstate.forget([f]) |
|
318 | repo.dirstate.forget([f]) | |
328 | elif m == "f": # forget |
|
319 | elif m == "f": # forget | |
329 | repo.dirstate.forget([f]) |
|
320 | repo.dirstate.forget([f]) | |
330 | elif m == "g": # get |
|
321 | elif m == "g": # get | |
331 | if branchmerge: |
|
322 | if branchmerge: | |
332 | repo.dirstate.update([f], 'n', st_mtime=-1) |
|
323 | repo.dirstate.update([f], 'n', st_mtime=-1) | |
333 | else: |
|
324 | else: | |
334 | repo.dirstate.update([f], 'n') |
|
325 | repo.dirstate.update([f], 'n') | |
335 | elif m == "m": # merge |
|
326 | elif m == "m": # merge | |
336 | f2, fd, flag, move = a[2:] |
|
327 | f2, fd, flag, move = a[2:] | |
337 | if branchmerge: |
|
328 | if branchmerge: | |
338 | # We've done a branch merge, mark this file as merged |
|
329 | # We've done a branch merge, mark this file as merged | |
339 | # so that we properly record the merger later |
|
330 | # so that we properly record the merger later | |
340 | repo.dirstate.update([fd], 'm') |
|
331 | repo.dirstate.update([fd], 'm') | |
341 | if f != f2: # copy/rename |
|
332 | if f != f2: # copy/rename | |
342 | if move: |
|
333 | if move: | |
343 | repo.dirstate.update([f], 'r') |
|
334 | repo.dirstate.update([f], 'r') | |
344 | if f != fd: |
|
335 | if f != fd: | |
345 | repo.dirstate.copy(f, fd) |
|
336 | repo.dirstate.copy(f, fd) | |
346 | else: |
|
337 | else: | |
347 | repo.dirstate.copy(f2, fd) |
|
338 | repo.dirstate.copy(f2, fd) | |
348 | else: |
|
339 | else: | |
349 | # We've update-merged a locally modified file, so |
|
340 | # We've update-merged a locally modified file, so | |
350 | # we set the dirstate to emulate a normal checkout |
|
341 | # we set the dirstate to emulate a normal checkout | |
351 | # of that file some time in the past. Thus our |
|
342 | # of that file some time in the past. Thus our | |
352 | # merge will appear as a normal local file |
|
343 | # merge will appear as a normal local file | |
353 | # modification. |
|
344 | # modification. | |
354 | repo.dirstate.update([fd], 'n', st_size=-1, st_mtime=-1) |
|
345 | repo.dirstate.update([fd], 'n', st_size=-1, st_mtime=-1) | |
355 | if move: |
|
346 | if move: | |
356 | repo.dirstate.forget([f]) |
|
347 | repo.dirstate.forget([f]) | |
357 |
|
348 | |||
358 | def update(repo, node, branchmerge, force, partial, wlock): |
|
349 | def update(repo, node, branchmerge, force, partial, wlock): | |
359 | """ |
|
350 | """ | |
360 | Perform a merge between the working directory and the given node |
|
351 | Perform a merge between the working directory and the given node | |
361 |
|
352 | |||
362 | branchmerge = whether to merge between branches |
|
353 | branchmerge = whether to merge between branches | |
363 | force = whether to force branch merging or file overwriting |
|
354 | force = whether to force branch merging or file overwriting | |
364 | partial = a function to filter file lists (dirstate not updated) |
|
355 | partial = a function to filter file lists (dirstate not updated) | |
365 | wlock = working dir lock, if already held |
|
356 | wlock = working dir lock, if already held | |
366 | """ |
|
357 | """ | |
367 |
|
358 | |||
368 | if not wlock: |
|
359 | if not wlock: | |
369 | wlock = repo.wlock() |
|
360 | wlock = repo.wlock() | |
370 |
|
361 | |||
371 | overwrite = force and not branchmerge |
|
362 | overwrite = force and not branchmerge | |
372 | forcemerge = force and branchmerge |
|
363 | forcemerge = force and branchmerge | |
373 | wc = repo.workingctx() |
|
364 | wc = repo.workingctx() | |
374 | pl = wc.parents() |
|
365 | pl = wc.parents() | |
375 | p1, p2 = pl[0], repo.changectx(node) |
|
366 | p1, p2 = pl[0], repo.changectx(node) | |
376 | pa = p1.ancestor(p2) |
|
367 | pa = p1.ancestor(p2) | |
377 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) |
|
368 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) | |
378 |
|
369 | |||
379 | ### check phase |
|
370 | ### check phase | |
380 | if not overwrite and len(pl) > 1: |
|
371 | if not overwrite and len(pl) > 1: | |
381 | raise util.Abort(_("outstanding uncommitted merges")) |
|
372 | raise util.Abort(_("outstanding uncommitted merges")) | |
382 | if pa == p1 or pa == p2: # is there a linear path from p1 to p2? |
|
373 | if pa == p1 or pa == p2: # is there a linear path from p1 to p2? | |
383 | if branchmerge: |
|
374 | if branchmerge: | |
384 | raise util.Abort(_("there is nothing to merge, just use " |
|
375 | raise util.Abort(_("there is nothing to merge, just use " | |
385 | "'hg update' or look at 'hg heads'")) |
|
376 | "'hg update' or look at 'hg heads'")) | |
386 | elif not (overwrite or branchmerge): |
|
377 | elif not (overwrite or branchmerge): | |
387 | raise util.Abort(_("update spans branches, use 'hg merge' " |
|
378 | raise util.Abort(_("update spans branches, use 'hg merge' " | |
388 | "or 'hg update -C' to lose changes")) |
|
379 | "or 'hg update -C' to lose changes")) | |
389 | if branchmerge and not forcemerge: |
|
380 | if branchmerge and not forcemerge: | |
390 | if wc.files(): |
|
381 | if wc.files(): | |
391 | raise util.Abort(_("outstanding uncommitted changes")) |
|
382 | raise util.Abort(_("outstanding uncommitted changes")) | |
392 |
|
383 | |||
393 | ### calculate phase |
|
384 | ### calculate phase | |
394 | action = [] |
|
385 | action = [] | |
395 | if not force: |
|
386 | if not force: | |
396 | checkunknown(wc, p2) |
|
387 | checkunknown(wc, p2) | |
397 | if not branchmerge: |
|
388 | if not branchmerge: | |
398 | action += forgetremoved(wc, p2) |
|
389 | action += forgetremoved(wc, p2) | |
399 | action += manifestmerge(repo, wc, p2, pa, overwrite, partial) |
|
390 | action += manifestmerge(repo, wc, p2, pa, overwrite, partial) | |
400 |
|
391 | |||
401 | ### apply phase |
|
392 | ### apply phase | |
402 | if not branchmerge: # just jump to the new rev |
|
393 | if not branchmerge: # just jump to the new rev | |
403 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' |
|
394 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' | |
404 | if not partial: |
|
395 | if not partial: | |
405 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) |
|
396 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) | |
406 |
|
397 | |||
407 | stats = applyupdates(repo, action, wc, p2) |
|
398 | stats = applyupdates(repo, action, wc, p2) | |
408 |
|
399 | |||
409 | if not partial: |
|
400 | if not partial: | |
410 | recordupdates(repo, action, branchmerge) |
|
401 | recordupdates(repo, action, branchmerge) | |
411 | repo.dirstate.setparents(fp1, fp2) |
|
402 | repo.dirstate.setparents(fp1, fp2) | |
412 | repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) |
|
403 | repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) | |
413 | if not branchmerge: |
|
404 | if not branchmerge: | |
414 | repo.opener("branch", "w").write(p2.branch() + "\n") |
|
405 | repo.opener("branch", "w").write(p2.branch() + "\n") | |
415 |
|
406 | |||
416 | return stats |
|
407 | return stats | |
417 |
|
408 |
General Comments 0
You need to be logged in to leave comments.
Login now