示例#1
0
def fakewrite(ui, func):
    # fake "now" of 'pack_dirstate' only if it is invoked while 'func'

    fakenow = ui.config("fakedirstatewritetime", "fakenow")
    if not fakenow:
        # Execute original one, if fakenow isn't configured. This is
        # useful to prevent subrepos from executing replaced one,
        # because replacing 'parsers.pack_dirstate' is also effective
        # in subrepos.
        return func()

    fakenow = util.parsedate(fakenow)[0]

    orig_pack_dirstate = parsers.pack_dirstate
    orig_dirstate_getfsnow = dirstate._getfsnow
    wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)

    parsers.pack_dirstate = wrapper
    dirstate._getfsnow = lambda *args: fakenow
    try:
        return func()
    finally:
        parsers.pack_dirstate = orig_pack_dirstate
        dirstate._getfsnow = orig_dirstate_getfsnow
示例#2
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))
示例#3
0
def treestatewrite(orig, self, st, now):
    ui = self._ui
    fakenow = ui.config("fakedirstatewritetime", "fakenow")
    if fakenow:
        now = util.parsedate(fakenow)[0]
    return orig(self, st, now)
示例#4
0
 def getdate(n):
     if n not in dates:
         dates[n] = util.parsedate(self.commitcache[n].date)
     return dates[n]
示例#5
0
        def parselogentry(orig_paths, revnum, author, date, message):
            """Return the parsed commit object or None, and True if
            the revision is a branch root.
            """
            self.ui.debug(
                "parsing revision %d (%d changes)\n" % (revnum, len(orig_paths))
            )

            branched = False
            rev = self.revid(revnum)
            # branch log might return entries for a parent we already have

            if rev in self.commits or revnum < to_revnum:
                return None, branched

            parents = []
            # check whether this revision is the start of a branch or part
            # of a branch renaming
            orig_paths = sorted(pycompat.iteritems(orig_paths))
            root_paths = [(p, e) for p, e in orig_paths if self.module.startswith(p)]
            if root_paths:
                path, ent = root_paths[-1]
                if ent.copyfrom_path:
                    branched = True
                    newpath = ent.copyfrom_path + self.module[len(path) :]
                    # ent.copyfrom_rev may not be the actual last revision
                    previd = self.latest(newpath, ent.copyfrom_rev)
                    if previd is not None:
                        prevmodule, prevnum = revsplit(previd)[1:]
                        if prevnum >= self.startrev:
                            parents = [previd]
                            self.ui.note(
                                _("found parent of branch %s at %d: %s\n")
                                % (self.module, prevnum, prevmodule)
                            )
                else:
                    self.ui.debug("no copyfrom path, don't know what to do.\n")

            paths = []
            # filter out unrelated paths
            for path, ent in orig_paths:
                if self.getrelpath(path) is None:
                    continue
                paths.append((path, ent))

            # Example SVN datetime. Includes microseconds.
            # ISO-8601 conformant
            # '2007-01-04T17:35:00.902377Z'
            date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
            if self.ui.configbool("convert", "localtimezone"):
                date = makedatetimestamp(date[0])

            if message:
                log = self.recode(message)
            else:
                log = ""

            if author:
                author = self.recode(author)
            else:
                author = ""

            try:
                branch = self.module.split("/")[-1]
                if branch == self.trunkname:
                    branch = None
            except IndexError:
                branch = None

            cset = commit(
                author=author,
                date=util.datestr(date, "%Y-%m-%d %H:%M:%S %1%2"),
                desc=log,
                parents=parents,
                branch=branch,
                rev=rev,
            )

            self.commits[rev] = cset
            # The parents list is *shared* among self.paths and the
            # commit object. Both will be updated below.
            self.paths[rev] = (paths, cset.parents)
            if self.child_cset and not self.child_cset.parents:
                self.child_cset.parents[:] = [rev]
            self.child_cset = cset
            return cset, branched
