Exemplo n.º 1
0
    def testSimpleFork(self):
        with phlgitu_fixture.lone_worker_context() as worker:

            # pylint has faulty detection here
            # pylint: disable=not-callable
            worker.repo("branch", "fork")
            worker.commit_new_file("add ONLY_MASTER", "ONLY_MASTER")
            worker.repo("checkout", "fork")
            # pylint: enable=not-callable

            worker.commit_new_file("add ONLY_FORK", "ONLY_FORK")
            worker.commit_new_file("add ONLY_FORK2", "ONLY_FORK2")
            rawDiff = phlgit_diff.raw_diff_range_to_here(
                worker.repo, "master")
            rawDiff2 = phlgit_diff.raw_diff_range(
                worker.repo, "master", "fork")
            rawDiff3 = phlgit_diff.raw_diff_range(
                worker.repo, "master", "fork", 1000)
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff))
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff2))
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff3))
    def testSimpleFork(self):
        with phlgitu_fixture.lone_worker_context() as worker:

            # pylint has faulty detection here
            # pylint: disable=not-callable
            worker.repo("branch", "fork")
            worker.commit_new_file("add ONLY_MASTER", "ONLY_MASTER")
            worker.repo("checkout", "fork")
            # pylint: enable=not-callable

            worker.commit_new_file("add ONLY_FORK", "ONLY_FORK")
            worker.commit_new_file("add ONLY_FORK2", "ONLY_FORK2")
            rawDiff = phlgit_diff.raw_diff_range_to_here(worker.repo, "master")
            rawDiff2 = phlgit_diff.raw_diff_range(worker.repo, "master",
                                                  "fork")
            rawDiff3 = phlgit_diff.raw_diff_range(worker.repo, "master",
                                                  "fork", 1000)
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff))
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff2))
            self.assertEqual(
                set(["ONLY_FORK", "ONLY_FORK2"]),
                phlgit_diff.parse_filenames_from_raw_diff(rawDiff3))
def updateInReview(conduit, wb, gitContext, review_branch, author):
    remoteBranch = review_branch.remote_branch
    clone = gitContext.clone

    print "updateInReview"

    print "- creating diff"
    rawDiff = phlgit_diff.raw_diff_range(
        clone, wb.remote_base, remoteBranch, _DIFF_CONTEXT_LINES)
    if not rawDiff:
        raise abdt_exception.AbdUserException(
            "no difference from " + wb.base + " to " + wb.branch)

    # if the diff is too big then regen with less context
    # used_less_context = False
    if len(rawDiff) >= MAX_DIFF_SIZE:
        # used_less_context = True
        rawDiff = phlgit_diff.raw_diff_range(
            clone, wb.remote_base, remoteBranch, _LESS_DIFF_CONTEXT_LINES)

    # if the diff is still too big then regen with no context
    # used_no_context = False
    if len(rawDiff) >= MAX_DIFF_SIZE:
        # used_no_context = True
        rawDiff = phlgit_diff.raw_diff_range(
            clone, wb.remote_base, remoteBranch)

    # if the diff is still too big then error
    if len(rawDiff) >= MAX_DIFF_SIZE:
        raise abdt_exception.LargeDiffException(
            "diff too big", len(rawDiff), MAX_DIFF_SIZE)

    d = phlcon_differential
    used_default_test_plan = False
    with phlsys_conduit.act_as_user_context(conduit, author):
        print "- updating revision " + str(wb.id)
        diffid = d.create_raw_diff(conduit, rawDiff).id
        d.update_revision(
            conduit, wb.id, diffid, [], "update")

    wb = abdt_workingbranch.pushStatus(
        gitContext,
        review_branch,
        wb,
        abdt_naming.WB_STATUS_OK)

    print "- commenting on revision " + str(wb.id)
    commenter = abdcmnt_commenter.Commenter(conduit, wb.id)
    commenter.updatedReview(review_branch.branch)
    if used_default_test_plan:
        commenter.usedDefaultTestPlan(wb.branch, _DEFAULT_TEST_PLAN)

    return wb
