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