Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 195:f4f13a25fe3e
Implement a --show command for timestamps.
Because the --show command needs a "--rev" at times remove the short options
for "--restore" and (for consistency) from "--save": "-r" would conflict with
the common "-r" for requesting a revision.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sat, 06 Oct 2018 14:58:42 +0200 |
| parents | d3c66ff43b4f |
| children | d6ce48feffd5 |
| files | extensions/timestamps.py |
| diffstat | 1 files changed, 47 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/timestamps.py Sat Oct 06 11:54:58 2018 +0200 +++ b/extensions/timestamps.py Sat Oct 06 14:58:42 2018 +0200 @@ -108,8 +108,10 @@ @command( "timestamps", [ - ("s", "save", None, _("save modification times")), - ("r", "restore", None, _("restore modification times")), + ("", "save", None, _("save modification times")), + ("", "restore", None, _("restore modification times")), + ("", "show", None, _("show the contents of the timestamps database")), + ("r", "rev", "", _("the revision to use"), _("REV")), ("", "tsconfig", "", _("use an alternate configuration file"), _("TSCONFIG")), ("", "amend", None, _("amend the current database file instead of generating a fresh one")), ], @@ -124,7 +126,7 @@ """ opts = pycompat.byteskwargs(opts) - ctx = scmutil.revsingle(repo, None) + ctx = scmutil.revsingle(repo, opts.get("rev")) if not ctx: raise error.Abort(_("no Mercurial working directory")) if opts.get("save"): @@ -135,8 +137,12 @@ amend=opts.get("amend")) elif opts.get("restore"): restore_timestamps(ui, repo, ctx, tsconfig=opts.get("tsconfig")) + elif opts.get("show"): + fm = ui.formatter("timestamps", opts) + show_timestamps(ui, repo, ctx, fm, tsconfig=opts.get("tsconfig")) else: - raise error.Abort(_("must give a command: --save or --restore")) + raise error.Abort(_("must give a command:" + "--save or --restore or --show")) def save_timestamps(ui, @@ -176,6 +182,43 @@ ts = Timestamps.from_filename(repo.wjoin(TIMESTAMPS_DATABASE)) +def show_timestamps(ui, repo, ctx, fm, + tsconfig=None): + # + # NOTE: no need for a local repo here + # + matcher = gen_matcher(repo, ctx, tsconfig=tsconfig) + ts = Timestamps.from_filename(repo.wjoin(TIMESTAMPS_DATABASE)) + if ui.debugflag or ui.verbose: + files = iter(ts) + else: + files = iter(ts.files()) + ui.pager("timestamps") + with fm: + for f in files: + fm.startitem() + fm.condwrite(not ui.debugflag and ui.verbose and f == "/version/", + "version", + "version=%d\n", + ts[f]) + fm.condwrite(not ui.debugflag and ui.verbose and f == "/encoding/", + "encoding", + "encoding=%s\n", + ts[f]) + fm.condwrite(not ui.debugflag and ui.verbose and f.startswith("/comment-"), + "comment", + "%s\n", + ts[f]) + fm.condwrite(not ui.debugflag and ui.verbose and f.startswith("/-"), + "", + "\n") + fm.condwrite(ui.debugflag or not f.startswith("/"), + "date file", + "%s\t%s\n", + ts[f], + f) + + def gen_matcher(repo, ctx, tsconfig=None): """Read the configuration file and return a Mercurial matcher which is configured.
