def print_loot(self, name, project, z_project, args):
        # Print a list of out of tree outstanding patches in the given
        # project.
        #
        # name: project name
        # project: the west.manifest.Project instance in the NCS manifest
        # z_project: the Project instance in the upstream manifest
        name_path = _name_and_path(project)

        # Get the upstream revision of the project. The zephyr project
        # has to be treated as a special case.
        if name == 'zephyr':
            z_rev = self.zephyr_rev
        else:
            z_rev = z_project.revision

        try:
            nsha = project.sha(project.revision)
            project.git('cat-file -e ' + nsha)
        except subprocess.CalledProcessError:
            log.wrn(f"{name_path}: can't get loot; please run "
                    f'"west update" (need revision {project.revision})')
            return
        try:
            zsha = z_project.sha(z_rev)
            z_project.git('cat-file -e ' + zsha)
        except subprocess.CalledProcessError:
            log.wrn(f"{name_path}: can't get loot; please fetch upstream URL "
                    f'{z_project.url} (need revision {z_project.revision})')
            return

        try:
            analyzer = nwh.RepoAnalyzer(project, z_project, project.revision,
                                        z_rev)
        except nwh.InvalidRepositoryError as ire:
            log.die(f"{name_path}: {str(ire)}")

        try:
            loot = analyzer.downstream_outstanding
        except nwh.UnknownCommitsError as uce:
            log.die(f'{name_path}: unknown commits: {str(uce)}')

        if not loot and log.VERBOSE <= log.VERBOSE_NONE:
            # Don't print output if there's no loot unless verbose
            # mode is on.
            return

        log.banner(name_path)
        log.inf(f'NCS commit: {nsha}, upstream commit: {zsha}')
        log.inf('OOT patches: ' + (f'{len(loot)} total' if loot else 'none') +
                (', output limited by --file' if args.files else ''))
        for c in loot:
            if args.files and not nwh.commit_affects_files(c, args.files):
                log.dbg(f"skipping {c.oid}; it doesn't affect file filter",
                        level=log.VERBOSE_VERY)
                continue
            if args.sha_only:
                log.inf(str(c.oid))
            else:
                log.inf(f'- {c.oid} {nwh.commit_shortlog(c)}')
Esempio n. 2
0
    def print_loot(self, name, project, z_project, args):
        # Print a list of out of tree outstanding patches in the given
        # project.
        #
        # name: project name
        # project: the west.manifest.Project instance in the NCS manifest
        # z_project: the Project instance in the upstream manifest
        msg = project.format('{name_and_path} outstanding downstream patches:')

        # Get the upstream revision of the project. The zephyr project
        # has to be treated as a special case.
        if name == 'zephyr':
            z_rev = self.zephyr_rev
            msg += ' NOTE: {} *must* be up to date'.format(z_rev)
        else:
            z_rev = z_project.revision

        log.banner(msg)

        try:
            nsha = project.sha(project.revision)
            project.git('cat-file -e ' + nsha)
        except subprocess.CalledProcessError:
            log.wrn(
                "can't get loot; please run \"west update {}\"".format(
                    project.name),
                '(need revision {})'.format(project.revision))
            return
        try:
            zsha = z_project.sha(z_project.revision)
            z_project.git('cat-file -e ' + zsha)
        except subprocess.CalledProcessError:
            log.wrn("can't get loot; please fetch upstream URL", z_project.url,
                    '(need revision {})'.format(z_project.revision))
            return

        try:
            analyzer = nwh.RepoAnalyzer(project, z_project, project.revision,
                                        z_rev)
        except nwh.InvalidRepositoryError as ire:
            log.die(str(ire))
        try:
            for c in analyzer.downstream_outstanding:
                if args.files and not nwh.commit_affects_files(c, args.files):
                    log.dbg(
                        'skipping {}; it does not affect file filter'.format(
                            c.oid),
                        level=log.VERBOSE_VERY)
                    continue
                if args.sha_only:
                    log.inf(str(c.oid))
                else:
                    log.inf('- {} {}'.format(c.oid, nwh.commit_shortlog(c)))
        except nwh.UnknownCommitsError as uce:
            log.die('unknown commits:', str(uce))
