def diff_packages(pkg1, pkg2=None):
if pkg2 is None:<EOL><INDENT>it = iter_packages(pkg1.name)<EOL>pkgs = [x for x in it if x.version < pkg1.version]<EOL>if not pkgs:<EOL><INDENT>raise RezError("<STR_LIT>"<EOL>"<STR_LIT>" % pkg1.qualified_name)<EOL><DEDENT>pkgs = sorted(pkgs, key=lambda x: x.version)<EOL>pkg2 = pkgs[-<NUM_LIT:1>]<EOL><DEDENT>def _check_pkg(pkg):<EOL><INDENT>if not (pkg.vcs and pkg.revision):<EOL><INDENT>raise RezError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% pkg.qualified_name)<EOL><DEDENT><DEDENT>_check_pkg(pkg1)<EOL>_check_pkg(pkg2)<EOL>path = mkdtemp(prefix="<STR_LIT>")<EOL>paths = []<EOL>for pkg in (pkg1, pkg2):<EOL><INDENT>print("<STR_LIT>" % pkg.qualified_name)<EOL>path_ = os.path.join(path, pkg.qualified_name)<EOL>vcs_cls_1 = plugin_manager.get_plugin_class("<STR_LIT>", pkg1.vcs)<EOL>vcs_cls_1.export(revision=pkg.revision, path=path_)<EOL>paths.append(path_)<EOL><DEDENT>difftool = config.difftool<EOL>print("<STR_LIT>" % difftool)<EOL>proc = Popen([difftool] + paths)<EOL>proc.wait()<EOL>
Invoke a diff editor to show the difference between the source of two
    packages.

    Args:
        pkg1 (`Package`): Package to diff.
        pkg2 (`Package`): Package to diff against. If None, the next most recent
            package version is used.