Esempio n. 1
0
    def _processlookups(self, lookups):
        repo = self.dirstate._repo
        p1 = self.dirstate.p1()

        if util.safehasattr(repo, "fileservice"):
            p1mf = repo[p1].manifest()
            lookupmatcher = matchmod.exact(repo.root, repo.root, lookups)
            # We fetch history because we know _compareondisk() uses
            # filelog.cmp() which computes the sha(p1, p2, text), which requires
            # the history of the file. Later we'll move to comparing content
            # hashes, and we can prefetch those hashes instead.
            # Note, this may be slow for files with long histories.
            repo.fileservice.prefetch(
                list((f, hex(p1mf[f])) for f in p1mf.matches(lookupmatcher)),
                fetchdata=False,
                fetchhistory=True,
            )

        wctx = repo[None]
        pctx = repo[p1]

        with progress.bar(self.ui, _("checking changes"), _("files"),
                          len(lookups)) as prog:
            # Sort so we get deterministic ordering. This is important for tests.
            count = 0
            for fn in sorted(lookups):
                count += 1
                prog.value = (count, fn)
                changed = self._compareondisk(fn, wctx, pctx)
                if changed is None:
                    # File no longer exists
                    if self.dtolog > 0:
                        self.dtolog -= 1
                        self.ui.log("status",
                                    "R %s: checked in filesystem" % fn)
                    yield (fn, False)
                elif changed is True:
                    # File exists and is modified
                    if self.mtolog > 0:
                        self.mtolog -= 1
                        self.ui.log("status",
                                    "M %s: checked in filesystem" % fn)
                    yield (fn, True)
                else:
                    # File exists and is clean
                    if self.ftolog > 0:
                        self.ftolog -= 1
                        self.ui.log("status",
                                    "C %s: checked in filesystem" % fn)
                    self.cleanlookups.append(fn)
Esempio n. 2
0
    def _processlookups(self, lookups):
        repo = self.dirstate._repo
        p1 = self.dirstate.p1()

        if util.safehasattr(repo, "fileservice"):
            p1mf = repo[p1].manifest()
            lookupmatcher = matchmod.exact(repo.root, repo.root, lookups)
            repo.fileservice.prefetch(
                list((f, hex(p1mf[f])) for f in p1mf.matches(lookupmatcher)),
                fetchhistory=False,
            )

        wctx = repo[None]
        pctx = repo[p1]

        # Sort so we get deterministic ordering. This is important for tests.
        for fn in sorted(lookups):
            changed = self._compareondisk(fn, wctx, pctx)
            if changed is None:
                # File no longer exists
                if self.dtolog > 0:
                    self.dtolog -= 1
                    self.ui.log("status", "R %s: checked in filesystem" % fn)
                yield (fn, False)
            elif changed is True:
                # File exists and is modified
                if self.mtolog > 0:
                    self.mtolog -= 1
                    self.ui.log("status", "M %s: checked in filesystem" % fn)
                yield (fn, True)
            else:
                # File exists and is clean
                if self.ftolog > 0:
                    self.ftolog -= 1
                    self.ui.log("status", "C %s: checked in filesystem" % fn)
                self.cleanlookups.append(fn)
Esempio n. 3
0
def _dosign(ui, repo, *revs, **opts):
    mygpg = newgpg(ui, **opts)
    sigver = "0"
    sigmessage = ""

    date = opts.get("date")
    if date:
        opts["date"] = util.parsedate(date)

    if revs:
        nodes = [repo.lookup(n) for n in revs]
    else:
        nodes = [
            node for node in repo.dirstate.parents() if node != hgnode.nullid
        ]
        if len(nodes) > 1:
            raise error.Abort(
                _("uncommitted merge - please provide a "
                  "specific revision"))
        if not nodes:
            nodes = [repo.changelog.tip()]

    for n in nodes:
        hexnode = hgnode.hex(n)
        ui.write(_("signing %s\n") % (hgnode.short(n)))
        # build data
        data = node2txt(repo, n, sigver)
        sig = mygpg.sign(data)
        if not sig:
            raise error.Abort(_("error while signing"))
        sig = binascii.b2a_base64(sig)
        sig = sig.replace("\n", "")
        sigmessage += "%s %s %s\n" % (hexnode, sigver, sig)

    # write it
    if opts["local"]:
        repo.localvfs.append("localsigs", sigmessage)
        return

    if not opts["force"]:
        msigs = match.exact(repo.root, "", [".hgsigs"])
        if any(repo.status(match=msigs, unknown=True, ignored=True)):
            raise error.Abort(
                _("working copy of .hgsigs is changed "),
                hint=_("please commit .hgsigs manually"),
            )

    sigsfile = repo.wvfs(".hgsigs", "ab")
    sigsfile.write(sigmessage)
    sigsfile.close()

    if ".hgsigs" not in repo.dirstate:
        with repo.lock(), repo.transaction("add-signatures"):
            repo[None].add([".hgsigs"])

    if opts["no_commit"]:
        return

    message = opts["message"]
    if not message:
        # we don't translate commit messages
        message = "\n".join([
            "Added signature for changeset %s" % hgnode.short(n) for n in nodes
        ])
    try:
        editor = cmdutil.getcommiteditor(editform="gpg.sign", **opts)
        repo.commit(message,
                    opts["user"],
                    opts["date"],
                    match=msigs,
                    editor=editor)
    except ValueError as inst:
        raise error.Abort(str(inst))