예제 #1
0
def showdiffstat(context, mapping, args):
    """String. Return diffstat-style summary of changes.

    If 'style' is not 'none', it could be 'status', in which case "added",
    "changed", "removed" will be shown before file names.
    """
    if "style" in args:
        style = args["style"][1]
    else:
        style = "none"

    repo = mapping["repo"]
    ctx = mapping["ctx"]
    revcache = mapping["revcache"]
    width = repo.ui.termwidth()

    if style == "none":
        status = None
    elif style == "status":
        status = templatekw.getfiles(repo, ctx, revcache)
    else:
        raise error.ParseError(_("stat does not support style %r") % (style, ))

    return patch.diffstat(util.iterlines(ctx.diff(noprefix=False)),
                          width=width,
                          status=status)
예제 #2
0
def diffcmd(orig, ui, repo, *args, **opts):
    if not opts.get("per_file_stat_json"):
        return orig(ui, repo, *args, **opts)

    ui.pushbuffer()
    res = orig(ui, repo, *args, **opts)
    buffer = ui.popbufferbytes()
    difflines = util.iterlines([buffer])
    diffstat = patch.diffstatdata(difflines)
    output = {}
    for filename, adds, removes, isbinary in diffstat:
        output[filename] = {"adds": adds, "removes": removes, "isbinary": isbinary}
    ui.write("%s\n" % (json.dumps(output, sort_keys=True)))
    return res
예제 #3
0
def diffstat(ui, repo, **kwargs):
    """Example usage:

    [hooks]
    commit.diffstat = python:/path/to/this/file.py:diffstat
    changegroup.diffstat = python:/path/to/this/file.py:diffstat
    """
    if kwargs.get("parent2"):
        return
    node = kwargs["node"]
    first = repo[node].p1().node()
    if "url" in kwargs:
        last = repo["tip"].node()
    else:
        last = node
    diff = patch.diff(repo, first, last)
    ui.write(patch.diffstat(util.iterlines(diff)))
예제 #4
0
def diffcmd(orig, ui, repo, *args, **opts):
    if not opts.get("per_file_stat_json"):
        return orig(ui, repo, *args, **opts)

    ui.pushbuffer()
    res = orig(ui, repo, *args, **opts)
    buffer = ui.popbuffer()
    difflines = util.iterlines([buffer])
    diffstat = patch.diffstatdata(difflines)
    output = {}
    for filename, adds, removes, isbinary in diffstat:
        # use special encoding that allows non-utf8 filenames
        filename = encoding.jsonescape(filename, paranoid=True)
        output[filename] = {
            "adds": adds,
            "removes": removes,
            "isbinary": isbinary
        }
    ui.write("%s\n" % (json.dumps(output, sort_keys=True)))
    return res
예제 #5
0
def debugfillinfinitepushmetadata(ui, repo, **opts):
    """Special command that fills infinitepush metadata for a node"""

    nodes = opts["node"]
    if not nodes:
        raise error.Abort(_("nodes are not specified"))

    filelimit = ui.configint("infinitepush", "metadatafilelimit", 100)
    nodesmetadata = {}
    for node in nodes:
        index = repo.bundlestore.index
        if not bool(index.getbundle(node)):
            raise error.Abort(_("node %s is not found") % node)

        if node not in repo:
            newbundlefile = server.downloadbundle(repo, bin(node))
            bundlepath = "bundle:%s+%s" % (repo.root, newbundlefile)
            bundlerepo = hg.repository(ui, bundlepath)
            repo = bundlerepo

        p1 = repo[node].p1().node()
        diffopts = patch.diffallopts(ui, {})
        match = scmutil.matchall(repo)
        chunks = patch.diff(repo, p1, node, match, None, diffopts, relroot="")
        difflines = util.iterlines(chunks)

        states = "modified added removed deleted unknown ignored clean".split()
        status = repo.status(p1, node)
        status = zip(states, status)

        filestatus = {}
        for state, files in status:
            for f in files:
                filestatus[f] = state

        diffstat = patch.diffstatdata(difflines)
        changed_files = {}
        copies = copiesmod.pathcopies(repo[p1], repo[node])
        for filename, adds, removes, isbinary in diffstat[:filelimit]:
            # use special encoding that allows non-utf8 filenames
            filename = pycompat.decodeutf8(
                encoding.jsonescape(pycompat.encodeutf8(filename), paranoid=True)
            )
            changed_files[filename] = {
                "adds": adds,
                "removes": removes,
                "isbinary": isbinary,
                "status": filestatus.get(filename, "unknown"),
            }
            if filename in copies:
                changed_files[filename]["copies"] = copies[filename]

        output = {}
        output["changed_files"] = changed_files
        if len(diffstat) > filelimit:
            output["changed_files_truncated"] = True
        nodesmetadata[node] = output

    with index:
        for node, metadata in pycompat.iteritems(nodesmetadata):
            dumped = json.dumps(metadata, sort_keys=True)
            index.saveoptionaljsonmetadata(node, pycompat.encodeutf8(dumped))