Exemplo n.º 4
0
def make_raw_diff(clone, base, branch, max_bytes):
    """Return a string raw diff of the changes on 'branch'.

    If the diff would exceed the _MAX_DIFF_SIZE then take measures
    to reduce the diff size by reducing the amount of context.

    Raise 'abdt_exception.LargeDiffException' if the diff could not be fit into
    'max_bytes'.

    :clone: supports 'call'
    :base: string name of the merge-base of 'branch'
    :branch: string name of the branch to diff
    :max_bytes: the maximum allowed size of the diff
    :returns: the string diff of the changes on the branch

    """
    raw_diff = phlgit_diff.raw_diff_range(
        clone, base, branch, _LOTS_OF_DIFF_CONTEXT_LINES)

    # TODO: report that we replaced errors, if any
    raw_diff = unicode(raw_diff, errors='replace')

    if not raw_diff:
        raise abdt_exception.AbdUserException(
            str("no difference from " + base + " to " + branch))

    # TODO: detect generated files and try less context on just those first
    # TODO: detect generated files and try no context on just those first
    # TODO: detect generated files and try excluding those first

    # if the diff is too big then regen with less context
    if len(raw_diff) >= max_bytes:
        raw_diff = phlgit_diff.raw_diff_range(
            clone, base, branch, _LESS_DIFF_CONTEXT_LINES)

    # if the diff is still too big then regen with no context
    if len(raw_diff) >= max_bytes:
        raw_diff = phlgit_diff.raw_diff_range(clone, base, branch, None)

    # if the diff is still too big then error
    if len(raw_diff) >= max_bytes:
        raise abdt_exception.LargeDiffException(
            "diff too big", len(raw_diff), max_bytes)

    # TODO: somehow report if we had to reduce the diff at all

    return raw_diff
Exemplo n.º 5
0
 def testSimpleFork(self):
     self._createCommitNewFile("README")
     self.clone.call("branch", "fork")
     self._createCommitNewFile("ONLY_MASTER")
     self.clone.call("checkout", "fork")
     self._createCommitNewFile("ONLY_FORK")
     self._createCommitNewFile("ONLY_FORK2")
     rawDiff = phlgit_diff.raw_diff_range_to_here(self.clone, "master")
     rawDiff2 = phlgit_diff.raw_diff_range(self.clone, "master", "fork")
     rawDiff3 = phlgit_diff.raw_diff_range(
         self.clone, "master", "fork", 1000)
     self.assertEqual(
         set(["ONLY_FORK", "ONLY_FORK2"]),
         phlgit_diff.parse_filenames_from_raw_diff(rawDiff))
     self.assertEqual(
         set(["ONLY_FORK", "ONLY_FORK2"]),
         phlgit_diff.parse_filenames_from_raw_diff(rawDiff2))
     self.assertEqual(
         set(["ONLY_FORK", "ONLY_FORK2"]),
         phlgit_diff.parse_filenames_from_raw_diff(rawDiff3))
Exemplo n.º 6
0
    def raw_diff_range(self, base, to, context=None):
        """Return a string of the unified diff between 'base' and 'to'.

        Note that the output is based on 'git diff base...to', so the commits
        are diff'ed via thier common ancestry.

        :base: the commit or branch name to start from
        :to: the commit or branch name to end with
        :context: integer amount of surrounding context to include
        :returns: string of the unified diff

        """
        return phlgit_diff.raw_diff_range(self._clone, base, to, context)
Exemplo n.º 7
0
    def raw_diff_range(self, base, to, context=None):
        """Return a string of the unified diff between 'base' and 'to'.

        Note that the output is based on 'git diff base...to', so the commits
        are diff'ed via thier common ancestry.

        :base: the commit or branch name to start from
        :to: the commit or branch name to end with
        :context: integer amount of surrounding context to include
        :returns: string of the unified diff

        """
        return phlgit_diff.raw_diff_range(self, base, to, context)
