Esempio n. 1
0
    def allowed_project(self, zp):
        nn = to_ncs_name(zp)
        np = self.ncs_pmap[nn]
        banner = f'{nn} ({zp.path}):'

        nrev = 'refs/heads/manifest-rev'
        if np.name == 'zephyr':
            zrev = self.zephyr_sha
        else:
            zrev = zp.revision

        nsha = self.checked_sha(np, nrev)
        zsha = self.checked_sha(zp, zrev)

        if not np.is_cloned() or nsha is None or zsha is None:
            log.small_banner(banner)
            if not np.is_cloned():
                log.wrn('project is not cloned; please run "west update"')
            elif nsha is None:
                log.wrn(f"can't compare; please run \"west update {nn}\" "
                        f'(need revision {np.revision})')
            elif zsha is None:
                log.wrn(f"can't compare; please fetch upstream URL {zp.url} "
                        f'(need revision {zp.revision})')
            return

        cp = np.git(f'rev-list --left-right --count {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 = f'ahead by {ahead} commits'
        elif np.is_ancestor_of(nsha, zsha):
            status = f'behind by {behind} commits; can be fast-forwarded'
        else:
            status = f'diverged: {ahead} ahead, {behind} behind'

        commits = f'NCS commit: {nsha}, upstream commit: {zsha}'
        if 'up to date' in status or 'ahead by' in status:
            if log.VERBOSE > log.VERBOSE_NONE:
                # Up to date or ahead: only print in verbose mode.
                log.small_banner(banner)
                log.inf(commits)
                log.inf(status)
                likely_merged(np, zp, nsha, zsha)
        else:
            # Behind or diverged: always print.
            log.small_banner(banner)
            log.inf(commits)
            log.msg(status, color=log.WRN_COLOR)
            likely_merged(np, zp, nsha, zsha)
Esempio n. 2
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. 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():
            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. 4
0
    def allowed_project(self, zp):
        nn = to_ncs_name(zp)
        np = self.ncs_pmap[nn]
        # is_imported is true if we imported this project from the
        # zephyr manifest rather than defining it directly ourselves
        # in nrf/west.yml.
        is_imported = nn in self.imported_pmap
        imported = ', imported from zephyr' if is_imported else ''
        banner = f'{nn} ({zp.path}){imported}:'

        nrev = 'refs/heads/manifest-rev'
        if np.name == 'zephyr':
            zrev = self.zephyr_sha
        else:
            zrev = zp.revision

        nsha = self.checked_sha(np, nrev)
        zsha = self.checked_sha(zp, zrev)

        if not np.is_cloned() or nsha is None or zsha is None:
            log.small_banner(banner)
            if not np.is_cloned():
                log.wrn('project is not cloned; please run "west update"')
            elif nsha is None:
                log.wrn(f"can't compare; please run \"west update {nn}\" "
                        f'(need revision {np.revision})')
            elif zsha is None:
                log.wrn(f"can't compare; please fetch upstream URL {zp.url} "
                        f'(need revision {zp.revision})')
            return

        cp = np.git(f'rev-list --left-right --count {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 = f'ahead by {ahead} commit' + ("s" if ahead > 1 else "")
        elif np.is_ancestor_of(nsha, zsha):
            status = f'behind by {behind} commit' + ("s" if behind > 1 else "")
        else:
            status = f'diverged: {ahead} ahead, {behind} behind'

        commits = f'NCS commit: {nsha}, upstream commit: {zsha}'
        if 'up to date' in status or 'ahead by' in status:
            if log.VERBOSE > log.VERBOSE_NONE:
                # Up to date or ahead: only print in verbose mode.
                log.small_banner(banner)
                log.inf(commits)
                log.inf(status)
                likely_merged(np, zp, nsha, zsha)
        else:
            # Behind or diverged: always print.
            if is_imported and 'behind by' in status:
                status += ' and imported: update by doing zephyr mergeup'

            log.small_banner(banner)
            log.inf(commits)
            log.msg(status, color=log.WRN_COLOR)
            likely_merged(np, zp, nsha, zsha)
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')
Esempio n. 6
0
    def allowed_project(self, zp):
        nn = self.to_ncs_name(zp)
        np = self.ncs_pmap[nn]
        banner = zp.format('{ncs_name} ({path}):', ncs_name=nn)

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

        nsha = self.checked_sha(np, nrev)
        zsha = self.checked_sha(zp, zrev)

        if not np.is_cloned() or nsha is None or zsha is None:
            log.small_banner(banner)
            if not np.is_cloned():
                log.wrn('project is not cloned; please run "west update"')
            elif nsha is None:
                log.wrn(
                    "can't compare; please run \"west update {}\"".format(nn),
                    '(need revision {})'.format(np.revision))
            elif zsha is None:
                log.wrn("can't compare; please fetch upstream URL", zp.url,
                        '(need revision {})'.format(zp.revision))
            return

        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))

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

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

        if 'up to date' in status or 'ahead by' in status:
            if log.VERBOSE > log.VERBOSE_NONE:
                # Up to date or ahead: only print in verbose mode.
                log.small_banner(banner)
                status += ', ' + downstream_rev
                if 'ahead by' in status:
                    status += ', ' + upstream_rev
                log.inf(status)
                self.likely_merged(np, zp, nsha, zsha)
        else:
            # Behind or diverged: always print.
            log.small_banner(banner)
            log.msg(status, color=log.WRN_COLOR)
            log.inf(upstream_rev)
            log.inf(downstream_rev)
            self.likely_merged(np, zp, nsha, zsha)