comparison mercurial/commands.py @ 50006:feaa5d08bb19

locking: take the `wlock` for the full `hg forget` duration Otherwise, there is a race condition window between the time we resolve the file to forget with the matcher and the time we lock the repo and modify the dirstate. For example, the working copy might have been updated away, or purged, and the matched files would no longer be correct.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 13 Dec 2022 16:26:13 +0100
parents 16b78c0de506
children 2aacd560cf59
comparison
equal deleted inserted replaced
50005:16b78c0de506 50006:feaa5d08bb19
2963 2963
2964 opts = pycompat.byteskwargs(opts) 2964 opts = pycompat.byteskwargs(opts)
2965 if not pats: 2965 if not pats:
2966 raise error.InputError(_(b'no files specified')) 2966 raise error.InputError(_(b'no files specified'))
2967 2967
2968 m = scmutil.match(repo[None], pats, opts) 2968 with repo.wlock():
2969 dryrun, interactive = opts.get(b'dry_run'), opts.get(b'interactive') 2969 m = scmutil.match(repo[None], pats, opts)
2970 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) 2970 dryrun, interactive = opts.get(b'dry_run'), opts.get(b'interactive')
2971 rejected = cmdutil.forget( 2971 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
2972 ui, 2972 rejected = cmdutil.forget(
2973 repo, 2973 ui,
2974 m, 2974 repo,
2975 prefix=b"", 2975 m,
2976 uipathfn=uipathfn, 2976 prefix=b"",
2977 explicitonly=False, 2977 uipathfn=uipathfn,
2978 dryrun=dryrun, 2978 explicitonly=False,
2979 interactive=interactive, 2979 dryrun=dryrun,
2980 )[0] 2980 interactive=interactive,
2981 )[0]
2981 return rejected and 1 or 0 2982 return rejected and 1 or 0
2982 2983
2983 2984
2984 @command( 2985 @command(
2985 b'graft', 2986 b'graft',