diff --git a/docs/devel/development.rst b/docs/devel/development.rst index b1056cd9c..b511f9248 100644 --- a/docs/devel/development.rst +++ b/docs/devel/development.rst @@ -515,12 +515,12 @@ When editing is complete run one or more of:: moin maint-reduce-revisions -q -n help-en --test true # lists selected items, no updates moin maint-reduce-revisions -q -n help-en # updates selected items -Dump all the help files:: +Dump all the English help files to the version controlled directory:: moin dump-help -n en -The above command may update meta files even though the data files have not changed, see #1533. -Commit only the target data and meta files. Revert the other meta files. +The above command may may be useful after updating one or more files. All of the files +will be rewritten but only the changed files will be highlighted in version control. Moin Shell ========== diff --git a/src/moin/cli/maint/modify_item.py b/src/moin/cli/maint/modify_item.py index a271a4fb2..992a7bafc 100644 --- a/src/moin/cli/maint/modify_item.py +++ b/src/moin/cli/maint/modify_item.py @@ -117,7 +117,11 @@ def PutItem(meta_file, data_file, overwrite): to_kill = [WIKINAME, ] # use target wiki name for key in to_kill: meta.pop(key, None) - if not overwrite: + if overwrite: + # by default, indexing.py will update meta[MTIME] with current time making global history useless + # we preserve the old modified time for use by indexing.py + flaskg.data_mtime = meta[MTIME] + else: # if we remove the REVID, it will create a new one and store under the new one meta.pop(REVID, None) meta.pop(DATAID, None) diff --git a/src/moin/cli/maint/reduce_revisions.py b/src/moin/cli/maint/reduce_revisions.py index e2508af06..79765dc6d 100644 --- a/src/moin/cli/maint/reduce_revisions.py +++ b/src/moin/cli/maint/reduce_revisions.py @@ -14,11 +14,12 @@ import click from flask import current_app as app +from flask import g as flaskg from flask.cli import FlaskGroup from whoosh.query import Term, And, Regex, Not -from moin.constants.keys import NAME, NAME_EXACT, NAMESPACE, REVID, WIKINAME, PARENTID, REV_NUMBER +from moin.constants.keys import NAME, NAME_SORT, NAME_EXACT, NAMESPACE, REVID, WIKINAME, PARENTID, REV_NUMBER, MTIME from moin.constants.namespaces import NAMESPACE_USERPROFILES from moin.app import create_app, before_wiki @@ -36,7 +37,7 @@ def cli(): @click.option('--query', '-q', type=str, default='', help='Only perform the operation on items found by the given query.') @click.option('--namespace', '-n', type=str, default='', - help='Limit selection to this namespace.') + help='Limit selection to a namespace; use "default" for default namespace.') @click.option('--test', '-t', type=bool, default=0, help='List selected items, but do not update.') def ReduceRevisions(query, namespace, test): @@ -47,11 +48,13 @@ def ReduceRevisions(query, namespace, test): if query: q = And([q, Regex(NAME_EXACT, query)]) if namespace: - q = And([q, Regex(NAMESPACE, namespace)]) + if namespace == 'default': + namespace = '' + q = And([q, Term(NAMESPACE, namespace)]) else: q = Not(Term(NAMESPACE, NAMESPACE_USERPROFILES)) - for current_rev in app.storage.search(q, limit=None): + for current_rev in app.storage.search(q, limit=None, sortedby=[NAMESPACE, NAME_SORT]): current_name = current_rev.meta[NAME] current_revid = current_rev.meta[REVID] current_namespace = current_rev.meta[NAMESPACE] @@ -76,6 +79,10 @@ def ReduceRevisions(query, namespace, test): changed = True del meta[PARENTID] if changed: + # By default store_revision and whoosh will replace mtime with current time making + # global history useless. + # Save existing mtime which has time this revision's data was last modified. + flaskg.data_mtime = meta[MTIME] current_rev.item.store_revision(meta, current_rev.data, overwrite=True) print(" (current rev meta data updated)") continue diff --git a/src/moin/storage/middleware/indexing.py b/src/moin/storage/middleware/indexing.py index 97deb9d9b..c3f4a47e1 100644 --- a/src/moin/storage/middleware/indexing.py +++ b/src/moin/storage/middleware/indexing.py @@ -301,9 +301,9 @@ def tell(self, *args, **kw): doc.set(moin_page.page_href, str(i)) refs_conv(doc) # side effect: we update some metadata: - meta[ITEMLINKS] = refs_conv.get_links() - meta[ITEMTRANSCLUSIONS] = refs_conv.get_transclusions() - meta[EXTERNALLINKS] = refs_conv.get_external_links() + meta[ITEMLINKS] = sorted(refs_conv.get_links()) + meta[ITEMTRANSCLUSIONS] = sorted(refs_conv.get_transclusions()) + meta[EXTERNALLINKS] = sorted(refs_conv.get_external_links()) doc = output_conv(doc) return doc # no way @@ -1233,6 +1233,10 @@ def store_revision(self, meta, data, overwrite=False, # e.g. userdefined meta keys or stuff we do not validate. thus, we # just update the meta dict with the validated stuff: meta.update(dict(m.value.items())) + if hasattr(flaskg, 'data_mtime'): + # this is maint-reduce-revisions OR item-put CL process, restore saved time of item's last update + meta[MTIME] = flaskg.data_mtime + del flaskg.data_mtime # we do not want None / empty values: # XXX do not kick out empty lists before fixing NAME processing: meta = dict([(k, v) for k, v in meta.items() if v not in [None, ]])