Esempio n. 3
0
def likely_merged(np, zp, nsha, zsha):
    analyzer = nwh.RepoAnalyzer(np, zp, nsha, zsha)
    likely_merged = analyzer.likely_merged
    if likely_merged:
        # likely_merged is a map from downstream commits to
        # lists of upstream commits that look similar.
        log.msg('downstream patches which are likely merged upstream',
                '(revert these if appropriate):', color=log.WRN_COLOR)
        for dc, ucs in likely_merged.items():
            log.inf(f'- {dc.oid} ({nwh.commit_shortlog(dc)})\n'
                    '  Similar upstream commits:')
            for uc in ucs:
                log.inf(f'  {uc.oid} ({nwh.commit_shortlog(uc)})')
    else:
        log.inf('no downstream patches seem to have been merged upstream')
Esempio n. 4
0
def likely_merged(np, zp, nsha, zsha):
    analyzer = nwh.RepoAnalyzer(np, zp, nsha, zsha)
    likely_merged = analyzer.likely_merged
    if likely_merged:
        # likely_merged is a map from downstream commits to
        # lists of upstream commits that look similar.
        log.msg('downstream patches which are likely merged upstream',
                '(revert these if appropriate):', color=log.WRN_COLOR)
        for dc, ucs in likely_merged.items():
            if len(ucs) == 1:
                log.inf(f'- {dc.oid} {nwh.commit_shortlog(dc)}')
                log.inf(f'  Similar upstream shortlog:\n'
                        f'  {ucs[0].oid} {nwh.commit_shortlog(ucs[0])}')
            else:
                log.inf(f'- {dc.oid} {nwh.commit_shortlog(dc)}\n'
                        '  Similar upstream shortlogs:')
                for i, uc in enumerate(ucs, start=1):
                    log.inf(f'    {i}. {uc.oid} {nwh.commit_shortlog(uc)}')
    else:
        log.dbg('no downstream patches seem to have been merged upstream')
Esempio n. 5
0
    def allowed_project(self, zp):
        nn = self.to_ncs_name(zp)
        np = self.ncs_pmap[nn]

        if np.name == 'zephyr':
            nrev = self.manifest.get_projects(['zephyr'])[0].revision
            zrev = self.zephyr_sha
        else:
            nrev = np.revision
            zrev = zp.revision

        log.small_banner(zp.format('{ncs_name} ({path}):', ncs_name=nn))

        try:
            nsha = np.sha(nrev)
            np.git('cat-file -e ' + nsha)
        except subprocess.CalledProcessError:
            log.wrn("can't compare; please run \"west update {}\"".format(nn),
                    '(need revision {})'.format(np.revision))
            return
        try:
            zsha = np.sha(zrev)
            np.git('cat-file -e ' + zsha)
        except subprocess.CalledProcessError:
            log.wrn("can't compare; please fetch upstream URL", zp.url,
                    '(need revision {})'.format(zp.revision))
            return

        upstream_rev = 'upstream revision: ' + zrev
        if zrev != zsha:
            upstream_rev += ' ({})'.format(zsha)

        downstream_rev = 'NCS revision: ' + nrev
        if nrev != nsha:
            downstream_rev += ' ({})'.format(nsha)

        cp = np.git('rev-list --left-right --count {}...{}'.format(zsha, nsha),
                    capture_stdout=True)
        behind, ahead = [int(c) for c in cp.stdout.split()]

        if zsha == nsha:
            status = 'up to date'
        elif ahead and not behind:
            status = 'ahead by {} commits'.format(ahead)
        elif np.is_ancestor_of(nsha, zsha):
            status = (
                'behind by {} commits, can be fast-forwarded to {}'.format(
                    behind, zsha))
        else:
            status = ('diverged from upstream: {} ahead, {} behind'.format(
                ahead, behind))

        if 'behind' in status or 'diverged' in status:
            color = log.WRN_COLOR
        else:
            color = log.INF_COLOR

        log.msg(status, color=color)
        log.inf(upstream_rev)
        log.inf(downstream_rev)

        analyzer = nwh.RepoAnalyzer(np, zp, nsha, zsha)
        likely_merged = analyzer.likely_merged
        if likely_merged:
            # likely_merged is a map from downstream commits to
            # lists of upstream commits that look similar.
            log.msg('downstream patches which are likely merged upstream',
                    '(revert these if appropriate):',
                    color=log.WRN_COLOR)
            for dc, ucs in likely_merged.items():
                log.inf('- {} ({})\n  Similar upstream commits:'.format(
                    dc.oid, nwh.commit_shortlog(dc)))
                for uc in ucs:
                    log.inf('  {} ({})'.format(uc.oid,
                                               nwh.commit_shortlog(uc)))
        else:
            log.inf('no downstream patches seem to have been merged upstream')