Ejemplo n.º 1
0
    def writeflat(self):
        from edenscm.mercurial import dirstate

        with self._opener("dirstate", "w", atomictemp=True,
                          checkambig=True) as st:
            newdmap = {}
            for k, v in pycompat.iteritems(self):
                newdmap[k] = dirstate.dirstatetuple(*v)

            st.write(
                dirstate.parsers.pack_dirstate(
                    newdmap,
                    self.copymap,
                    self._parents,
                    dirstate._getfsnow(self._opener),
                ))
Ejemplo n.º 2
0
    def _gc(self):
        """Clean up old tree files.

        When repacking, we write out the tree data to a new file.  This allows us
        to rollback transactions without fear of losing dirstate information, as
        the old dirstate file points at the old tree file.

        This leaves old tree files lying around.  We must periodically clean up
        any tree files that are not referred to by any of the dirstate files.
        """
        treesinuse = {}
        for f in ["dirstate", "undo.dirstate", "undo.backup.dirstate"]:
            try:
                treeid = gettreeid(self._opener, f)
                if treeid is not None:
                    treesinuse.setdefault(treeid, set()).add(f)
            except Exception:
                pass
        from . import dirstate  # avoid cycle

        fsnow = dirstate._getfsnow(self._opener)
        maxmtime = fsnow - self._ui.configint("treestate", "mingcage")
        for f in self._opener.listdir():
            if f.startswith(treefileprefix):
                treeid = f[len(treefileprefix):]
                if treeid in treesinuse:
                    self._ui.debug("dirstate tree %s in use by %s\n" %
                                   (treeid, ", ".join(treesinuse[treeid])))
                    continue
                try:
                    if self._opener.stat(f).st_mtime > maxmtime:
                        continue
                except OSError:
                    continue
                self._ui.debug("removing old unreferenced dirstate tree %s\n" %
                               treeid)
                self._opener.tryunlink(f)