def summary()

in eden/scm/edenscm/mercurial/commands/__init__.py [0:0]


def summary(ui, repo, **opts):
    """summarize working directory state

    This generates a brief summary of the working directory state,
    including parents, branch, commit status, phase and available updates.

    With the --remote option, this will check the default paths for
    incoming and outgoing changes. This can be time-consuming.

    Returns 0 on success.
    """
    if not util.istest():
        ui.deprecate(
            "hg-summary", "summary is deprecated - use `hg sl` and `hg status` instead"
        )

    ui.pager("summary")
    ctx = repo[None]
    parents = ctx.parents()
    marks = []

    ms = None
    try:
        ms = mergemod.mergestate.read(repo)
    except error.UnsupportedMergeRecords as e:
        s = " ".join(e.recordtypes)
        ui.warn(_("warning: merge state has unsupported record types: %s\n") % s)
        unresolved = []
    else:
        unresolved = list(ms.unresolved())

    for p in parents:
        # label with log.changeset (instead of log.parent) since this
        # shows a working directory parent *changeset*:
        # i18n: column positioning for "hg summary"
        ui.write(_("parent: %s ") % (p), label=cmdutil._changesetlabels(p))
        if p.bookmarks():
            marks.extend(p.bookmarks())
        if p.rev() == -1:
            if not len(repo):
                ui.write(_(" (empty repository)"))
            else:
                ui.write(_(" (no revision checked out)"))
        if p.obsolete():
            ui.write(_(" (obsolete)"))
        ui.write("\n")
        if p.description():
            ui.status(
                " " + p.description().splitlines()[0].strip() + "\n",
                label="log.summary",
            )

    if marks:
        active = repo._activebookmark
        # i18n: column positioning for "hg summary"
        ui.write(_("bookmarks:"), label="log.bookmark")
        if active is not None:
            if active in marks:
                ui.write(" *" + active, label=bookmarks.activebookmarklabel)
                marks.remove(active)
            else:
                ui.write(" [%s]" % active, label=bookmarks.activebookmarklabel)
        for m in marks:
            ui.write(" " + m, label="log.bookmark")
        ui.write("\n", label="log.bookmark")

    status = repo.status(unknown=True)

    c = repo.dirstate.copies()
    copied, renamed = [], []
    for d, s in pycompat.iteritems(c):
        if s in status.removed:
            status.removed.remove(s)
            renamed.append(d)
        else:
            copied.append(d)
        if d in status.added:
            status.added.remove(d)

    labels = [
        (ui.label(_("%d modified"), "status.modified"), status.modified),
        (ui.label(_("%d added"), "status.added"), status.added),
        (ui.label(_("%d removed"), "status.removed"), status.removed),
        (ui.label(_("%d renamed"), "status.copied"), renamed),
        (ui.label(_("%d copied"), "status.copied"), copied),
        (ui.label(_("%d deleted"), "status.deleted"), status.deleted),
        (ui.label(_("%d unknown"), "status.unknown"), status.unknown),
        (ui.label(_("%d unresolved"), "resolve.unresolved"), unresolved),
    ]
    t = []
    for l, s in labels:
        if s:
            t.append(l % len(s))

    t = ", ".join(t)
    cleanworkdir = False

    if repo.localvfs.exists("graftstate"):
        t += _(" (graft in progress)")
    if repo.localvfs.exists("updatestate"):
        t += _(" (interrupted update)")
    elif len(parents) > 1:
        t += _(" (merge)")
    elif not (status.modified or status.added or status.removed or renamed or copied):
        t += _(" (clean)")
        cleanworkdir = True

    if parents:
        pendingphase = max(p.phase() for p in parents)
    else:
        pendingphase = phases.public

    if pendingphase > phases.newcommitphase(ui):
        t += " (%s)" % phases.phasenames[pendingphase]

    if cleanworkdir:
        # i18n: column positioning for "hg summary"
        ui.status(_("commit: %s\n") % t.strip())
    else:
        # i18n: column positioning for "hg summary"
        ui.write(_("commit: %s\n") % t.strip())

    t = []
    draft = len(repo.revs("draft()"))
    if draft:
        t.append(_("%d draft") % draft)
    secret = len(repo.revs("secret()"))
    if secret:
        t.append(_("%d secret") % secret)

    if draft or secret:
        ui.status(_("phases: %s\n") % ", ".join(t))

    cmdutil.summaryhooks(ui, repo)

    if opts.get("remote"):
        needsincoming, needsoutgoing = True, True
    else:
        needsincoming, needsoutgoing = False, False
        for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
            if i:
                needsincoming = True
            if o:
                needsoutgoing = True
        if not needsincoming and not needsoutgoing:
            return

    def getincoming():
        source, branches = hg.parseurl(ui.expandpath("default"))
        sbranch = branches[0]
        try:
            other = hg.peer(repo, {}, source)
        except error.RepoError:
            if opts.get("remote"):
                raise
            return source, sbranch, None, None, None
        revs, checkout = hg.addbranchrevs(repo, other, branches, None)
        if revs:
            revs = [other.lookup(rev) for rev in revs]
        ui.debug("comparing with %s\n" % util.hidepassword(source))
        with repo.ui.configoverride({("ui", "quiet"): True}):
            commoninc = discovery.findcommonincoming(repo, other, heads=revs)
        return source, sbranch, other, commoninc, commoninc[1]

    if needsincoming:
        source, sbranch, sother, commoninc, incoming = getincoming()
    else:
        source = sbranch = sother = commoninc = incoming = None

    def getoutgoing():
        dest, branches = hg.parseurl(ui.expandpath("default-push", "default"))
        dbranch = branches[0]
        revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
        if source != dest:
            try:
                dother = hg.peer(repo, {}, dest)
            except error.RepoError:
                if opts.get("remote"):
                    raise
                return dest, dbranch, None, None
            ui.debug("comparing with %s\n" % util.hidepassword(dest))
        elif sother is None:
            # there is no explicit destination peer, but source one is invalid
            return dest, dbranch, None, None
        else:
            dother = sother
        if source != dest or (sbranch is not None and sbranch != dbranch):
            common = None
        else:
            common = commoninc
        if revs:
            revs = [repo.lookup(rev) for rev in revs]
        with repo.ui.configoverride({("ui", "quiet"): True}):
            outgoing = discovery.findcommonoutgoing(
                repo, dother, onlyheads=revs, commoninc=common
            )
        return dest, dbranch, dother, outgoing

    if needsoutgoing:
        dest, dbranch, dother, outgoing = getoutgoing()
    else:
        dest = dbranch = dother = outgoing = None

    if opts.get("remote"):
        t = []
        if incoming:
            t.append(_("1 or more incoming"))
        o = outgoing.missing
        if o:
            t.append(_("%d outgoing") % len(o))
        other = dother or sother
        if "bookmarks" in other.listkeys("namespaces"):
            counts = bookmarks.summary(repo, other)
            if counts[0] > 0:
                t.append(_("%d incoming bookmarks") % counts[0])
            if counts[1] > 0:
                t.append(_("%d outgoing bookmarks") % counts[1])

        if t:
            # i18n: column positioning for "hg summary"
            ui.write(_("remote: %s\n") % (", ".join(t)))
        else:
            # i18n: column positioning for "hg summary"
            ui.status(_("remote: (synced)\n"))

    cmdutil.summaryremotehooks(
        ui,
        repo,
        opts,
        ((source, sbranch, sother, commoninc), (dest, dbranch, dother, outgoing)),
    )