'Refresh the index list.
This method verifies if .midx files were superseded (e.g. all of its
contents are in another, bigger .midx file) and removes the superseded
files.
If skip_midx is True, all work on .midx files will be skipped and .midx
files will be removed from the list.
The module-global variable \'ignore_midx\' can force this function to
always act as if skip_midx was True.'

def refresh(self, skip_midx=False):

    self.bloom = None
    self.do_bloom = False
    skip_midx = (skip_midx or ignore_midx)
    d = dict(((p.name, p) for p in self.packs if ((not skip_midx) or (not isinstance(p, midx.PackMidx)))))
    if os.path.exists(self.dir):
        if (not skip_midx):
            midxl = []
            for ix in self.packs:
                if isinstance(ix, midx.PackMidx):
                    for name in ix.idxnames:
                        d[os.path.join(self.dir, name)] = ix
            for full in glob.glob(os.path.join(self.dir, '*.midx')):
                if (not d.get(full)):
                    mx = midx.PackMidx(full)
                    (mxd, mxf) = os.path.split(mx.name)
                    broken = False
                    for n in mx.idxnames:
                        if (not os.path.exists(os.path.join(mxd, n))):
                            log((('warning:    index    %s    missing\n' + '        used    by    %s\n') % (n, mxf)))
                            broken = True
                    if broken:
                        mx.close()
                        del mx
                        unlink(full)
                    else:
                        midxl.append(mx)
            midxl.sort(key=(lambda ix: ((- len(ix)), (- xstat.stat(ix.name).st_mtime))))
            for ix in midxl:
                any_needed = False
                for sub in ix.idxnames:
                    found = d.get(os.path.join(self.dir, sub))
                    if ((not found) or isinstance(found, PackIdx)):
                        any_needed = True
                        break
                if any_needed:
                    d[ix.name] = ix
                    for name in ix.idxnames:
                        d[os.path.join(self.dir, name)] = ix
                elif (not ix.force_keep):
                    debug1(('midx:    removing    redundant:    %s\n' % os.path.basename(ix.name)))
                    ix.close()
                    unlink(ix.name)
        for full in glob.glob(os.path.join(self.dir, '*.idx')):
            if (not d.get(full)):
                try:
                    ix = open_idx(full)
                except GitError as e:
                    add_error(e)
                    continue
                d[full] = ix
        bfull = os.path.join(self.dir, 'bup.bloom')
        if ((self.bloom is None) and os.path.exists(bfull)):
            self.bloom = bloom.ShaBloom(bfull)
        self.packs = list(set(d.values()))
        self.packs.sort((lambda x, y: (- cmp(len(x), len(y)))))
        if (self.bloom and self.bloom.valid() and (len(self.bloom) >= len(self))):
            self.do_bloom = True
        else:
            self.bloom = None
    debug1(('PackIdxList:    using    %d    index%s.\n' % (len(self.packs), (((len(self.packs) != 1) and 'es') or ''))))
