Beispiel #1
0
    def _cleanupdirectory(self, rootdir):
        """Removes the empty directories and unnecessary files within the root
        directory recursively. Note that this method does not remove the root
        directory itself. """

        oldfiles = set()
        otherfiles = set()
        # osutil.listdir returns stat information which saves some rmdir/listdir
        # syscalls.
        for name, mode in util.osutil.listdir(rootdir):
            if stat.S_ISDIR(mode):
                dirpath = os.path.join(rootdir, name)
                self._cleanupdirectory(dirpath)

                # Now that the directory specified by dirpath is potentially
                # empty, try and remove it.
                try:
                    os.rmdir(dirpath)
                except OSError:
                    pass

            elif stat.S_ISREG(mode):
                if name.endswith('_old'):
                    oldfiles.add(name[:-4])
                else:
                    otherfiles.add(name)

        # Remove the files which end with suffix '_old' and have no
        # corresponding file without the suffix '_old'. See addremotefilelognode
        # method for the generation/purpose of files with '_old' suffix.
        for filename in oldfiles - otherfiles:
            filepath = os.path.join(rootdir, filename + '_old')
            util.tryunlink(filepath)
Beispiel #2
0
    def _cleanupdirectory(self, rootdir):
        """Removes the empty directories and unnecessary files within the root
        directory recursively. Note that this method does not remove the root
        directory itself. """

        oldfiles = set()
        otherfiles = set()
        # osutil.listdir returns stat information which saves some rmdir/listdir
        # syscalls.
        for name, mode in util.osutil.listdir(rootdir):
            if stat.S_ISDIR(mode):
                dirpath = os.path.join(rootdir, name)
                self._cleanupdirectory(dirpath)

                # Now that the directory specified by dirpath is potentially
                # empty, try and remove it.
                try:
                    os.rmdir(dirpath)
                except OSError:
                    pass

            elif stat.S_ISREG(mode):
                if name.endswith('_old'):
                    oldfiles.add(name[:-4])
                else:
                    otherfiles.add(name)

        # Remove the files which end with suffix '_old' and have no
        # corresponding file without the suffix '_old'. See addremotefilelognode
        # method for the generation/purpose of files with '_old' suffix.
        for filename in oldfiles - otherfiles:
            filepath = os.path.join(rootdir, filename + '_old')
            util.tryunlink(filepath)
Beispiel #3
0
def ancestorcache(path):
    # simple cache to speed up revlog.ancestors
    try:
        db = anydbm.open(path, 'c')
    except anydbm.error:
        # database locked, fail gracefully
        yield
    else:
        def revlogancestor(orig, self, a, b):
            key = a + b
            try:
                return db[key]
            except KeyError:
                result = orig(self, a, b)
                db[key] = result
                return result
        extensions.wrapfunction(revlog.revlog, 'ancestor', revlogancestor)
        try:
            yield
        finally:
            extensions.unwrapfunction(revlog.revlog, 'ancestor', revlogancestor)
            try:
                db.close()
            except Exception:
                # database corruption, we just nuke the database
                util.tryunlink(path)
Beispiel #4
0
def ancestorcache(path):
    # simple cache to speed up revlog.ancestors
    try:
        db = anydbm.open(path, 'c')
    except anydbm.error:
        # database locked, fail gracefully
        yield
    else:
        def revlogancestor(orig, self, a, b):
            key = a + b
            try:
                return db[key]
            except KeyError:
                result = orig(self, a, b)
                db[key] = result
                return result
        extensions.wrapfunction(revlog.revlog, 'ancestor', revlogancestor)
        try:
            yield
        finally:
            extensions.unwrapfunction(revlog.revlog, 'ancestor', revlogancestor)
            try:
                db.close()
            except Exception:
                # database corruption, we just nuke the database
                util.tryunlink(path)
Beispiel #5
0
    def cleanup(self, ledger):
        ui = self.ui
        entries = ledger.sources.get(self, [])
        count = 0
        for entry in entries:
            if entry.gced or (entry.datarepacked and entry.historyrepacked):
                ui.progress(_("cleaning up"), count, unit="files",
                            total=len(entries))
                path = self._getfilepath(entry.filename, entry.node)
                util.tryunlink(path)
            count += 1
        ui.progress(_("cleaning up"), None)

        # Clean up the repo cache directory.
        self._cleanupdirectory(self._getrepocachepath())
Beispiel #6
0
    def cleanup(self, ledger):
        ui = self.ui
        entries = ledger.sources.get(self, [])
        count = 0
        progress = ui.makeprogress(_("cleaning up"), unit="files",
                                   total=len(entries))
        for entry in entries:
            if entry.gced or (entry.datarepacked and entry.historyrepacked):
                progress.update(count)
                path = self._getfilepath(entry.filename, entry.node)
                util.tryunlink(path)
            count += 1
        progress.complete()

        # Clean up the repo cache directory.
        self._cleanupdirectory(self._getrepocachepath())