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