def createReview(conduit, gitContext, review_branch):
    clone = gitContext.clone
    verifyReviewBranchBase(gitContext, review_branch)

    # TODO: we should also cc other users on the branch
    # TODO: if there are emails that don't match up to users then we should
    #       note that on the review and perhaps use the mailer to notify them
    name, email, user = abdt_conduitgit.getPrimaryNameEmailAndUserFromBranch(
        clone, conduit, review_branch.remote_base,
        review_branch.remote_branch)

    print "- author: " + user

    used_default_test_plan = False

    hashes = phlgit_log.get_range_hashes(
        clone, review_branch.remote_base, review_branch.remote_branch)
    commit = hashes[-1]
    parsed = abdt_conduitgit.getFieldsFromCommitHash(
        conduit, clone, commit)
    if parsed.errors:
        used_default_test_plan = True
        parsed = abdt_conduitgit.getFieldsFromCommitHash(
            conduit, clone, commit, _DEFAULT_TEST_PLAN)
        if parsed.errors:
            print parsed
            raise abdt_exception.CommitMessageParseException(
                errors=parsed.errors,
                fields=parsed.fields,
                digest=makeMessageDigest(
                    clone,
                    review_branch.remote_base,
                    review_branch.remote_branch))

    rawDiff = phlgit_diff.raw_diff_range(
        clone,
        review_branch.remote_base,
        review_branch.remote_branch,
        _DIFF_CONTEXT_LINES)

    # if the diff is too big then regen with less context
    if len(rawDiff) >= MAX_DIFF_SIZE:
        rawDiff = phlgit_diff.raw_diff_range(
            clone,
            review_branch.remote_base,
            review_branch.remote_branch,
            _LESS_DIFF_CONTEXT_LINES)

    # if the diff is still too big then regen with no context
    if len(rawDiff) >= MAX_DIFF_SIZE:
        rawDiff = phlgit_diff.raw_diff_range(
            clone, review_branch.remote_base, review_branch.remote_branch)

    # if the diff is still too big then error
    if len(rawDiff) >= MAX_DIFF_SIZE:
        raise abdt_exception.LargeDiffException(
            "diff too big", len(rawDiff), MAX_DIFF_SIZE)

    revisionid = createDifferentialReview(
        conduit, user, parsed, gitContext, review_branch, rawDiff)

    if used_default_test_plan:
        commenter = abdcmnt_commenter.Commenter(conduit, revisionid)
        commenter.usedDefaultTestPlan(review_branch.branch, _DEFAULT_TEST_PLAN)
Exemplo n.º 9
0
def make_raw_diff(repo, base, branch, max_diff_size_utf8_bytes):
    """Return a string raw diff of the changes on 'branch'.

    If the diff would exceed the _MAX_DIFF_SIZE then take measures
    to reduce the diff size by reducing the amount of context.

    Raise 'NoDiffError' if the diff could not be fit into
    'max_bytes'.

    :repo: a callable supporting git commands, e.g. repo("status")
    :base: string name of the merge-base of 'branch'
    :branch: string name of the branch to diff
    :max_diff_size_utf8_bytes: the maximum allowed size of the diff as utf8
    :returns: the string diff of the changes on the branch

    """
    raw_diff = phlgit_diff.raw_diff_range(
        repo, base, branch, _FULL_DIFF_CONTEXT_LINES)
    new_raw_diff = unicode(raw_diff, errors='replace')
    full_diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
    diff_size_utf8_bytes = full_diff_size_utf8_bytes

    if not raw_diff:
        raise NoDiffError()

    reduction_list = []

    # TODO: detect generated files and try less context on just those first
    # TODO: detect generated files and try no context on just those first
    # TODO: detect generated files and try excluding those first

    # if the diff is too big then regen with less context
    for context_lines in [_GOOD_DIFF_CONTEXT_LINES, _SOME_DIFF_CONTEXT_LINES]:
        if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
            raw_diff = phlgit_diff.raw_diff_range(
                repo, base, branch, context_lines)
            new_raw_diff = unicode(raw_diff, errors='replace')
            diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
            reduction_list.append(
                LessContextReduction(
                    diff_size_utf8_bytes,
                    context_lines))

    # if the diff is still too big then regen with no context
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        raw_diff = phlgit_diff.raw_diff_range(repo, base, branch, None)
        new_raw_diff = unicode(raw_diff, errors='replace')
        diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
        reduction_list.append(
            RemoveContextReduction(
                diff_size_utf8_bytes))

    # if the diff is still too big then just use the diff stat with message
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        stat = phlgit_diff.stat_range(repo, base, branch)
        content = "this diff is very large, it has been reduced to a summary:"
        content = '\n\n'.join([content, stat])
        raw_diff = phlgit_diff.create_add_file('diffstat', content)
        new_raw_diff = unicode(raw_diff, errors='replace')
        diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
        reduction_list.append(
            DiffStatReduction(
                diff_size_utf8_bytes))

    # if the diff is still too big then error
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        raise abdt_exception.LargeDiffException(
            "diff too big", diff_size_utf8_bytes, max_diff_size_utf8_bytes)

    did_replace_unicode = new_raw_diff != raw_diff

    return DiffResult(
        new_raw_diff,
        reduction_list,
        did_replace_unicode,
        diff_size_utf8_bytes,
        full_diff_size_utf8_bytes,
        max_diff_size_utf8_bytes)
