Beispiel #1
0
def merge_wikitext(ui_, repo, base_dir, tmp_file, in_stream):
    """ Merge changes from a submission zip file into the
        repository. """

    # HgFileOverlay to read bundle files with.
    prev_overlay = HgFileOverlay(ui_, repo, base_dir, tmp_file)

    # Direct overlay to write updates into the repo.
    head_overlay = DirectFiles(os.path.join(repo.root, base_dir))

    arch = ZipFile(in_stream, 'r')
    try:
        base_ver, dummy = unpack_info(arch.read('__INFO__'))
        if not has_version(repo, base_ver):
            # REDFLAG: Think. What about 000000000000?
            #          It is always legal. hmmmm...
            raise SubmitError("Base version: %s not in repository." %
                              base_ver[:12], True)

        # Still need to check for illegal submissions.
        prev_overlay.version = base_ver

        # REDFLAG: revisit.
        # just assert in forking_extract_wikitext and
        # get rid of extra checking / exception raising?
        check_base_shas(arch, prev_overlay)
        # Hmmmm... checking against a version of readonly.txt
        # which may be later than the one that the submitter
        # used.
        check_writable(head_overlay, arch)
        check_merges([name for name in arch.namelist()
                      if name != '__INFO__'],
                     # pylint gives spurious E1101 here ???
                     #pylint: disable-msg=E1101
                     prev_overlay.list_pages(os.path.join(prev_overlay.
                                                          base_path,
                                                          'wikitext')),
                     ArchiveHasher(arch).hexdigest)

        # created, modified, removed, skipped, forked
        op_lut = (set([]), set([]), set([]), set([]), set([]))

        for name in arch.namelist():
            # check_base_sha validates wikinames.
            if name == "__INFO__":
                continue
            action, versioned_name = forking_extract_wikitext(arch,
                                                              prev_overlay,
                                                              head_overlay,
                                                              name)
            op_lut[action].add(versioned_name)
        return op_lut
    finally:
        arch.close()
Beispiel #2
0
    def modtime(self, path, non_overlayed=False):
        """ Return the modtime for the file."""
        if non_overlayed:
            # Hmmm commit time for changeset, not file. Good enough.
            return int(self.repo.changectx(self.version).date()[0])

        overlay = self.overlay_path(path)
        if os.path.exists(overlay) and os.path.getsize(overlay) > 0:
            return DirectFiles.modtime(self, overlay)

        return int(self.repo.changectx(self.version).date()[0])
Beispiel #3
0
    def read(self, path, mode='rb', non_overlayed=False):
        """ Read a file. """
        if non_overlayed:
            return unicode(
                get_hg_file(self.repo, self.repo_path(path),
                            self.version, self.tmp_file),
                WIKITEXT_ENCODING)
        overlayed = self.overlay_path(path)
        if os.path.exists(overlayed):
            return DirectFiles.read(self, overlayed, mode)

        return unicode(get_hg_file(self.repo, self.repo_path(path),
                                   self.version, self.tmp_file),
                       WIKITEXT_ENCODING)
Beispiel #4
0
    def list_pages(self, path, non_overlayed=False):
        """ IFileFunctions implementation. """
        if non_overlayed:
            return self.repo_pages()

        overlay_pages = set([])
        overlay = self.overlay_path(path)
        if os.path.exists(overlay):
            overlay_pages = set(DirectFiles.list_pages(self, overlay))

        deleted = set([])
        for name in overlay_pages:
            if os.path.getsize(os.path.join(overlay, name)) == 0:
                deleted.add(name)

        return list(overlay_pages.union(set(self.repo_pages(path)) - deleted))