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