# HG changeset patch # User Alexis S. L. Carvalho # Date 1206317004 10800 # Node ID 6440e25a1ba3fb3383076c0ab5a90ffecd6a4e27 # Parent 53912d30ac402b5f412bfcae56a7e3bc98b2bbd1 localrepo.commit: grab locks before getting the list of files to commit Somebody may change the dirstate after we've determined the parents of the working dir and run repo.status, but before we called wlock(). This should also fix issue997, where backout would change a file without changing its size and then call repo.commit without passing the list of files. If this happened in less than one second, we wouldn't detect any file changes - the in-memory dirstate still has the cached stat data for that file. Grabbing the wlock early causes the dirstate to be invalidated and we end up reading the dirstate file again, which has that file marked for lookup (size == -1). A better fix would be for backout to give repo.commit the exact list of files, but that'll require some changes to the revert operation. A significant user-visible change is that the precommit hook is always run with both locks grabbed - previously, hg commit would run it before grabbing any locks, but hg import would run it after grabbing locks. diff -r 53912d30ac40 -r 6440e25a1ba3 mercurial/localrepo.py --- a/mercurial/localrepo.py Sun Mar 23 21:03:24 2008 -0300 +++ b/mercurial/localrepo.py Sun Mar 23 21:03:24 2008 -0300 @@ -752,6 +752,8 @@ if files: files = util.unique(files) try: + wlock = self.wlock() + lock = self.lock() commit = [] remove = [] changed = [] @@ -810,8 +812,6 @@ self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) - wlock = self.wlock() - lock = self.lock() tr = self.transaction() trp = weakref.proxy(tr)