Example #1
0
    def iter_tree_contents(self, tree_id, include_trees=False):
        """Iterate the contents of a tree and all subtrees.

        Iteration is depth-first pre-order, as in e.g. os.walk.

        :param tree_id: SHA1 of the tree.
        :param include_trees: If True, include tree objects in the iteration.
        :return: Iterator over TreeEntry namedtuples for all the objects in a
            tree.
        """
        for entry, _ in walk_trees(self, tree_id, None):
            if not stat.S_ISDIR(entry.mode) or include_trees:
                yield entry
Example #2
0
    def iter_tree_contents(self, tree_id, include_trees=False):
        """Iterate the contents of a tree and all subtrees.

        Iteration is depth-first pre-order, as in e.g. os.walk.

        :param tree_id: SHA1 of the tree.
        :param include_trees: If True, include tree objects in the iteration.
        :return: Iterator over TreeEntry namedtuples for all the objects in a
            tree.
        """
        for entry, _ in walk_trees(self, tree_id, None):
            if not stat.S_ISDIR(entry.mode) or include_trees:
                yield entry
Example #3
0
def verify(ui, repo, hgctx):
    """verify that a Mercurial rev matches the corresponding Git rev

    Given a Mercurial revision that has a corresponding Git revision in the map,
    this attempts to answer whether that revision has the same contents as the
    corresponding Git revision.

    """
    handler = repo.githandler

    gitsha = handler.map_git_get(hgctx.hex())
    if not gitsha:
        # TODO deal better with commits in the middle of octopus merges
        raise hgutil.Abort(
            _("no git commit found for rev %s") % hgctx,
            hint=_("if this is an octopus merge, "
                   "verify against the last rev"),
        )

    try:
        gitcommit = handler.git.get_object(pycompat.encodeutf8(gitsha))
    except KeyError:
        raise hgutil.Abort(
            _("git equivalent %s for rev %s not found!") % (gitsha, hgctx))
    if not isinstance(gitcommit, Commit):
        raise hgutil.Abort(
            _("git equivalent %s for rev %s is not a commit!") %
            (gitsha, hgctx))

    ui.status(_("verifying rev %s against git commit %s\n") % (hgctx, gitsha))
    failed = False

    # TODO check commit message and other metadata

    dirkind = stat.S_IFDIR

    hgfiles = set(hgctx)
    gitfiles = set()

    i = 0
    with progress.bar(ui, _("verify"), total=len(hgfiles)) as prog:
        for gitfile, dummy in diff_tree.walk_trees(handler.git.object_store,
                                                   gitcommit.tree, None):
            if gitfile.mode == dirkind:
                continue
            # TODO deal with submodules
            if gitfile.mode == S_IFGITLINK:
                continue
            prog.value = i
            i += 1
            gitfilepath = pycompat.decodeutf8(gitfile.path)
            gitfiles.add(gitfilepath)

            try:
                fctx = hgctx[gitfilepath]
            except error.LookupError:
                # we'll deal with this at the end
                continue

            hgflags = fctx.flags()
            gitflags = handler.convert_git_int_mode(gitfile.mode)
            if hgflags != gitflags:
                ui.write(
                    _("file has different flags: %s (hg '%s', git '%s')\n") %
                    (gitfilepath, hgflags, gitflags))
                failed = True
            if fctx.data() != handler.git[gitfile.sha].data:
                ui.write(_("difference in: %s\n") % gitfilepath)
                failed = True

    if hgfiles != gitfiles:
        failed = True
        missing = gitfiles - hgfiles
        for f in sorted(missing):
            ui.write(_("file found in git but not hg: %s\n") % f)
        unexpected = hgfiles - gitfiles
        for f in sorted(unexpected):
            ui.write(_("file found in hg but not git: %s\n") % f)

    if failed:
        return 1
    else:
        return 0
