[PATCH] Use a predictable folder for temp files

Jason Harris jason at jasonfharris.com
Sat Jan 15 18:44:20 CST 2011


On Jan 15, 2011, at 4:37 PM, Steven Streeting wrote:

> # HG changeset patch
> # User Steve Streeting <steve at stevestreeting.com>
> # Date 1295104582 0
> # Node ID 8f72d2f6c26322c235602280ea0a2b3debf37b06
> # Parent  20a54bdf232832d3d6c4e4a43361dc84ec73dca0
> Move files used by _checklink and _checkexec to a .hgtmp subfolder rather than the root folder
> This is needed because any software which watches the repository tree for changes gets notified of these temp files, which causes a false positive on repo changes, which can basically loop forever:
> 1. File event is received
> 2. Program checks with hg diff / hg status
> 3. hg creates temp file to serve the request
> 4. Goto 1
> The need to put the file in a folder, rather than simply naming the file predictably, is because for example the Mac OS X kernel file events notification system FSEvents only gives information to the containing folder, not to the file level. Also, kernel events are in a deferred queue so it is not possible to use some other kind of synchronous workaround such as ignoring events just while hg is called.
> More discussion on this topic can be found in this tracker item: http://mercurial.selenic.com/bts/issue2591
> 
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -113,11 +113,25 @@
> 
>     @propertycache
>     def _checklink(self):
> -        return util.checklink(self._root)
> +        # Use '.hgtmp' folder so FSEvents can identify & ignore
> +        d = os.path.join(self._root, '.hgtmp')
> +        try:
> +            if not os.path.isdir(d):
> +                os.mkdir(d)
> +            return util.checklink(d)
> +        except (IOError, OSError):
> +            return False
> 
>     @propertycache
>     def _checkexec(self):
> -        return util.checkexec(self._root)
> +        # Use '.hgtmp' folder so FSEvents can identify & ignore
> +        d = os.path.join(self._root, '.hgtmp')
> +        try:
> +            if not os.path.isdir(d):
> +                os.mkdir(d)
> +            return util.checkexec(d)
> +        except (IOError, OSError):
> +            return False
> 
>     @propertycache
>     def _checkcase(self):

I would also strongly support the spirit of this patch which moves the temp files into their own consolidated directory, or manages to work around the problem that us GUI writers face [3]. In fact I have been doing exactly this kind of patch for MacHg since I think the very first launched version of MacHg. There is a big long thread about this starting with [1] and specifically the same patch you have above at [2] and then general comments [3]:

[1] http://www.selenic.com/pipermail/mercurial/2010-April/031329.html
[2] http://www.selenic.com/pipermail/mercurial/2010-April/031342.html
[3] http://www.selenic.com/pipermail/mercurial-devel/2010-June/021839.html

In [2]  I basically did *exactly* the thing you are doing here for *exactly* the same reasons... 

There are other comments floating around and the final patch I use in MacHg was kindly written by Martin Geisler for me. (Its included in the MacHg sources and also posted here http://mercurial.selenic.com/bts/issue2591)

In any case, basically any Mac GUI that is even moderately decent will need to do such a thing, and thus likely they will almost inevitably have to have their own bundled and patched copy of Mercurial unless we can include something in the spirt of this patch.

Cheers,
  Jas


More information about the Mercurial-devel mailing list