Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 394:0fd1473ff168
Really handle repository setup: "__init__" to be called in the derived repository class cannot be relied upon.
"repo" in "reposetup" is an instance already and not a class. "__init__" has
been called already. So use the strategy to ensure that all timestamps related
variabled are initialized with the special method "_tss_ensure_vars()".
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 04 Aug 2019 17:57:53 +0200 |
| parents | dbf995ba1b75 |
| children | fdf77e125eb3 |
| files | extensions/timestamps.py |
| diffstat | 1 files changed, 23 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/timestamps.py Sun Aug 04 12:58:48 2019 +0200 +++ b/extensions/timestamps.py Sun Aug 04 17:57:53 2019 +0200 @@ -216,14 +216,28 @@ if not repo.local(): return + # + # NOTE: `repo` is not a class but an *instance* + # ``__init__`` has been called already and cannot overwritten + # afterwards. + # + class TimestampedRepo(repo.__class__): - def __init__(self, *args, **kwds): - super(TimestampedRepo, self).__init__(*args, **kwds) - self._tss_hooktype = None - self._tss_hook_pats = None - self._tss_from_parents = None - ui.warn(b"end init of a TimestampedRepo\n") + def _tss_ensure_vars(self): + """Ensure that all timestamps variables are set. + + Note that :meth:`__init__` cannot used because + :function:`reposetup` is called with an *instance* and not a + class. + + """ + if not hasattr(self, "_tss_initialized"): + self._tss_hooktype = None + self._tss_hook_pats = None + self._tss_from_parents = None + self._tss_initialized = True + self.ui.debug(_(b"timestamps: variables initialized")) def commit(self, text=b"", user=None, date=None, match=None, force=False, editor=False, extra=None, **kwds): @@ -245,7 +259,7 @@ if match is None: self.ui.status(_("timestamps: handling skipped: no `match' instance given in commit\n")) return None - + self._tss_ensure_vars() wctx = self[None] tsconfmatch = _gen_matcher_from_tsconfig(wctx) if tsconfmatch is not None: @@ -335,6 +349,7 @@ def _tss_record_pre_data(self, hooktype, **kwds): """Called by generic pre-hooks""" + self._tss_ensure_vars() self._tss_hooktype = hooktype self._tss_hook_pats = kwds.get("pats", None) self._tss_from_parents = [p.hex() for p in self[None].parents()] @@ -343,6 +358,7 @@ """Called on :hg:`hg update` and :hg:`hg merge` """ + self._tss_ensure_vars() if not self._tss_hooktype \ or self._tss_hooktype not in (b"pre-update", b"pre-merge"):