Exemplo n.º 10
0
def make_raw_diff(repo, base, branch, max_diff_size_utf8_bytes):
    """Return a string raw diff of the changes on 'branch'.

    If the diff would exceed the _MAX_DIFF_SIZE then take measures
    to reduce the diff size by reducing the amount of context.

    Raise 'NoDiffError' if there is no difference to show.

    Raise 'abdt_exception.LargeDiffException' if the diff could not be fit into
    'max_bytes'.

    :repo: a callable supporting git commands, e.g. repo("status")
    :base: string name of the merge-base of 'branch'
    :branch: string name of the branch to diff
    :max_diff_size_utf8_bytes: the maximum allowed size of the diff as utf8
    :returns: the string diff of the changes on the branch

    """
    raw_diff = phlgit_diff.raw_diff_range(repo, base, branch,
                                          _FULL_DIFF_CONTEXT_LINES)
    new_raw_diff = unicode(raw_diff, errors='replace')
    full_diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
    diff_size_utf8_bytes = full_diff_size_utf8_bytes

    if not raw_diff:
        raise NoDiffError()

    reduction_list = []

    # TODO: detect generated files and try less context on just those first
    # TODO: detect generated files and try no context on just those first
    # TODO: detect generated files and try excluding those first

    # if the diff is too big then regen with less context
    for context_lines in [_GOOD_DIFF_CONTEXT_LINES, _SOME_DIFF_CONTEXT_LINES]:
        if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
            raw_diff = phlgit_diff.raw_diff_range(repo, base, branch,
                                                  context_lines)
            new_raw_diff = unicode(raw_diff, errors='replace')
            diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
            reduction_list.append(
                LessContextReduction(diff_size_utf8_bytes, context_lines))

    # if the diff is still too big then regen with no context
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        raw_diff = phlgit_diff.raw_diff_range(repo, base, branch, None)
        new_raw_diff = unicode(raw_diff, errors='replace')
        diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
        reduction_list.append(RemoveContextReduction(diff_size_utf8_bytes))

    # if the diff is still too big then just use the diff stat with message
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        stat = phlgit_diff.stat_range(repo, base, branch)
        content = "this diff is very large, it has been reduced to a summary:"
        content = '\n\n'.join([content, stat])
        raw_diff = phlgit_diff.create_add_file('diffstat', content)
        new_raw_diff = unicode(raw_diff, errors='replace')
        diff_size_utf8_bytes = len(new_raw_diff.encode("utf-8"))
        reduction_list.append(DiffStatReduction(diff_size_utf8_bytes))

    # if the diff is still too big then error
    if diff_size_utf8_bytes > max_diff_size_utf8_bytes:
        raise abdt_exception.LargeDiffException("diff too big",
                                                diff_size_utf8_bytes,
                                                max_diff_size_utf8_bytes)

    did_replace_unicode = new_raw_diff != raw_diff

    return DiffResult(new_raw_diff, reduction_list, did_replace_unicode,
                      diff_size_utf8_bytes, full_diff_size_utf8_bytes,
                      max_diff_size_utf8_bytes)