comparison mercurial/commit.py @ 45231:f0d4d1343cb4

commitctx: extract the function that commit a new manifest The logic is large enough and isolated enough to be extracted, this reduce the size of the main function, making it simpler to follow.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 23 Jul 2020 14:58:21 +0200
parents 5d0998ccedbb
children 4eb6466e6889
comparison
equal deleted inserted replaced
45230:5d0998ccedbb 45231:f0d4d1343cb4
130 130
131 if writechangesetcopy: 131 if writechangesetcopy:
132 filesremoved = removed 132 filesremoved = removed
133 133
134 files = touched 134 files = touched
135 md = None 135 mn = _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop)
136 if not files:
137 # if no "files" actually changed in terms of the changelog,
138 # try hard to detect unmodified manifest entry so that the
139 # exact same commit can be reproduced later on convert.
140 md = m1.diff(m, scmutil.matchfiles(repo, ctx.files()))
141 if not files and md:
142 repo.ui.debug(
143 b'not reusing manifest (no file change in '
144 b'changelog, but manifest differs)\n'
145 )
146 if files or md:
147 repo.ui.note(_(b"committing manifest\n"))
148 # we're using narrowmatch here since it's already applied at
149 # other stages (such as dirstate.walk), so we're already
150 # ignoring things outside of narrowspec in most cases. The
151 # one case where we might have files outside the narrowspec
152 # at this point is merges, and we already error out in the
153 # case where the merge has files outside of the narrowspec,
154 # so this is safe.
155 mn = mctx.write(
156 tr,
157 linkrev,
158 p1.manifestnode(),
159 p2.manifestnode(),
160 added,
161 drop,
162 match=repo.narrowmatch(),
163 )
164 else:
165 repo.ui.debug(
166 b'reusing manifest from p1 (listed files '
167 b'actually unchanged)\n'
168 )
169 mn = p1.manifestnode()
170 136
171 if writecopiesto == b'changeset-only': 137 if writecopiesto == b'changeset-only':
172 # If writing only to changeset extras, use None to indicate that 138 # If writing only to changeset extras, use None to indicate that
173 # no entry should be written. If writing to both, write an empty 139 # no entry should be written. If writing to both, write an empty
174 # entry to prevent the reader from falling back to reading 140 # entry to prevent the reader from falling back to reading
347 touched = 'modified' 313 touched = 'modified'
348 fnode = fparent1 314 fnode = fparent1
349 else: 315 else:
350 fnode = fparent1 316 fnode = fparent1
351 return fnode, touched 317 return fnode, touched
318
319
320 def _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop):
321 """make a new manifest entry (or reuse a new one)
322
323 given an initialised manifest context and precomputed list of
324 - files: files affected by the commit
325 - added: new entries in the manifest
326 - drop: entries present in parents but absent of this one
327
328 Create a new manifest revision, reuse existing ones if possible.
329
330 Return the nodeid of the manifest revision.
331 """
332 repo = ctx.repo()
333
334 md = None
335
336 # all this is cached, so it is find to get them all from the ctx.
337 p1 = ctx.p1()
338 p2 = ctx.p2()
339 m1ctx = p1.manifestctx()
340
341 m1 = m1ctx.read()
342
343 manifest = mctx.read()
344
345 if not files:
346 # if no "files" actually changed in terms of the changelog,
347 # try hard to detect unmodified manifest entry so that the
348 # exact same commit can be reproduced later on convert.
349 md = m1.diff(manifest, scmutil.matchfiles(repo, ctx.files()))
350 if not files and md:
351 repo.ui.debug(
352 b'not reusing manifest (no file change in '
353 b'changelog, but manifest differs)\n'
354 )
355 if files or md:
356 repo.ui.note(_(b"committing manifest\n"))
357 # we're using narrowmatch here since it's already applied at
358 # other stages (such as dirstate.walk), so we're already
359 # ignoring things outside of narrowspec in most cases. The
360 # one case where we might have files outside the narrowspec
361 # at this point is merges, and we already error out in the
362 # case where the merge has files outside of the narrowspec,
363 # so this is safe.
364 mn = mctx.write(
365 tr,
366 linkrev,
367 p1.manifestnode(),
368 p2.manifestnode(),
369 added,
370 drop,
371 match=repo.narrowmatch(),
372 )
373 else:
374 repo.ui.debug(
375 b'reusing manifest from p1 (listed files ' b'actually unchanged)\n'
376 )
377 mn = p1.manifestnode()
378
379 return mn