[PATCH 2 of 2 STABLE] store: add auto detection for hardlink count blindness (issue1866)

Matt Mackall mpm at selenic.com
Wed Nov 3 15:58:51 CDT 2010


On Wed, 2010-11-03 at 21:18 +0100, Adrian Buehlmann wrote:
> On 03.11.2010 17:52, Matt Mackall wrote:
> > ..and then I went on to point out that we shouldn't even be testing
> > nlinks on 'w'rite (where COW is pointless), but only on 'a'ppend. On
> > write, we should (and usually do, see localrepo.wwrite) unconditionally
> > break links by first unlinking any existing file.
> 
> So, should we do
> 
> diff -r 0e0a52bd58f9 mercurial/util.py
> --- a/mercurial/util.py Thu Oct 21 16:04:34 2010 -0500
> +++ b/mercurial/util.py Wed Nov 03 21:13:03 2010 +0100
> @@ -871,7 +871,10 @@
>              if atomictemp:
>                  return atomictempfile(f, mode, self.createmode)
>              if nlink > 1:
> -                rename(mktempcopy(f), f)
> +                if 'w' in mode:
> +                    os.unlink(f)
> +                else:
> +                    rename(mktempcopy(f), f)
>          fp = posixfile(f, mode)
>          if nlink == 0:
>              self._fixfilemode(f)
> 
> as a first step?

No, we should skip looking at nlinks -entirely-. Just do what
localrepo.wwrite does.

System calls are not cheap. Imagine that each system call is roughly
equal to 100-1000 basic Python statements (the low end being Linux and
the high end being Windows/OS X). Doing one unlink wrapped in an
exception check is much cheaper than a stat (possibly including an extra
open and close!) followed by an unlink.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list