Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 329:39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 10 Jul 2019 17:42:30 +0200 |
| parents | 80fa55e2fb16 |
| children | 793161e48af2 |
| files | .hgkwarchive extensions/revinfo.py tests/test-revinfo.t |
| diffstat | 3 files changed, 43 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgkwarchive Mon Jul 08 18:11:51 2019 +0200 +++ b/.hgkwarchive Wed Jul 10 17:42:30 2019 +0200 @@ -3,6 +3,7 @@ path:VERSION = reST path:README = RCS, reST path:test2.txt = RCS, reST +path:tests/test-revinfo.t = reST [keywords] JustDate =
--- a/extensions/revinfo.py Mon Jul 08 18:11:51 2019 +0200 +++ b/extensions/revinfo.py Wed Jul 10 17:42:30 2019 +0200 @@ -37,7 +37,7 @@ command = cmdutil.command(cmdtable) -testedwith = "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" +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" def getversion(): @@ -52,26 +52,26 @@ try: fn = __file__ except NameError: - return "<unknown>" + return b"<unknown>" else: try: verdata = open(os.path.join(os.path.dirname(fn), "../VERSION"), - "r").read() - return re.search("^(.*)", verdata,).group(1) + "rb").read() + return re.search(b"^(.*)", verdata,).group(1) except OSError: - return "<not found>" + return b"<not found>" @command( - "revinfo", + b"revinfo", [ - ("r", "rev", "", _('revision to handle'), _('REV')), - ("", "amend", None, _('amend a given file with path information')), - ("p", "path", [], _('the configured default path'), _('SOURCE')), - ("d", "data", [], _("add an extra `KEY: VALUE' pair into the file"), _('KEY=VALUE')), + (b'r', b"rev", b'', _(b"revision to handle"), _(b"REV")), + (b'', b"amend", None, _(b"amend a given file with path information")), + (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")), ], - _("hg revinfo [OPTION]... [DEST]"), + _(b"hg revinfo [OPTION]... [DEST]"), inferrepo=True) def revinfo(ui, repo, dest=None, **opts): """write a revision summary @@ -96,49 +96,49 @@ """ opts = pycompat.byteskwargs(opts) - if opts.get("amend") and opts.get("rev"): - raise error.Abort(_("cannot use -r/--rev together with --amend")) + if opts.get(b"amend") and opts.get(b"rev"): + raise error.Abort(_(b"cannot use -r/--rev together with --amend")) - if opts.get("amend"): + if opts.get(b"amend"): if not dest: - raise error.Abort(_('need a destination file with --amend')) + 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("rev")) + ctx = scmutil.revsingle(repo, opts.get(b"rev")) if not ctx: raise error.Abort( - _("no working directory: please specify a revision")) + _(b"no working directory: please specify a revision")) msg = archival.buildmetadata(ctx) - for kv in opts.get("data"): - kvparts = [i.strip() for i in kv.split("=", 1)] + for kv in opts.get(b"data"): + kvparts = [i.strip() for i in kv.split(b'=', 1)] if len(kvparts) == 2: - msg += "%s: %s\n" % tuple(kvparts) + msg += b"%s: %s\n" % tuple(kvparts) else: raise error.Abort( - _("given data `%s' is not a KEY=VALUE pair") % (kv, )) + _(b"given data `%s' is not a KEY=VALUE pair") % (kv, )) - paths = opts.get("path") + paths = opts.get(b"path") # # When not amending and no path options is given print the # "default" path # - if not opts.get("amend"): + if not opts.get(b"amend"): if not paths: - paths = ["default"] + paths = [b"default"] for canonicalpath in paths: if canonicalpath: - if canonicalpath == ".": - msg += "path: %s\n" % repo.root + if canonicalpath == b'.': + msg += b"path: %s\n" % repo.root else: - for name, path in sorted(ui.paths.iteritems()): + for name, path in sorted(ui.paths.items()): if name == canonicalpath: - msg += "path: %s\n" % util.hidepassword(path.loc) + msg += b"path: %s\n" % util.hidepassword(path.loc) break else: - msg += "path: %s\n" % canonicalpath + msg += b"path: %s\n" % canonicalpath if dest: with open(dest, "wb") as rfile: rfile.write(msg)
--- a/tests/test-revinfo.t Mon Jul 08 18:11:51 2019 +0200 +++ b/tests/test-revinfo.t Wed Jul 10 17:42:30 2019 +0200 @@ -72,3 +72,16 @@ path: https://theuser:***@hg.example.com:4443/repo.hg key1: val1 key2: val2 with space + +Now test module help because of PY3 compatibility with Unicode doc-strings + + $ hg help -e revinfo + revinfo extension - write a revision summary similar to .hg_archival.txt + ^$ (re) + (rev |VCSRevision|) + ^$ (re) + list of commands: + ^$ (re) + revinfo write a revision summary + ^$ (re) + (use 'hg help -v -e revinfo' to show built-in aliases and global options)
