Esempio n. 1
0
def _shelvecreatedcommit(ui, repo, node, name):
    shelvedfile(repo, name, "oshelve").writeobsshelveinfo({"node": nodemod.hex(node)})
    cmdutil.export(
        repo,
        [node],
        fp=shelvedfile(repo, name, patchextension).opener("wb"),
        opts=mdiff.diffopts(git=True),
    )
Esempio n. 2
0
 def changediff(node):
     nodebase = repo[node].p1().node()
     m = scmutil.matchall(repo)
     diff = patch.diffhunks(repo, nodebase, node, m, opts=mdiff.diffopts(context=0))
     filepatches = {}
     for _fctx1, _fctx2, headerlines, hunks in diff:
         difflines = []
         for hunkrange, hunklines in hunks:
             difflines += list(hunklines)
         header = patch.header(headerlines)
         filepatches[header.files()[0]] = "".join(difflines)
     return (set(filepatches.keys()), filepatches, node)
Esempio n. 3
0
def _diff2o(ui, repo, rev1, rev2, *pats, **opts):
    # Phabricator revs are often filtered (hidden)
    # First reconstruct textual diffs for rev1 and rev2 independently.
    def changediff(node):
        nodebase = repo[node].p1().node()
        m = scmutil.matchall(repo)
        diff = patch.diffhunks(repo,
                               nodebase,
                               node,
                               m,
                               opts=mdiff.diffopts(context=0))
        filepatches = {}
        for _fctx1, _fctx2, headerlines, hunks in diff:
            difflines = []
            for hunkrange, hunklines in hunks:
                difflines += list(hunklines)
            header = patch.header(headerlines)
            filepatches[header.files()[0]] = b"".join(difflines)
        return (set(filepatches.keys()), filepatches, node)

    rev1node = repo[rev1].node()
    rev2node = repo[rev2].node()
    files1, filepatches1, node1 = changediff(rev1node)
    files2, filepatches2, node2 = changediff(rev2node)

    ui.write(_("Phabricator rev: %s\n") % hex(node1)),
    ui.write(_("Local rev: %s (%s)\n") % (hex(node2), rev2))

    # For files have changed, produce a diff of the diffs first using a normal
    # text diff of the input diffs, then fixing-up the output for readability.
    changedfiles = files1 & files2
    for f in changedfiles:
        opts["context"] = 0
        diffopts = mdiff.diffopts(**opts)
        header, hunks = mdiff.unidiff(filepatches1[f],
                                      "",
                                      filepatches2[f],
                                      "",
                                      f,
                                      f,
                                      opts=diffopts)
        hunklines = []
        for hunk in hunks:
            hunklines += hunk[1]
        changelines = []
        i = 0
        while i < len(hunklines):
            line = pycompat.decodeutf8(hunklines[i], errors="replace")
            i += 1
            if line[:2] == "++":
                changelines.append("+" + line[2:])
            elif line[:2] == "+-":
                changelines.append("-" + line[2:])
            elif line[:2] == "-+":
                changelines.append("-" + line[2:])
            elif line[:2] == "--":
                changelines.append("+" + line[2:])
            elif line[:2] == "@@" or line[1:3] == "@@":
                if len(changelines) < 1 or changelines[-1] != "...\n":
                    changelines.append("...\n")
            else:
                changelines.append(line)
        if len(changelines):
            ui.write(_("Changed: %s\n") % f)
            for line in changelines:
                ui.write("| " + line)
    wholefilechanges = files1 ^ files2
    for f in wholefilechanges:
        ui.write(_("Added/removed: %s\n") % f)
Esempio n. 4
0
    def testannotatepair(self):
        self.maxDiff = None  # camelcase-required

        oldfctx = "old"
        p1fctx, p2fctx, childfctx = "p1", "p2", "c"
        olddata = b"a\nb\n"
        p1data = b"a\nb\nc\n"
        p2data = b"a\nc\nd\n"
        childdata = b"a\nb2\nc\nc2\nd\n"
        diffopts = mdiff.diffopts()

        def decorate(text, rev):
            return (
                [
                    annotateline(fctx=rev, lineno=i)
                    for i in xrange(1, text.count(b"\n") + 1)
                ],
                text,
            )

        # Basic usage

        oldann = decorate(olddata, oldfctx)
        p1ann = decorate(p1data, p1fctx)
        p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
        self.assertEqual(
            p1ann[0],
            [annotateline("old", 1), annotateline("old", 2), annotateline("p1", 3)],
        )

        p2ann = decorate(p2data, p2fctx)
        p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
        self.assertEqual(
            p2ann[0],
            [annotateline("old", 1), annotateline("p2", 2), annotateline("p2", 3)],
        )

        # Test with multiple parents (note the difference caused by ordering)

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, diffopts)
        self.assertEqual(
            childann[0],
            [
                annotateline("old", 1),
                annotateline("c", 2),
                annotateline("p2", 2),
                annotateline("c", 4),
                annotateline("p2", 3),
            ],
        )

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, diffopts)
        self.assertEqual(
            childann[0],
            [
                annotateline("old", 1),
                annotateline("c", 2),
                annotateline("p1", 3),
                annotateline("c", 4),
                annotateline("p2", 3),
            ],
        )

        # Test with skipchild (note the difference caused by ordering)

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, diffopts)
        self.assertEqual(
            childann[0],
            [
                annotateline("old", 1),
                annotateline("old", 2, True),
                # note that this line was carried over from earlier so it is *not*
                # marked skipped
                annotateline("p2", 2),
                annotateline("p2", 2, True),
                annotateline("p2", 3),
            ],
        )

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, diffopts)
        self.assertEqual(
            childann[0],
            [
                annotateline("old", 1),
                annotateline("old", 2, True),
                annotateline("p1", 3),
                annotateline("p1", 3, True),
                annotateline("p2", 3),
            ],
        )