Show More
@@ -1,334 +1,334 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(), "util os tempfile") |
|
11 | demandload(globals(), "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 update(repo, node, branchmerge=False, force=False, partial=None, |
|
50 | def update(repo, node, branchmerge=False, force=False, partial=None, | |
51 | wlock=None, show_stats=True, remind=True): |
|
51 | wlock=None, show_stats=True, remind=True): | |
52 |
|
52 | |||
53 | overwrite = force and not branchmerge |
|
53 | overwrite = force and not branchmerge | |
54 | forcemerge = force and branchmerge |
|
54 | forcemerge = force and branchmerge | |
55 |
|
55 | |||
56 | if not wlock: |
|
56 | if not wlock: | |
57 | wlock = repo.wlock() |
|
57 | wlock = repo.wlock() | |
58 |
|
58 | |||
59 | ### check phase |
|
59 | ### check phase | |
60 |
|
60 | |||
61 | pl = repo.dirstate.parents() |
|
61 | pl = repo.dirstate.parents() | |
62 | if not overwrite and pl[1] != nullid: |
|
62 | if not overwrite and pl[1] != nullid: | |
63 | raise util.Abort(_("outstanding uncommitted merges")) |
|
63 | raise util.Abort(_("outstanding uncommitted merges")) | |
64 |
|
64 | |||
65 | p1, p2 = pl[0], node |
|
65 | p1, p2 = pl[0], node | |
66 | pa = repo.changelog.ancestor(p1, p2) |
|
66 | pa = repo.changelog.ancestor(p1, p2) | |
67 |
|
67 | |||
68 | # is there a linear path from p1 to p2? |
|
68 | # is there a linear path from p1 to p2? | |
69 | linear_path = (pa == p1 or pa == p2) |
|
69 | linear_path = (pa == p1 or pa == p2) | |
70 | if branchmerge and linear_path: |
|
70 | if branchmerge and linear_path: | |
71 | raise util.Abort(_("there is nothing to merge, just use " |
|
71 | raise util.Abort(_("there is nothing to merge, just use " | |
72 | "'hg update' or look at 'hg heads'")) |
|
72 | "'hg update' or look at 'hg heads'")) | |
73 |
|
73 | |||
74 | if not overwrite and not linear_path and not branchmerge: |
|
74 | if not overwrite and not linear_path and not branchmerge: | |
75 | raise util.Abort(_("update spans branches, use 'hg merge' " |
|
75 | raise util.Abort(_("update spans branches, use 'hg merge' " | |
76 | "or 'hg update -C' to lose changes")) |
|
76 | "or 'hg update -C' to lose changes")) | |
77 |
|
77 | |||
78 | modified, added, removed, deleted, unknown = repo.changes() |
|
78 | modified, added, removed, deleted, unknown = repo.changes() | |
79 | if branchmerge and not forcemerge: |
|
79 | if branchmerge and not forcemerge: | |
80 | if modified or added or removed: |
|
80 | if modified or added or removed: | |
81 | raise util.Abort(_("outstanding uncommitted changes")) |
|
81 | raise util.Abort(_("outstanding uncommitted changes")) | |
82 |
|
82 | |||
83 | m1n = repo.changelog.read(p1)[0] |
|
83 | m1n = repo.changelog.read(p1)[0] | |
84 | m2n = repo.changelog.read(p2)[0] |
|
84 | m2n = repo.changelog.read(p2)[0] | |
85 | man = repo.manifest.ancestor(m1n, m2n) |
|
85 | man = repo.manifest.ancestor(m1n, m2n) | |
86 | m1 = repo.manifest.read(m1n) |
|
86 | m1 = repo.manifest.read(m1n) | |
87 | m2 = repo.manifest.read(m2n).copy() |
|
87 | m2 = repo.manifest.read(m2n).copy() | |
88 | ma = repo.manifest.read(man) |
|
88 | ma = repo.manifest.read(man) | |
89 |
|
89 | |||
90 | if not forcemerge and not overwrite: |
|
90 | if not force: | |
91 | for f in unknown: |
|
91 | for f in unknown: | |
92 | if f in m2: |
|
92 | if f in m2: | |
93 | t1 = repo.wread(f) |
|
93 | t1 = repo.wread(f) | |
94 | t2 = repo.file(f).read(m2[f]) |
|
94 | t2 = repo.file(f).read(m2[f]) | |
95 | if cmp(t1, t2) != 0: |
|
95 | if cmp(t1, t2) != 0: | |
96 | raise util.Abort(_("'%s' already exists in the working" |
|
96 | raise util.Abort(_("'%s' already exists in the working" | |
97 | " dir and differs from remote") % f) |
|
97 | " dir and differs from remote") % f) | |
98 |
|
98 | |||
99 | # resolve the manifest to determine which files |
|
99 | # resolve the manifest to determine which files | |
100 | # we care about merging |
|
100 | # we care about merging | |
101 | repo.ui.note(_("resolving manifests\n")) |
|
101 | repo.ui.note(_("resolving manifests\n")) | |
102 | repo.ui.debug(_(" overwrite %s branchmerge %s partial %s linear %s\n") % |
|
102 | repo.ui.debug(_(" overwrite %s branchmerge %s partial %s linear %s\n") % | |
103 | (overwrite, branchmerge, partial and True or False, linear_path)) |
|
103 | (overwrite, branchmerge, partial and True or False, linear_path)) | |
104 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % |
|
104 | repo.ui.debug(_(" ancestor %s local %s remote %s\n") % | |
105 | (short(man), short(m1n), short(m2n))) |
|
105 | (short(man), short(m1n), short(m2n))) | |
106 |
|
106 | |||
107 | merge = {} |
|
107 | merge = {} | |
108 | get = {} |
|
108 | get = {} | |
109 | remove = [] |
|
109 | remove = [] | |
110 |
|
110 | |||
111 | # construct a working dir manifest |
|
111 | # construct a working dir manifest | |
112 | mw = m1.copy() |
|
112 | mw = m1.copy() | |
113 | umap = dict.fromkeys(unknown) |
|
113 | umap = dict.fromkeys(unknown) | |
114 |
|
114 | |||
115 | for f in added + modified + unknown: |
|
115 | for f in added + modified + unknown: | |
116 | mw[f] = "" |
|
116 | mw[f] = "" | |
117 | mw.set(f, util.is_exec(repo.wjoin(f), mw.execf(f))) |
|
117 | mw.set(f, util.is_exec(repo.wjoin(f), mw.execf(f))) | |
118 |
|
118 | |||
119 | for f in deleted + removed: |
|
119 | for f in deleted + removed: | |
120 | if f in mw: |
|
120 | if f in mw: | |
121 | del mw[f] |
|
121 | del mw[f] | |
122 |
|
122 | |||
123 | # If we're jumping between revisions (as opposed to merging), |
|
123 | # If we're jumping between revisions (as opposed to merging), | |
124 | # and if neither the working directory nor the target rev has |
|
124 | # and if neither the working directory nor the target rev has | |
125 | # the file, then we need to remove it from the dirstate, to |
|
125 | # the file, then we need to remove it from the dirstate, to | |
126 | # prevent the dirstate from listing the file when it is no |
|
126 | # prevent the dirstate from listing the file when it is no | |
127 | # longer in the manifest. |
|
127 | # longer in the manifest. | |
128 | if not partial and linear_path and f not in m2: |
|
128 | if not partial and linear_path and f not in m2: | |
129 | repo.dirstate.forget((f,)) |
|
129 | repo.dirstate.forget((f,)) | |
130 |
|
130 | |||
131 | # Compare manifests |
|
131 | # Compare manifests | |
132 | for f, n in mw.iteritems(): |
|
132 | for f, n in mw.iteritems(): | |
133 | if partial and not partial(f): |
|
133 | if partial and not partial(f): | |
134 | continue |
|
134 | continue | |
135 | if f in m2: |
|
135 | if f in m2: | |
136 | s = 0 |
|
136 | s = 0 | |
137 |
|
137 | |||
138 | # is the wfile new since m1, and match m2? |
|
138 | # is the wfile new since m1, and match m2? | |
139 | if f not in m1: |
|
139 | if f not in m1: | |
140 | t1 = repo.wread(f) |
|
140 | t1 = repo.wread(f) | |
141 | t2 = repo.file(f).read(m2[f]) |
|
141 | t2 = repo.file(f).read(m2[f]) | |
142 | if cmp(t1, t2) == 0: |
|
142 | if cmp(t1, t2) == 0: | |
143 | n = m2[f] |
|
143 | n = m2[f] | |
144 | del t1, t2 |
|
144 | del t1, t2 | |
145 |
|
145 | |||
146 | # are files different? |
|
146 | # are files different? | |
147 | if n != m2[f]: |
|
147 | if n != m2[f]: | |
148 | a = ma.get(f, nullid) |
|
148 | a = ma.get(f, nullid) | |
149 | # are both different from the ancestor? |
|
149 | # are both different from the ancestor? | |
150 | if n != a and m2[f] != a: |
|
150 | if n != a and m2[f] != a: | |
151 | repo.ui.debug(_(" %s versions differ, resolve\n") % f) |
|
151 | repo.ui.debug(_(" %s versions differ, resolve\n") % f) | |
152 | # merge executable bits |
|
152 | # merge executable bits | |
153 | # "if we changed or they changed, change in merge" |
|
153 | # "if we changed or they changed, change in merge" | |
154 | a, b, c = ma.execf(f), mw.execf(f), m2.execf(f) |
|
154 | a, b, c = ma.execf(f), mw.execf(f), m2.execf(f) | |
155 | mode = ((a^b) | (a^c)) ^ a |
|
155 | mode = ((a^b) | (a^c)) ^ a | |
156 | merge[f] = (mode, m1.get(f, nullid), m2[f]) |
|
156 | merge[f] = (mode, m1.get(f, nullid), m2[f]) | |
157 | s = 1 |
|
157 | s = 1 | |
158 | # are we clobbering? |
|
158 | # are we clobbering? | |
159 | # is remote's version newer? |
|
159 | # is remote's version newer? | |
160 | # or are we going back in time? |
|
160 | # or are we going back in time? | |
161 | elif overwrite or m2[f] != a or (p2 == pa and mw[f] == m1[f]): |
|
161 | elif overwrite or m2[f] != a or (p2 == pa and mw[f] == m1[f]): | |
162 | repo.ui.debug(_(" remote %s is newer, get\n") % f) |
|
162 | repo.ui.debug(_(" remote %s is newer, get\n") % f) | |
163 | get[f] = (m2.execf(f), m2[f]) |
|
163 | get[f] = (m2.execf(f), m2[f]) | |
164 | s = 1 |
|
164 | s = 1 | |
165 | elif f in umap or f in added: |
|
165 | elif f in umap or f in added: | |
166 | # this unknown file is the same as the checkout |
|
166 | # this unknown file is the same as the checkout | |
167 | # we need to reset the dirstate if the file was added |
|
167 | # we need to reset the dirstate if the file was added | |
168 | get[f] = (m2.execf(f), m2[f]) |
|
168 | get[f] = (m2.execf(f), m2[f]) | |
169 |
|
169 | |||
170 | if not s and mw.execf(f) != m2.execf(f): |
|
170 | if not s and mw.execf(f) != m2.execf(f): | |
171 | if overwrite: |
|
171 | if overwrite: | |
172 | repo.ui.debug(_(" updating permissions for %s\n") % f) |
|
172 | repo.ui.debug(_(" updating permissions for %s\n") % f) | |
173 | util.set_exec(repo.wjoin(f), m2.execf(f)) |
|
173 | util.set_exec(repo.wjoin(f), m2.execf(f)) | |
174 | else: |
|
174 | else: | |
175 | a, b, c = ma.execf(f), mw.execf(f), m2.execf(f) |
|
175 | a, b, c = ma.execf(f), mw.execf(f), m2.execf(f) | |
176 | mode = ((a^b) | (a^c)) ^ a |
|
176 | mode = ((a^b) | (a^c)) ^ a | |
177 | if mode != b: |
|
177 | if mode != b: | |
178 | repo.ui.debug(_(" updating permissions for %s\n") |
|
178 | repo.ui.debug(_(" updating permissions for %s\n") | |
179 | % f) |
|
179 | % f) | |
180 | util.set_exec(repo.wjoin(f), mode) |
|
180 | util.set_exec(repo.wjoin(f), mode) | |
181 | del m2[f] |
|
181 | del m2[f] | |
182 | elif f in ma: |
|
182 | elif f in ma: | |
183 | if n != ma[f]: |
|
183 | if n != ma[f]: | |
184 | r = _("d") |
|
184 | r = _("d") | |
185 | if not overwrite and (linear_path or branchmerge): |
|
185 | if not overwrite and (linear_path or branchmerge): | |
186 | r = repo.ui.prompt( |
|
186 | r = repo.ui.prompt( | |
187 | (_(" local changed %s which remote deleted\n") % f) + |
|
187 | (_(" local changed %s which remote deleted\n") % f) + | |
188 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) |
|
188 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) | |
189 | if r == _("d"): |
|
189 | if r == _("d"): | |
190 | remove.append(f) |
|
190 | remove.append(f) | |
191 | else: |
|
191 | else: | |
192 | repo.ui.debug(_("other deleted %s\n") % f) |
|
192 | repo.ui.debug(_("other deleted %s\n") % f) | |
193 | remove.append(f) # other deleted it |
|
193 | remove.append(f) # other deleted it | |
194 | else: |
|
194 | else: | |
195 | # file is created on branch or in working directory |
|
195 | # file is created on branch or in working directory | |
196 | if overwrite and f not in umap: |
|
196 | if overwrite and f not in umap: | |
197 | repo.ui.debug(_("remote deleted %s, clobbering\n") % f) |
|
197 | repo.ui.debug(_("remote deleted %s, clobbering\n") % f) | |
198 | remove.append(f) |
|
198 | remove.append(f) | |
199 | elif n == m1.get(f, nullid): # same as parent |
|
199 | elif n == m1.get(f, nullid): # same as parent | |
200 | if p2 == pa: # going backwards? |
|
200 | if p2 == pa: # going backwards? | |
201 | repo.ui.debug(_("remote deleted %s\n") % f) |
|
201 | repo.ui.debug(_("remote deleted %s\n") % f) | |
202 | remove.append(f) |
|
202 | remove.append(f) | |
203 | else: |
|
203 | else: | |
204 | repo.ui.debug(_("local modified %s, keeping\n") % f) |
|
204 | repo.ui.debug(_("local modified %s, keeping\n") % f) | |
205 | else: |
|
205 | else: | |
206 | repo.ui.debug(_("working dir created %s, keeping\n") % f) |
|
206 | repo.ui.debug(_("working dir created %s, keeping\n") % f) | |
207 |
|
207 | |||
208 | for f, n in m2.iteritems(): |
|
208 | for f, n in m2.iteritems(): | |
209 | if partial and not partial(f): |
|
209 | if partial and not partial(f): | |
210 | continue |
|
210 | continue | |
211 | if f[0] == "/": |
|
211 | if f[0] == "/": | |
212 | continue |
|
212 | continue | |
213 | if f in ma and n != ma[f]: |
|
213 | if f in ma and n != ma[f]: | |
214 | r = _("k") |
|
214 | r = _("k") | |
215 | if not overwrite and (linear_path or branchmerge): |
|
215 | if not overwrite and (linear_path or branchmerge): | |
216 | r = repo.ui.prompt( |
|
216 | r = repo.ui.prompt( | |
217 | (_("remote changed %s which local deleted\n") % f) + |
|
217 | (_("remote changed %s which local deleted\n") % f) + | |
218 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) |
|
218 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) | |
219 | if r == _("k"): |
|
219 | if r == _("k"): | |
220 | get[f] = (m2.execf(f), n) |
|
220 | get[f] = (m2.execf(f), n) | |
221 | elif f not in ma: |
|
221 | elif f not in ma: | |
222 | repo.ui.debug(_("remote created %s\n") % f) |
|
222 | repo.ui.debug(_("remote created %s\n") % f) | |
223 | get[f] = (m2.execf(f), n) |
|
223 | get[f] = (m2.execf(f), n) | |
224 | else: |
|
224 | else: | |
225 | if overwrite or p2 == pa: # going backwards? |
|
225 | if overwrite or p2 == pa: # going backwards? | |
226 | repo.ui.debug(_("local deleted %s, recreating\n") % f) |
|
226 | repo.ui.debug(_("local deleted %s, recreating\n") % f) | |
227 | get[f] = (m2.execf(f), n) |
|
227 | get[f] = (m2.execf(f), n) | |
228 | else: |
|
228 | else: | |
229 | repo.ui.debug(_("local deleted %s\n") % f) |
|
229 | repo.ui.debug(_("local deleted %s\n") % f) | |
230 |
|
230 | |||
231 | del mw, m1, m2, ma |
|
231 | del mw, m1, m2, ma | |
232 |
|
232 | |||
233 | if overwrite: |
|
233 | if overwrite: | |
234 | for f in merge: |
|
234 | for f in merge: | |
235 | get[f] = merge[f][:2] |
|
235 | get[f] = merge[f][:2] | |
236 | merge = {} |
|
236 | merge = {} | |
237 |
|
237 | |||
238 | if linear_path or overwrite: |
|
238 | if linear_path or overwrite: | |
239 | # we don't need to do any magic, just jump to the new rev |
|
239 | # we don't need to do any magic, just jump to the new rev | |
240 | p1, p2 = p2, nullid |
|
240 | p1, p2 = p2, nullid | |
241 |
|
241 | |||
242 | xp1 = hex(p1) |
|
242 | xp1 = hex(p1) | |
243 | xp2 = hex(p2) |
|
243 | xp2 = hex(p2) | |
244 | if p2 == nullid: xxp2 = '' |
|
244 | if p2 == nullid: xxp2 = '' | |
245 | else: xxp2 = xp2 |
|
245 | else: xxp2 = xp2 | |
246 |
|
246 | |||
247 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xxp2) |
|
247 | repo.hook('preupdate', throw=True, parent1=xp1, parent2=xxp2) | |
248 |
|
248 | |||
249 | # get the files we don't need to change |
|
249 | # get the files we don't need to change | |
250 | files = get.keys() |
|
250 | files = get.keys() | |
251 | files.sort() |
|
251 | files.sort() | |
252 | for f in files: |
|
252 | for f in files: | |
253 | flag, node = get[f] |
|
253 | flag, node = get[f] | |
254 | if f[0] == "/": |
|
254 | if f[0] == "/": | |
255 | continue |
|
255 | continue | |
256 | repo.ui.note(_("getting %s\n") % f) |
|
256 | repo.ui.note(_("getting %s\n") % f) | |
257 | t = repo.file(f).read(node) |
|
257 | t = repo.file(f).read(node) | |
258 | repo.wwrite(f, t) |
|
258 | repo.wwrite(f, t) | |
259 | util.set_exec(repo.wjoin(f), flag) |
|
259 | util.set_exec(repo.wjoin(f), flag) | |
260 | if not partial: |
|
260 | if not partial: | |
261 | if branchmerge: |
|
261 | if branchmerge: | |
262 | repo.dirstate.update([f], 'n', st_mtime=-1) |
|
262 | repo.dirstate.update([f], 'n', st_mtime=-1) | |
263 | else: |
|
263 | else: | |
264 | repo.dirstate.update([f], 'n') |
|
264 | repo.dirstate.update([f], 'n') | |
265 |
|
265 | |||
266 | # merge the tricky bits |
|
266 | # merge the tricky bits | |
267 | unresolved = [] |
|
267 | unresolved = [] | |
268 | files = merge.keys() |
|
268 | files = merge.keys() | |
269 | files.sort() |
|
269 | files.sort() | |
270 | for f in files: |
|
270 | for f in files: | |
271 | repo.ui.status(_("merging %s\n") % f) |
|
271 | repo.ui.status(_("merging %s\n") % f) | |
272 | flag, my, other = merge[f] |
|
272 | flag, my, other = merge[f] | |
273 | ret = merge3(repo, f, my, other, xp1, xp2) |
|
273 | ret = merge3(repo, f, my, other, xp1, xp2) | |
274 | if ret: |
|
274 | if ret: | |
275 | unresolved.append(f) |
|
275 | unresolved.append(f) | |
276 | util.set_exec(repo.wjoin(f), flag) |
|
276 | util.set_exec(repo.wjoin(f), flag) | |
277 | if not partial: |
|
277 | if not partial: | |
278 | if branchmerge: |
|
278 | if branchmerge: | |
279 | # We've done a branch merge, mark this file as merged |
|
279 | # We've done a branch merge, mark this file as merged | |
280 | # so that we properly record the merger later |
|
280 | # so that we properly record the merger later | |
281 | repo.dirstate.update([f], 'm') |
|
281 | repo.dirstate.update([f], 'm') | |
282 | else: |
|
282 | else: | |
283 | # We've update-merged a locally modified file, so |
|
283 | # We've update-merged a locally modified file, so | |
284 | # we set the dirstate to emulate a normal checkout |
|
284 | # we set the dirstate to emulate a normal checkout | |
285 | # of that file some time in the past. Thus our |
|
285 | # of that file some time in the past. Thus our | |
286 | # merge will appear as a normal local file |
|
286 | # merge will appear as a normal local file | |
287 | # modification. |
|
287 | # modification. | |
288 | f_len = len(repo.file(f).read(other)) |
|
288 | f_len = len(repo.file(f).read(other)) | |
289 | repo.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) |
|
289 | repo.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) | |
290 |
|
290 | |||
291 | remove.sort() |
|
291 | remove.sort() | |
292 | for f in remove: |
|
292 | for f in remove: | |
293 | repo.ui.note(_("removing %s\n") % f) |
|
293 | repo.ui.note(_("removing %s\n") % f) | |
294 | util.audit_path(f) |
|
294 | util.audit_path(f) | |
295 | try: |
|
295 | try: | |
296 | util.unlink(repo.wjoin(f)) |
|
296 | util.unlink(repo.wjoin(f)) | |
297 | except OSError, inst: |
|
297 | except OSError, inst: | |
298 | if inst.errno != errno.ENOENT: |
|
298 | if inst.errno != errno.ENOENT: | |
299 | repo.ui.warn(_("update failed to remove %s: %s!\n") % |
|
299 | repo.ui.warn(_("update failed to remove %s: %s!\n") % | |
300 | (f, inst.strerror)) |
|
300 | (f, inst.strerror)) | |
301 | if not partial: |
|
301 | if not partial: | |
302 | if branchmerge: |
|
302 | if branchmerge: | |
303 | repo.dirstate.update(remove, 'r') |
|
303 | repo.dirstate.update(remove, 'r') | |
304 | else: |
|
304 | else: | |
305 | repo.dirstate.forget(remove) |
|
305 | repo.dirstate.forget(remove) | |
306 |
|
306 | |||
307 | if not partial: |
|
307 | if not partial: | |
308 | repo.dirstate.setparents(p1, p2) |
|
308 | repo.dirstate.setparents(p1, p2) | |
309 |
|
309 | |||
310 | if show_stats: |
|
310 | if show_stats: | |
311 | stats = ((len(get), _("updated")), |
|
311 | stats = ((len(get), _("updated")), | |
312 | (len(merge) - len(unresolved), _("merged")), |
|
312 | (len(merge) - len(unresolved), _("merged")), | |
313 | (len(remove), _("removed")), |
|
313 | (len(remove), _("removed")), | |
314 | (len(unresolved), _("unresolved"))) |
|
314 | (len(unresolved), _("unresolved"))) | |
315 | note = ", ".join([_("%d files %s") % s for s in stats]) |
|
315 | note = ", ".join([_("%d files %s") % s for s in stats]) | |
316 | repo.ui.status("%s\n" % note) |
|
316 | repo.ui.status("%s\n" % note) | |
317 | if not partial: |
|
317 | if not partial: | |
318 | if branchmerge: |
|
318 | if branchmerge: | |
319 | if unresolved: |
|
319 | if unresolved: | |
320 | repo.ui.status(_("There are unresolved merges," |
|
320 | repo.ui.status(_("There are unresolved merges," | |
321 | " you can redo the full merge using:\n" |
|
321 | " you can redo the full merge using:\n" | |
322 | " hg update -C %s\n" |
|
322 | " hg update -C %s\n" | |
323 | " hg merge %s\n" |
|
323 | " hg merge %s\n" | |
324 | % (repo.changelog.rev(p1), |
|
324 | % (repo.changelog.rev(p1), | |
325 | repo.changelog.rev(p2)))) |
|
325 | repo.changelog.rev(p2)))) | |
326 | elif remind: |
|
326 | elif remind: | |
327 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
|
327 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) | |
328 | elif unresolved: |
|
328 | elif unresolved: | |
329 | repo.ui.status(_("There are unresolved merges with" |
|
329 | repo.ui.status(_("There are unresolved merges with" | |
330 | " locally modified files.\n")) |
|
330 | " locally modified files.\n")) | |
331 |
|
331 | |||
332 | repo.hook('update', parent1=xp1, parent2=xxp2, error=len(unresolved)) |
|
332 | repo.hook('update', parent1=xp1, parent2=xxp2, error=len(unresolved)) | |
333 | return len(unresolved) |
|
333 | return len(unresolved) | |
334 |
|
334 |
General Comments 0
You need to be logged in to leave comments.
Login now