예제 #1
0
    def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
        """
        Get's mercurial discovery data used to calculate difference between
        repos and refs

        :param org_repo:
        :type org_repo:
        :param org_ref:
        :type org_ref:
        :param other_repo:
        :type other_repo:
        :param other_ref:
        :type other_ref:
        """

        _org_repo = org_repo._repo
        org_rev_type, org_rev = org_ref

        _other_repo = other_repo._repo
        other_rev_type, other_rev = other_ref

        log.debug('Doing discovery for %s@%s vs %s@%s' % (
                        org_repo, org_ref, other_repo, other_ref)
        )

        #log.debug('Filter heads are %s[%s]' % ('', org_ref[1]))
        org_peer = localrepo.locallegacypeer(_org_repo.local())
        tmp = discovery.findcommonincoming(
                  repo=_other_repo,  # other_repo we check for incoming
                  remote=org_peer,  # org_repo source for incoming
#                  heads=[_other_repo[other_rev].node(),
#                         _org_repo[org_rev].node()],
                  force=True
        )
        return tmp
예제 #2
0
    def _get_changesets(self, org_repo, org_ref, other_repo, other_ref,
                        discovery_data):
        """
        Returns a list of changesets that are incoming from org_repo@org_ref
        to other_repo@other_ref

        :param org_repo:
        :type org_repo:
        :param org_ref:
        :type org_ref:
        :param other_repo:
        :type other_repo:
        :param other_ref:
        :type other_ref:
        :param tmp:
        :type tmp:
        """
        changesets = []
        #case two independent repos
        common, incoming, rheads = discovery_data
        if org_repo != other_repo and incoming:
            obj = findcommonoutgoing(org_repo._repo,
                        localrepo.locallegacypeer(other_repo._repo.local()),
                        force=True)
            revs = obj.missing

            for cs in reversed(map(binascii.hexlify, revs)):
                changesets.append(org_repo.get_changeset(cs))
        else:
            _revset_predicates = {
                    'branch': 'branch',
                    'book': 'bookmark',
                    'tag': 'tag',
                    'rev': 'id',
                }

            revs = [
                "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
                    _revset_predicates[org_ref[0]], org_ref[1],
                    _revset_predicates[other_ref[0]], other_ref[1]
               )
            ]

            out = scmutil.revrange(org_repo._repo, revs)
            for cs in reversed(out):
                changesets.append(org_repo.get_changeset(cs))

        return changesets
예제 #3
0
    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref,
                        discovery_data):
        """
        Returns a list of changesets that are incoming from org_repo@org_ref
        to other_repo@other_ref

        :param org_repo:
        :param org_ref:
        :param other_repo:
        :param other_ref:
        :param tmp:
        """

        changesets = []
        #case two independent repos
        common, incoming, rheads = discovery_data
        if org_repo != other_repo:
            revs = [
                org_repo._repo.lookup(org_ref[1]),
                org_repo._repo.lookup(other_ref[1]),
            ]

            obj = findcommonoutgoing(org_repo._repo,
                        localrepo.locallegacypeer(other_repo._repo.local()),
                        revs,
                        force=True)
            revs = obj.missing

            for cs in map(binascii.hexlify, revs):
                _cs = org_repo.get_changeset(cs)
                changesets.append(_cs)
            # in case we have revisions filter out the ones not in given range
            if org_ref[0] == 'rev' and other_ref[0] == 'rev':
                revs = [x.raw_id for x in changesets]
                start = org_ref[1]
                stop = other_ref[1]
                changesets = changesets[revs.index(start):revs.index(stop) + 1]
        else:
            #no remote compare do it on the same repository
            if alias == 'hg':
                _revset_predicates = {
                        'branch': 'branch',
                        'book': 'bookmark',
                        'tag': 'tag',
                        'rev': 'id',
                    }

                revs = [
                    "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
                        _revset_predicates[other_ref[0]], other_ref[1],
                        _revset_predicates[org_ref[0]], org_ref[1],
                   )
                ]

                out = scmutil.revrange(org_repo._repo, revs)
                for cs in (out):
                    changesets.append(org_repo.get_changeset(cs))
            elif alias == 'git':
                so, se = org_repo.run_git_command(
                    'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
                                                                     other_ref[1])
                )
                ids = re.findall(r'[0-9a-fA-F]{40}', so)
                for cs in (ids):
                    changesets.append(org_repo.get_changeset(cs))

        return changesets
예제 #4
0
파일: diffs.py 프로젝트: break123/rhodecode
def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None,
           remote_compare=False, context=3, ignore_whitespace=False):
    """
    General differ between branches, bookmarks, revisions of two remote or
    local but related repositories

    :param org_repo:
    :param org_ref:
    :param other_repo:
    :type other_repo:
    :type other_ref:
    """

    org_repo_scm = org_repo.scm_instance
    other_repo_scm = other_repo.scm_instance

    org_repo = org_repo_scm._repo
    other_repo = other_repo_scm._repo

    org_ref = org_ref[1]
    other_ref = other_ref[1]

    if org_repo_scm == other_repo_scm:
        log.debug('running diff between %s@%s and %s@%s'
                  % (org_repo.path, org_ref, other_repo.path, other_ref))
        _diff = org_repo_scm.get_diff(rev1=org_ref, rev2=other_ref,
            ignore_whitespace=ignore_whitespace, context=context)
        return _diff

    elif remote_compare:
        opts = diffopts(git=True, ignorews=ignore_whitespace, context=context)
        common, incoming, rheads = discovery_data
        org_repo_peer = localrepo.locallegacypeer(org_repo.local())
        # create a bundle (uncompressed if other repo is not local)
        if org_repo_peer.capable('getbundle'):
            # disable repo hooks here since it's just bundle !
            # patch and reset hooks section of UI config to not run any
            # hooks on fetching archives with subrepos
            for k, _ in org_repo.ui.configitems('hooks'):
                org_repo.ui.setconfig('hooks', k, None)
            unbundle = org_repo.getbundle('incoming', common=None,
                                          heads=None)

            buf = BytesIO()
            while True:
                chunk = unbundle._stream.read(1024 * 4)
                if not chunk:
                    break
                buf.write(chunk)

            buf.seek(0)
            # replace chunked _stream with data that can do tell() and seek()
            unbundle._stream = buf

            ui = make_ui('db')
            bundlerepo = InMemoryBundleRepo(ui, path=org_repo.root,
                                            bundlestream=unbundle)

            return ''.join(patch.diff(bundlerepo,
                                      node1=other_repo[other_ref].node(),
                                      node2=org_repo[org_ref].node(),
                                      opts=opts))

    return ''