# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1516610459 -19800 # Node ID 8275ef0991356f6550f50feb8e80bc9360d768cb # Parent f062a4719e46a583b52eed4e4c643aec448c82df amend: query the wdir parent after taking lock (issue5266) If we query wdir parent without taking a lock, that can lead to bugs because the wdir parent can change is another process has changed the wdir parent. One such example of this was issue 5266. When a user is running amend and that amend is waiting for commit message, the user runs another amend which waits for lock. The second amend is waiting for lock, but has already read the description from the parent of working directory to use. Once the first amend completes the wdir parent changes but we still have the description from an old wdir parent. This patch fixes the bug by querying the description after taking lock. Attempts were made to add test for this but the results were unstable because they depend on time in which lock is released. diff -r f062a4719e46 -r 8275ef099135 CHANGELOG --- a/CHANGELOG Mon Jan 22 13:44:32 2018 +0530 +++ b/CHANGELOG Mon Jan 22 14:10:59 2018 +0530 @@ -5,6 +5,7 @@ ---------------------- * fold: fix issue related to bookmarks movement (issue5772) + * amend: take lock before parsing the commit description (issue5266) 7.2.1 --2018-01-20 ------------------- diff -r f062a4719e46 -r 8275ef099135 hgext3rd/evolve/cmdrewrite.py --- a/hgext3rd/evolve/cmdrewrite.py Mon Jan 22 13:44:32 2018 +0530 +++ b/hgext3rd/evolve/cmdrewrite.py Mon Jan 22 14:10:59 2018 +0530 @@ -126,13 +126,13 @@ edit = opts.pop('edit', False) log = opts.get('logfile') opts['amend'] = True - if not (edit or opts['message'] or log): - opts['message'] = repo['.'].description() _resolveoptions(ui, opts) _alias, commitcmd = cmdutil.findcmd('commit', commands.table) try: wlock = repo.wlock() lock = repo.lock() + if not (edit or opts['message'] or log): + opts['message'] = repo['.'].description() rewriteutil.precheck(repo, [repo['.'].rev()], action='amend') return commitcmd[0](ui, repo, *pats, **opts) finally: