Mercurial > hgrepos > DevTools > mercurial-extensions
view extensions/revinfo.py @ 440:72df885a1012 default tip trunk
===== signature for changeset e1ae0c15acfc
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 30 May 2026 13:16:08 +0200 |
| parents | 11bbdd7fd7b0 |
| children |
line wrap: on
line source
# -*- coding: utf-8 -*- # @(#) $HGheader$ # $HGnodeid$ # :- # :Copyright: © 2015-2026 Franz Glasner <fzglas.hg@dom66.de> # :License: This software may be used and distributed according to the # terms of the GNU General Public License version 2 or any # later version. # The license is incorporated herein by reference. # :- # """write a revision summary similar to .hg_archival.txt (rev |VCSRevision|) """ __revision__ = "|VCSRevision|" __date__ = "|VCSJustDate|" __author__ = "Franz Glasner" from mercurial.i18n import _ from mercurial import (cmdutil, scmutil, error, archival, pycompat, util, templatefilters, demandimport) with demandimport.deactivated(): try: from mercurial import registrar except ImportError: registrar = None # some URL specific util functions moved to new mercurial.utils.urlutil try: from mercurial.utils import urlutil as _urlutil except ImportError: _urlutil = util testedwith = b"4.3.1 4.3.2 4.4.1 4.4.2 4.5.2 4.6.1 4.8.1 4.9 5.0.1 5.1.2 5.2.1 5.5 5.6 5.9.1 6.1.4 6.9.5" cmdtable = {} if registrar and hasattr(registrar, "command"): command = registrar.command(cmdtable) else: command = cmdutil.command(cmdtable) def getversion(): """Provide the version information for verbose :hg:`version` output. Read the :file:`VERSION` from the parent of the :file:`extensions` directory. """ import re import os try: fn = __file__ except NameError: return b"<unknown>" else: try: verdata = open(os.path.join(os.path.dirname(fn), "../VERSION"), "rb").read() return re.search(b"^(.*)", verdata,).group(1) except OSError: return b"<not found>" @command( b"revinfo", [ (b'r', b"rev", b'', _(b"revision to handle"), _(b"REV")), (b'', b"amend", None, _(b"amend a given file with path information")), (b'T', b'timestamp', None, _(b"put also the commit timestamp into the file")), (b'D', b'date', None, _(b"put also the the commit date into the file")), (b'p', b"path", [], _(b"the configured default path"), _(b"SOURCE")), (b'd', b"data", [], _(b"add an extra `KEY: VALUE' pair into the file"), _(b"KEY=VALUE")), ], _(b"hg revinfo [OPTION]... [DEST]"), inferrepo=True) def revinfo(ui, repo, dest=None, **opts): """write a revision summary If DEST is given the info is written into the file DEST. Otherwise it is written to stdout. By default, the revision used is the parent of the working directory; use -r/--rev to specify a different revision. Use -p/--path to specify named path information from :hg:`paths` as the canonical repository location. It will be printed as "path" item to the output. If no path is given then "default" is assumed. Use "." to use the current workspace root. Disable this by providing an empty SOURCE. Use --amend to extend a given file with a "path" item. Can also be used to put more than one path item into the file. Use -T/--timestamp to put also the complete commit timestamp in ISO format into the output. It will be printed as "timestamp" item. Use -D/--date to put the commit date in ISO format (YYYY-MM-DD) into the output. It will be printed as "date" item. The printed information is the same as the :hg:`archive` command writes into ".hg_archival.txt". The "path", "timestamp" and "date" infos are extra items. """ opts = pycompat.byteskwargs(opts) if opts.get(b"amend") and opts.get(b"rev"): raise error.Abort(_(b"cannot use -r/--rev together with --amend")) if opts.get(b"amend") and opts.get(b"timestamp"): raise error.Abort(_(b"cannot use -T/--timestamp together with --amend")) if opts.get(b"amend") and opts.get(b"date"): raise error.Abort(_(b"cannot use -D/--date together with --amend")) if opts.get(b"amend"): if not dest: raise error.Abort(_(b"need a destination file with --amend")) with open(dest, "rb") as rfile: msg = rfile.read() else: ctx = scmutil.revsingle(repo, opts.get(b"rev")) if not ctx: raise error.Abort( _(b"no working directory: please specify a revision")) msg = archival.buildmetadata(ctx) if opts.get(b"timestamp"): msg += b"timestamp: %s\n" % templatefilters.isodatesec(ctx.date()) if opts.get(b"date"): msg += b"date: %s\n" % templatefilters.shortdate(ctx.date()) for kv in opts.get(b"data"): kvparts = [i.strip() for i in kv.split(b'=', 1)] if len(kvparts) == 2: msg += b"%s: %s\n" % tuple(kvparts) else: raise error.Abort( _(b"given data `%s' is not a KEY=VALUE pair") % (kv, )) paths = opts.get(b"path") # # When not amending and no path options is given print the # "default" path # if not opts.get(b"amend"): if not paths: paths = [b"default"] for canonicalpath in paths: if canonicalpath: if canonicalpath == b'.': msg += b"path: %s\n" % repo.root else: # # Since Mercurial 5.8 ui.paths[n] yields a list of # locations # for name, paths in sorted(ui.paths.items()): if not isinstance(paths, list): paths = [paths] # for now a quick check of assumptions assert len(paths) == 1 if name == canonicalpath: msg += b"path: %s\n" % _urlutil.hidepassword(paths[0].loc) break else: msg += b"path: %s\n" % canonicalpath if dest: with open(dest, "wb") as rfile: rfile.write(msg) else: ui.write(msg)
