comparison mercurial/commit.py @ 51754:421c9b3f2f4e

commit: set whole manifest entries at once (node with its associated flags) Add a new function manifest.set that sets whole manifest entries at once, so the caller doesn't have to do two separate operations: m[p] = n m.set_flags(f) becomes: m.set(p, n, f) This obviously saves an extra lookup by path, and it also lets the underlying manifest implementation to be more efficient as it doesn't have to deal with partially-specified entries. It makes the interaction conceptually simpler, as well, since we don't have to go through an intermediate state of incorrect partially-written entry. (the real motivation for this change is an alternative manifest implementation where we batch pending writes, and dealing with fully defined entries makes the batching logic muchsimpler while avoiding slowdown due to alternating writes and reads)
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 01 Aug 2024 13:38:31 +0100
parents fce591256085
children f4733654f144
comparison
equal deleted inserted replaced
51753:a1e4fa9330d8 51754:421c9b3f2f4e
212 files.mark_removed(f) 212 files.mark_removed(f)
213 removed.append(f) 213 removed.append(f)
214 elif narrow_action == mergestate.CHANGE_ADDED: 214 elif narrow_action == mergestate.CHANGE_ADDED:
215 files.mark_added(f) 215 files.mark_added(f)
216 added.append(f) 216 added.append(f)
217 m[f] = m2[f] 217 fnode = m2[f]
218 flags = m2ctx.find(f)[1] or b'' 218 flags = m2ctx.find(f)[1] or b''
219 m.setflag(f, flags) 219 m.set(f, fnode, flags)
220 elif narrow_action == mergestate.CHANGE_MODIFIED: 220 elif narrow_action == mergestate.CHANGE_MODIFIED:
221 files.mark_touched(f) 221 files.mark_touched(f)
222 added.append(f) 222 added.append(f)
223 m[f] = m2[f] 223 fnode = m2[f]
224 flags = m2ctx.find(f)[1] or b'' 224 flags = m2ctx.find(f)[1] or b''
225 m.setflag(f, flags) 225 m.set(f, fnode, flags)
226 else: 226 else:
227 msg = _(b"corrupted mergestate, unknown narrow action: %b") 227 msg = _(b"corrupted mergestate, unknown narrow action: %b")
228 hint = _(b"restart the merge") 228 hint = _(b"restart the merge")
229 raise error.Abort(msg, hint=hint) 229 raise error.Abort(msg, hint=hint)
230 continue 230 continue
232 fctx = ctx[f] 232 fctx = ctx[f]
233 if fctx is None: 233 if fctx is None:
234 removed.append(f) 234 removed.append(f)
235 else: 235 else:
236 added.append(f) 236 added.append(f)
237 m[f], is_touched = _filecommit( 237 fnode, is_touched = _filecommit(
238 repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, ms 238 repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, ms
239 ) 239 )
240 if is_touched: 240 if is_touched:
241 if is_touched == 'added': 241 if is_touched == 'added':
242 files.mark_added(f) 242 files.mark_added(f)
243 elif is_touched == 'merged': 243 elif is_touched == 'merged':
244 files.mark_merged(f) 244 files.mark_merged(f)
245 else: 245 else:
246 files.mark_touched(f) 246 files.mark_touched(f)
247 m.setflag(f, fctx.flags()) 247 m.set(f, fnode, fctx.flags())
248 except OSError: 248 except OSError:
249 repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f)) 249 repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f))
250 raise 250 raise
251 251
252 # update manifest 252 # update manifest