示例#6
0
def cloudsmartlog(ui, repo, template="sl_cloud", **opts):
    """get smartlog view for the default workspace of the given user

    If the requested template is not defined in the config
    the command provides a simple view as a list of draft commits.
    """

    reponame = ccutil.getreponame(repo)
    workspacename = workspace.parseworkspace(ui, opts)
    if workspacename is None:
        workspacename = workspace.currentworkspace(repo)
    if workspacename is None:
        workspacename = workspace.defaultworkspace(ui)

    if opts.get("history"):
        interactivehistory.showhistory(ui, repo, reponame, workspacename,
                                       **opts)
        return

    date = opts.get("date")
    version = opts.get("workspace_version")
    if date:
        parseddate = util.parsedate(date)
    else:
        parseddate = None

    ui.status(
        _("searching draft commits for the '%s' workspace for the '%s' repo\n")
        % (workspacename, reponame),
        component="commitcloud",
    )
    serv = service.get(ui, tokenmod.TokenLocator(ui).token)
    if parseddate is None and not version:
        with progress.spinner(ui, _("fetching")):
            firstpublic, revdag = serv.getsmartlog(reponame, workspacename,
                                                   repo, 0)
    else:
        with progress.spinner(ui, _("fetching")):
            firstpublic, revdag, slversion, sltimestamp = serv.getsmartlogbyversion(
                reponame, workspacename, repo, parseddate, version, 0)
    if parseddate or version:
        formatteddate = time.strftime("%Y-%m-%d %H:%M:%S",
                                      time.localtime(sltimestamp))
        ui.status(
            _("Smartlog version %d \nsynced at %s\n\n") %
            (slversion, formatteddate))
    else:
        ui.status(_("Smartlog:\n\n"))
    # set up pager
    ui.pager("smartlog")

    smartlogstyle = ui.config("templatealias", template)
    # if style is defined in templatealias section of config apply that style
    if smartlogstyle:
        opts["template"] = "{%s}" % smartlogstyle
    else:
        ui.debug(
            _("style %s is not defined, skipping") % smartlogstyle,
            component="commitcloud",
        )

    # show all the nodes
    displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
    if ui.config("experimental", "graph.renderer") == "legacy":
        cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)
    else:
        cmdutil.rustdisplaygraph(ui,
                                 repo,
                                 revdag,
                                 displayer,
                                 reserved=firstpublic)
示例#7
0
        def __init__(self, ui, repo, reponame, workspacename, **opts):
            self.ui = ui
            self.repo = repo
            self.reponame = reponame
            self.workspacename = workspacename
            self.opts = opts
            self.serv = service.get(ui, tokenmod.TokenLocator(ui).token)
            self.servlock = threading.Lock()
            self.renderevent = threading.Event()
            self.running = True
            self.cache = {}
            with progress.spinner(ui, _("fetching cloud smartlog history")):
                self.versions = sorted(
                    self.serv.gethistoricalversions(reponame, workspacename),
                    key=lambda version: version["version_number"],
                )

            initversion = opts.get("workspace_version")
            date = opts.get("date")
            inittime = int(util.parsedate(date)[0]) if date else None

            if initversion and inittime:
                raise error.Abort(
                    "'--workspace-version' and '--date' options can't be both provided"
                )

            if inittime:
                timestamps = sorted(
                    self.versions,
                    key=lambda version: version["timestamp"],
                )
                for index, version in enumerate(timestamps):
                    if version["timestamp"] >= inittime:
                        initversion = version["version_number"]
                        break
                    if index == len(timestamps) - 1:
                        raise error.Abort(
                            "You have no recorded history at or after this date"
                        )

            smartlogstyle = ui.config("templatealias", template)
            if smartlogstyle:
                self.opts["template"] = "{%s}" % smartlogstyle

            if initversion:
                initversion = int(initversion)
                for index, version in enumerate(self.versions):
                    if version["version_number"] == initversion:
                        self.cur_index = index
                        break
                else:
                    versionrange = [
                        version["version_number"] for version in self.versions
                    ]
                    raise error.Abort(
                        "workspace version %s is not available (%s to %s are available)"
                        % (initversion, min(versionrange), max(versionrange)))
            else:
                self.cur_index = len(self.versions)
            if opts.get("all"):
                self.limit = 0
            else:
                self.limit = 12 * 7 * 24 * 60 * 60  # 12 weeks
            self.flags = []
            if ui.configbool("commitcloud", "sl_showremotebookmarks"):
                self.flags.append("ADD_REMOTE_BOOKMARKS")
            if ui.configbool("commitcloud", "sl_showallbookmarks"):
                self.flags.append("ADD_ALL_BOOKMARKS")
            if opts.get("force_original_backend"):
                self.flags.append("USE_ORIGINAL_BACKEND")