Example #4
0
def verify(ui, repo, hgctx):
    '''verify that a Mercurial rev matches the corresponding Git rev

    Given a Mercurial revision that has a corresponding Git revision in the map,
    this attempts to answer whether that revision has the same contents as the
    corresponding Git revision.

    '''
    handler = repo.githandler

    gitsha = handler.map_git_get(hgctx.hex())
    if not gitsha:
        # TODO deal better with commits in the middle of octopus merges
        raise hgutil.Abort(_('no git commit found for rev %s') % hgctx,
                           hint=_('if this is an octopus merge, verify against the last rev'))

    try:
        gitcommit = handler.git.get_object(gitsha)
    except KeyError:
        raise hgutil.Abort(_('git equivalent %s for rev %s not found!') %
                           (gitsha, hgctx))
    if not isinstance(gitcommit, Commit):
        raise hgutil.Abort(_('git equivalent %s for rev %s is not a commit!') %
                           (gitsha, hgctx))

    ui.status(_('verifying rev %s against git commit %s\n') % (hgctx, gitsha))
    failed = False

    # TODO check commit message and other metadata

    dirkind = stat.S_IFDIR

    hgfiles = set(hgctx)
    # TODO deal with submodules
    hgfiles.discard('.hgsubstate')
    hgfiles.discard('.hgsub')
    gitfiles = set()

    i = 0
    for gitfile, dummy in diff_tree.walk_trees(handler.git.object_store,
                                               gitcommit.tree, None):
        if gitfile.mode == dirkind:
            continue
        # TODO deal with submodules
        if (gitfile.mode == S_IFGITLINK or gitfile.path == '.hgsubstate'
            or gitfile.path == '.hgsub'):
            continue
        ui.progress('verify', i, total=len(hgfiles))
        i += 1
        gitfiles.add(gitfile.path)

        try:
            fctx = hgctx[gitfile.path]
        except error.LookupError:
            # we'll deal with this at the end
            continue

        hgflags = fctx.flags()
        gitflags = handler.convert_git_int_mode(gitfile.mode)
        if hgflags != gitflags:
            ui.write(_("file has different flags: %s (hg '%s', git '%s')\n") %
                     (gitfile.path, hgflags, gitflags))
            failed = True
        if fctx.data() != handler.git[gitfile.sha].data:
            ui.write(_('difference in: %s\n') % gitfile.path)
            failed = True

    ui.progress('verify', None, total=len(hgfiles))

    if hgfiles != gitfiles:
        failed = True
        missing = gitfiles - hgfiles
        for f in sorted(missing):
            ui.write(_('file found in git but not hg: %s\n') % f)
        unexpected = hgfiles - gitfiles
        for f in sorted(unexpected):
            ui.write(_('file found in hg but not git: %s\n') % f)

    if failed:
        return 1
    else:
        return 0
Example #5
0
def verify(ui, repo, hgctx):
    '''verify that a Mercurial rev matches the corresponding Git rev

    Given a Mercurial revision that has a corresponding Git revision in the
    map, this attempts to answer whether that revision has the same contents as
    the corresponding Git revision.

    '''
    handler = repo.githandler

    gitsha = handler.map_git_get(hgctx.hex())
    if not gitsha:
        # TODO deal better with commits in the middle of octopus merges
        raise error.Abort(
            _(b'no git commit found for rev %s') % hgctx,
            hint=_(b'if this is an octopus merge, '
                   b'verify against the last rev'),
        )

    try:
        gitcommit = handler.git.get_object(gitsha)
    except KeyError:
        raise error.Abort(
            _(b'git equivalent %s for rev %s not found!') % (gitsha, hgctx))
    except Exception:
        ui.traceback()
        raise error.Abort(
            _(b'git equivalent %s for rev %s is corrupt!') % (gitsha, hgctx),
            hint=b're-run with --traceback for details',
        )

    if not isinstance(gitcommit, Commit):
        raise error.Abort(
            _(b'git equivalent %s for rev %s is not a commit!') %
            (gitsha, hgctx))

    ui.status(_(b'verifying rev %s against git commit %s\n') % (hgctx, gitsha))
    failed = False

    # TODO check commit message and other metadata

    dirkind = stat.S_IFDIR

    hgfiles = set(hgctx)
    # TODO deal with submodules
    hgfiles.discard(b'.hgsubstate')
    hgfiles.discard(b'.hgsub')
    gitfiles = set()

    with ui.makeprogress(b'verify', total=len(hgfiles)) as progress:
        for gitfile, dummy in diff_tree.walk_trees(handler.git.object_store,
                                                   gitcommit.tree, None):
            if gitfile.mode == dirkind:
                continue
            # TODO deal with submodules
            if (gitfile.mode == S_IFGITLINK or gitfile.path == b'.hgsubstate'
                    or gitfile.path == b'.hgsub'):
                continue
            progress.increment()
            gitfiles.add(gitfile.path)

            try:
                fctx = hgctx[gitfile.path]
            except error.LookupError:
                # we'll deal with this at the end
                continue

            hgflags = fctx.flags()
            gitflags = git2hg.convert_git_int_mode(gitfile.mode)
            if hgflags != gitflags:
                ui.write(
                    _(b"file has different flags: %s (hg '%s', git '%s')\n") %
                    (gitfile.path, hgflags, gitflags))
                failed = True
            if fctx.data() != handler.git[gitfile.sha].data:
                ui.write(_(b'difference in: %s\n') % gitfile.path)
                failed = True

    if hgfiles != gitfiles:
        failed = True
        missing = gitfiles - hgfiles
        for f in sorted(missing):
            ui.write(_(b'file found in git but not hg: %s\n') % f)
        unexpected = hgfiles - gitfiles
        for f in sorted(unexpected):
            ui.write(_(b'file found in hg but not git: %s\n') % f)

    if failed:
        return 1
    else:
        return 0