comparison mercurial/cmdutil.py @ 46778:62c2857a174b

amend: mark commit obsolete after moving working copy We were doing it this way: 1. move working copy (repo.setparents) 2. add obsmarkers (scmutil.cleanupnodes) 3. fix dirstate (dirstate.normal/drop) Step 1 and 3 are closely related, so let's move them together. It seems safest to create the obsmarkers last. This patch thus makes the order 1, 3, 2. Differential Revision: https://phab.mercurial-scm.org/D10197
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 26 Feb 2019 15:54:20 -0800
parents f0982c76ef1b
children e2f7b2695ba1
comparison
equal deleted inserted replaced
46777:685383486d0a 46778:62c2857a174b
2965 newid = repo.commitctx(new) 2965 newid = repo.commitctx(new)
2966 ms.reset() 2966 ms.reset()
2967 2967
2968 # Reroute the working copy parent to the new changeset 2968 # Reroute the working copy parent to the new changeset
2969 repo.setparents(newid, nullid) 2969 repo.setparents(newid, nullid)
2970
2971 # Fixing the dirstate because localrepo.commitctx does not update
2972 # it. This is rather convenient because we did not need to update
2973 # the dirstate for all the files in the new commit which commitctx
2974 # could have done if it updated the dirstate. Now, we can
2975 # selectively update the dirstate only for the amended files.
2976 dirstate = repo.dirstate
2977
2978 # Update the state of the files which were added and modified in the
2979 # amend to "normal" in the dirstate. We need to use "normallookup" since
2980 # the files may have changed since the command started; using "normal"
2981 # would mark them as clean but with uncommitted contents.
2982 normalfiles = set(wctx.modified() + wctx.added()) & filestoamend
2983 for f in normalfiles:
2984 dirstate.normallookup(f)
2985
2986 # Update the state of files which were removed in the amend
2987 # to "removed" in the dirstate.
2988 removedfiles = set(wctx.removed()) & filestoamend
2989 for f in removedfiles:
2990 dirstate.drop(f)
2991
2970 mapping = {old.node(): (newid,)} 2992 mapping = {old.node(): (newid,)}
2971 obsmetadata = None 2993 obsmetadata = None
2972 if opts.get(b'note'): 2994 if opts.get(b'note'):
2973 obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])} 2995 obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])}
2974 backup = ui.configbool(b'rewrite', b'backup-bundle') 2996 backup = ui.configbool(b'rewrite', b'backup-bundle')
2979 metadata=obsmetadata, 3001 metadata=obsmetadata,
2980 fixphase=True, 3002 fixphase=True,
2981 targetphase=commitphase, 3003 targetphase=commitphase,
2982 backup=backup, 3004 backup=backup,
2983 ) 3005 )
2984
2985 # Fixing the dirstate because localrepo.commitctx does not update
2986 # it. This is rather convenient because we did not need to update
2987 # the dirstate for all the files in the new commit which commitctx
2988 # could have done if it updated the dirstate. Now, we can
2989 # selectively update the dirstate only for the amended files.
2990 dirstate = repo.dirstate
2991
2992 # Update the state of the files which were added and modified in the
2993 # amend to "normal" in the dirstate. We need to use "normallookup" since
2994 # the files may have changed since the command started; using "normal"
2995 # would mark them as clean but with uncommitted contents.
2996 normalfiles = set(wctx.modified() + wctx.added()) & filestoamend
2997 for f in normalfiles:
2998 dirstate.normallookup(f)
2999
3000 # Update the state of files which were removed in the amend
3001 # to "removed" in the dirstate.
3002 removedfiles = set(wctx.removed()) & filestoamend
3003 for f in removedfiles:
3004 dirstate.drop(f)
3005 3006
3006 return newid 3007 return newid
3007 3008
3008 3009
3009 def commiteditor(repo, ctx, subs, editform=b''): 3010 def commiteditor(repo, ctx, subs, editform=b''):