[PATCH 4 of 5] dirstate: make writing in-memory changes aware of transaction activity

Yuya Nishihara yuya at tcha.org
Sun Oct 11 12:08:42 CDT 2015


On Mon, 12 Oct 2015 01:11:00 +0900, FUJIWARA Katsunori wrote:
> At Sun, 11 Oct 2015 22:48:01 +0900,
> Yuya Nishihara wrote:
> > 
> > On Sat, 10 Oct 2015 03:59:28 +0900, FUJIWARA Katsunori wrote:
> > > # HG changeset patch
> > > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > > # Date 1444416862 -32400
> > > #      Sat Oct 10 03:54:22 2015 +0900
> > > # Node ID fdbfcbe61c00c684c71335b3be483df5a20d526a
> > > # Parent  0c77ac7b070e4109765ee2e7759c40de7a52b2fc
> > > dirstate: make writing in-memory changes aware of transaction activity
> > 
> > > diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> > > --- a/mercurial/dirstate.py
> > > +++ b/mercurial/dirstate.py
> > > @@ -27,6 +27,15 @@
> > >      def join(self, obj, fname):
> > >          return obj._join(fname)
> > >  
> > > +def _getfsnow(vfs):
> > > +    '''Get "now" timestamp on filesystem'''
> > > +    tmpfd, tmpname = vfs.mkstemp()
> > > +    try:
> > > +        return os.fstat(tmpfd).st_mtime
> > > +    finally:
> > > +        os.close(tmpfd)
> > > +        vfs.unlink(tmpname)
> > [...]
> > > +        if tr:
> > > +            # 'dirstate.write()' is not only for writing in-memory
> > > +            # changes out, but also for dropping ambiguous timestamp.
> > > +            # delayed writing re-raise "ambiguous timestamp issue".
> > > +            # See also the wiki page below for detail:
> > > +            # https://www.mercurial-scm.org/wiki/DirstateTransactionPlan
> > > +
> > > +            # emulate dropping timestamp in 'parsers.pack_dirstate'
> > > +            now = _getfsnow(repo.vfs)
> > > +            dmap = self._map
> > > +            for f, e in dmap.iteritems():
> > > +                if e[0] == 'n' and e[3] == now:
> > > +                    dmap[f] = dirstatetuple(e[0], e[1], e[2], -1)
> > 
> > It seems "now" is float but "e[3]" is int, so "e[3] == now" won't be true
> > on modern filesystem.
> 
> Oh, I forgot that now we should use 'util.statmtimesec' for st_mtime
> in sec. Thank you for pointing out.
> 
> BTW, for consistent st_mtime handling, we should use
> 'util.statmtimesec'-ed st_mtime of 'util.fstat(st)' also for calling
> 'parsers.pack_dirstate()', shouldn't we ?
> 
>   - dirstate.write calls parsers.pack_dirstate" with
>     util.fstat(st).st_mtime directly
> 
>     https://selenic.com/repo/hg/file/6e715040c172/mercurial/dirstate.py#l627
> 
>   - pack_dirstate() in parsers.c uses downcast "(uint32_t)now"
> 
>   - pack_dirstate() in pure/parsers.py uses downcast "int(now)"

Perhaps int will be good for consistency.

I didn't change them at 13272104bb07 because it might cause TypeError if
old .py calls new C pack_dirstate() or vice versa, and I thought floating-point
inaccuracy would be acceptable there from the comment in pure/parsers.py.


More information about the Mercurial-devel mailing list