def _smartlog(ui, repo, *pats, **opts): masterfallback = "interestingmaster()" masterstring = (opts.get("master") or ui.config("smartlog", "master") or masterfallback) masterrev = repo.anyrevs([masterstring], user=True).first() revs = getrevs(ui, repo, masterstring, **opts) if -1 in revs: revs.remove(-1) if len(revs) == 0: return # Print it! template = opts.get("template") or "" revdag, reserved = getdag(ui, repo, sorted(revs), masterrev, template) displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) ui.pager("smartlog") cmdutil.displaygraph(ui, repo, revdag, displayer, reserved=reserved) try: with open(repo.localvfs.join("completionhints"), "w+") as f: for rev in revdag: commit_hash = rev[2].node() f.write(nodemod.short(commit_hash) + "\n") except IOError: # No write access. No big deal. pass
def _showchangesets(ui, repo, contexts=None, revs=None, nodes=None, indices=False): """Pretty print a list of changesets. Can take a list of change contexts, a list of revision numbers, or a list of commit hashes. """ if contexts is None: contexts = [] if revs is not None: contexts.extend(repo[r] for r in revs) if nodes is not None: contexts.extend(repo[n] for n in nodes) showopts = { "template": '[{shortest(node, 6)}] {if(bookmarks, "({bookmarks}) ")}' "{desc|firstline}\n" } displayer = cmdutil.show_changeset(ui, repo, showopts) contexts = sorted(contexts, key=lambda c: c.rev()) for idx, ctx in enumerate(contexts, start=1): if indices: ui.status(_("({}) ").format(idx)) displayer.show(ctx) return contexts
def render(self): ui = self.ui ui.pushbuffer() ui.status(_("Interactive Smartlog History\n\n")) if opts.get("all"): limit = 0 else: limit = 2 * 604800 # two weeks if self.index == len(self.versions): self.index = -1 if self.index == -2: self.index = len(self.versions) - 1 if self.index == -1: with progress.spinner(ui, _("fetching")): firstpublic, revdag = serv.getsmartlog( reponame, workspacename, repo, limit) ui.status(_("Current Smartlog:\n\n")) else: with progress.spinner(ui, _("fetching")): firstpublic, revdag, slversion, sltimestamp = serv.getsmartlogbyversion( reponame, workspacename, repo, None, self.versions[self.index]["version_number"], limit, ) formatteddate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(sltimestamp)) ui.status( _("Smartlog version %d \nsynced at %s\n\n") % (slversion, formatteddate)) template = "sl_cloud" smartlogstyle = ui.config("templatealias", template) if smartlogstyle: opts["template"] = "{%s}" % smartlogstyle else: ui.debug( _("style %s is not defined, skipping") % smartlogstyle, component="commitcloud", ) 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) repo.ui.status( _("<-: newer " "->: older " "q: abort \n" "a: 1 day forward d: 1 day back \n")) return ui.popbuffer()
def _smartlog(ui, repo, *pats, **opts): if opts.get("rev"): masterfallback = "null" else: masterfallback = "interestingmaster()" masterstring = (opts.get("master") or ui.config("smartlog", "master") or masterfallback) masterrev = repo.anyrevs([masterstring], user=True).first() revs = getrevs(ui, repo, masterstring, **opts) if -1 in revs: revs.remove(-1) if len(revs) == 0: return # Print it! revdag, reserved = getdag(ui, repo.unfiltered(), sorted(revs, reverse=True), masterrev) displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) ui.pager("smartlog") if ui.config("experimental", "graph.renderer") == "legacy": overrides = {} if ui.config("experimental", "graphstyle.grandparent", "2.") == "|": overrides[("experimental", "graphstyle.grandparent")] = "2." with ui.configoverride(overrides, "smartlog"): if reserved: for prev in reserved: addfakerev(revdag, prev) cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, None, None) else: cmdutil.rustdisplaygraph(ui, repo, revdag, displayer, reserved=reserved) try: with open(repo.localvfs.join("completionhints"), "w+") as f: for rev in revdag: commit_hash = rev[2].node() # Skip fakectxt nodes if commit_hash != "...": f.write(nodemod.short(commit_hash) + "\n") except IOError: # No write access. No big deal. pass global hiddenchanges if hiddenchanges: ui.warn( _("hiding %s old heads without bookmarks\n") % hiddenchanges, notice=_("note"), ) ui.warn(_("(use --all to see them)\n"))
def patchcontents(state): repo = state["repo"] rule = state["rules"][state["pos"]] displayer = cmdutil.show_changeset( repo.ui, repo, {"patch": True, "verbose": True}, buffered=True ) displayer.show(rule.ctx) displayer.close() return displayer.hunk[rule.ctx.rev()].splitlines()
def _showrev(ui, repo, revid): """pretty print the changeset to drop""" showopts = { "template": "Dropping changeset " '{shortest(node, 6)}{if(bookmarks, " ({bookmarks})")}' ": {desc|firstline}\n" } displayer = cmdutil.show_changeset(ui, repo, showopts) displayer.show(repo[revid])
def snapshotshow(ui, repo, *args, **opts): """show the snapshot contents, given its revision id""" cctx = getsnapshotctx(ui, repo, args) rev = cctx.hex() opts["rev"] = [rev] opts["patch"] = True revs, expr, filematcher = cmdutil.getlogrevs(repo, [], opts) revmatchfn = filematcher(rev) if filematcher else None ui.pager("snapshotshow") displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) with extensions.wrappedfunction(patch, "diff", _diff), extensions.wrappedfunction( cmdutil.changeset_printer, "_show", _show ), extensions.wrappedfunction(cmdutil.changeset_templater, "_show", _show): displayer.show(cctx, matchfn=revmatchfn) displayer.flush(cctx) displayer.close()
def rendercontents(self, versionindex): if versionindex in self.cache: contents = self.cache[versionindex] else: if versionindex == len(self.versions): (title, slinfo) = self.loadcurrentversion() else: (title, slinfo) = self.loadoldversion(versionindex) contents = [ ui.label("Commit Cloud Smartlog History", "bold cyan underline").encode(), ui.label( "Use [ and ] to navigate to earlier or later versions", "cyan").encode(), ui.label( "Note: version dates may be off by one due to a server bug", "cyan", ).encode(), b"", title.encode(), b"", ] firstpublic, revdag = self.serv.makedagwalker( slinfo, self.repo) displayer = cmdutil.show_changeset(self.ui, self.repo, self.opts, buffered=True) def out(row): contents.extend(row.rstrip().encode().split(b"\n")) with progress.spinner(ui, _("loading commit information")): cmdutil.displaygraph( self.ui, self.repo, revdag, displayer, reserved=firstpublic, out=out, ) self.cache[versionindex] = contents return contents
def _showchangesets(ui, repo, contexts=None, revs=None, nodes=None): """Pretty print a list of changesets. Can take a list of change contexts, a list of revision numbers, or a list of commit hashes. """ if contexts is None: contexts = [] if revs is not None: contexts.extend(repo[r] for r in revs) if nodes is not None: contexts.extend(repo[n] for n in nodes) showopts = { "template": '[{shortest(node, 6)}] {if(bookmarks, "({bookmarks}) ")}' "{desc|firstline}\n" } displayer = cmdutil.show_changeset(ui, repo, showopts) for ctx in sorted(contexts, key=lambda c: c.rev()): displayer.show(ctx)
def journal(ui, repo, *args, **opts) -> None: """show history of the checked out commit or a bookmark Show the history of all the commits that were once the current commit. In other words, shows a list of your previously checked out commits. :hg:`journal` can be used to find older versions of commits (for example, when you want to revert to a previous state). It can also be used to discover commits that were previously hidden. By default, :hg:`journal` displays the history of the current commit. To display a list of commits pointed to by a bookmark, specify a bookmark name. Specify --all to show the history of both the current commit and all bookmarks. In the output for --all, bookmarks are listed by name, and '.' indicates the current commit. Specify -Tjson to produce machine-readable output. .. container:: verbose By default, :hg:`journal` only shows the commit hash and the corresponding command. Specify --verbose to also include the previous commit hash, user, and timestamp. Use -c/--commits to output log information about each commit hash. To customize the log output, you can also specify switches like '--patch', '--git', '--stat', and '--template'. If a bookmark name starts with 're:', the remainder of the name is treated as a regular expression. To match a name that actually starts with 're:', use the prefix 'literal:'. """ name = "." if opts.get("all"): if args: raise error.Abort( _("You can't combine --all and filtering on a name")) name = None if args: name = args[0] fm = ui.formatter("journal", opts) ui.pager("journal") if not opts.get("template"): if name is None: displayname = _("the working copy and bookmarks") else: displayname = "'%s'" % name ui.status(_("previous locations of %s:\n") % displayname) limit = cmdutil.loglimit(opts) entry = None for count, entry in enumerate(repo.journal.filtered(name=name)): if count == limit: break newhashesstr = fm.formatlist(list(map(fm.hexfunc, entry.newhashes)), name="node", sep=",") oldhashesstr = fm.formatlist(list(map(fm.hexfunc, entry.oldhashes)), name="node", sep=",") fm.startitem() fm.condwrite(ui.verbose, "oldhashes", "%s -> ", oldhashesstr) fm.write("newhashes", "%s", newhashesstr) fm.condwrite(ui.verbose, "user", " %-8s", entry.user) fm.condwrite( opts.get("all") or name.startswith("re:"), "name", " %-8s", entry.name) timestring = fm.formatdate(entry.timestamp, "%Y-%m-%d %H:%M %1%2") fm.condwrite(ui.verbose, "date", " %s", timestring) fm.write("command", " %s\n", entry.command) if opts.get("commits"): displayer = cmdutil.show_changeset(ui, repo, opts, buffered=False) for hash in entry.newhashes: try: ctx = repo[hash] displayer.show(ctx) except error.RepoLookupError as e: fm.write("repolookuperror", "%s\n\n", str(e)) displayer.close() fm.end() if entry is None and not opts.get("template"): ui.status(_("no recorded locations\n"))
def showtemplate(ui, repo, rev, **opts): if opts.get("template"): displayer = cmdutil.show_changeset(ui, repo, opts) displayer.show(rev)
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)