Mercurial > hg
comparison hgext/largefiles/overrides.py @ 45375:8c466bcb0879
revert: remove dangerous `parents` argument from `cmdutil.revert()`
As we found out the hard way (thanks to spectral@ for figuring it
out!), `cmdutil.revert()`'s `parents` argument must be
`repo.dirstate.parents()` or things may go wrong. We had an extension
that passed in the target commit as the first parent. The `hg split`
command from the evolve extension seems to have made the same mistake,
but I haven't looked carefully.
The problem is that `cmdutil._performrevert()` calls
`dirstate.normal()` on reverted files if the commit to revert to
equals the first parent. So if you pass in `ctx=foo` and
`parents=(foo.node(), nullid)`, then `dirstate.normal()` will be
called for the revert files, even though they might not be clean in
the working copy.
There doesn't seem to be any reason, other than a tiny performance
benefit, to passing the `parents` around instead of looking them up
again in `cmdutil._performrevert()`, so that's what this patch does.
Differential Revision: https://phab.mercurial-scm.org/D8925
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 10 Aug 2020 21:46:47 -0700 |
parents | 490607efc992 |
children | 39ddb1121c4e |
comparison
equal
deleted
inserted
replaced
45374:bd56597b2254 | 45375:8c466bcb0879 |
---|---|
872 # Standins are only updated (to match the hash of largefiles) before | 872 # Standins are only updated (to match the hash of largefiles) before |
873 # commits. Update the standins then run the original revert, changing | 873 # commits. Update the standins then run the original revert, changing |
874 # the matcher to hit standins instead of largefiles. Based on the | 874 # the matcher to hit standins instead of largefiles. Based on the |
875 # resulting standins update the largefiles. | 875 # resulting standins update the largefiles. |
876 @eh.wrapfunction(cmdutil, b'revert') | 876 @eh.wrapfunction(cmdutil, b'revert') |
877 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts): | 877 def overriderevert(orig, ui, repo, ctx, *pats, **opts): |
878 # Because we put the standins in a bad state (by updating them) | 878 # Because we put the standins in a bad state (by updating them) |
879 # and then return them to a correct state we need to lock to | 879 # and then return them to a correct state we need to lock to |
880 # prevent others from changing them in their incorrect state. | 880 # prevent others from changing them in their incorrect state. |
881 with repo.wlock(): | 881 with repo.wlock(): |
882 lfdirstate = lfutil.openlfdirstate(ui, repo) | 882 lfdirstate = lfutil.openlfdirstate(ui, repo) |
935 | 935 |
936 m.matchfn = matchfn | 936 m.matchfn = matchfn |
937 return m | 937 return m |
938 | 938 |
939 with extensions.wrappedfunction(scmutil, b'match', overridematch): | 939 with extensions.wrappedfunction(scmutil, b'match', overridematch): |
940 orig(ui, repo, ctx, parents, *pats, **opts) | 940 orig(ui, repo, ctx, *pats, **opts) |
941 | 941 |
942 newstandins = lfutil.getstandinsstate(repo) | 942 newstandins = lfutil.getstandinsstate(repo) |
943 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) | 943 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) |
944 # lfdirstate should be 'normallookup'-ed for updated files, | 944 # lfdirstate should be 'normallookup'-ed for updated files, |
945 # because reverting doesn't touch dirstate for 'normal' files | 945 # because reverting doesn't touch dirstate for 'normal' files |