diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -407,7 +407,6 @@ coreconfigitem( ) # TODO before getting `persistent-nodemap` out of experimental # -# * regenerate a new nodemap when the unused/total ration is to high # * decide for a "status" of the persistent nodemap and associated location # - part of the store next the revlog itself (new requirements) # - part of the cache directory diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py --- a/mercurial/revlogutils/nodemap.py +++ b/mercurial/revlogutils/nodemap.py @@ -143,13 +143,16 @@ def _persist_nodemap(tr, revlog, pending data_changed_count, data, ) = revlog.index.nodemap_data_incremental() + new_length = target_docket.data_length + len(data) + new_unused = target_docket.data_unused + data_changed_count if src_docket != target_docket: data = None + elif new_length <= (new_unused * 10): # under 10% of unused data + data = None else: datafile = _rawdata_filepath(revlog, target_docket) # EXP-TODO: if this is a cache, this should use a cache vfs, not a # store vfs - new_length = target_docket.data_length + len(data) tr.add(datafile, target_docket.data_length) with revlog.opener(datafile, b'r+') as fd: fd.seek(target_docket.data_length) @@ -162,7 +165,7 @@ def _persist_nodemap(tr, revlog, pending fd.flush() new_data = util.buffer(util.mmapread(fd, new_length)) target_docket.data_length = new_length - target_docket.data_unused += data_changed_count + target_docket.data_unused = new_unused if data is None: # otherwise fallback to a full new export diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t --- a/tests/test-persistent-nodemap.t +++ b/tests/test-persistent-nodemap.t @@ -278,12 +278,12 @@ the nodemap should detect the changelog tip-rev: 5002 tip-node: 42bf3068c7ddfdfded53c4eb11d02266faeebfee data-length: 123456 (pure !) - data-length: 246464 (rust !) + data-length: 123008 (rust !) data-length: 123008 (no-pure no-rust !) data-unused: 448 (pure !) - data-unused: 123904 (rust !) + data-unused: 0 (rust !) data-unused: 0 (no-pure no-rust !) - data-unused: 50.273% (rust !) + data-unused: 0.000% (rust !) data-unused: 0.363% (pure !) data-unused: 0.000% (no-pure no-rust !)