From patchwork Mon Feb 10 18:02:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D8095: tags: behave better if a tags cache entry is partially written From: phabricator X-Patchwork-Id: 45077 Message-Id: <83ddcc70327fff93738045aaa556dec8@localhost.localdomain> To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Mon, 10 Feb 2020 18:02:18 +0000 Closed by commit rHGf5a7cf0adb12: tags: behave better if a tags cache entry is partially written (authored by valentin.gatienbaron). This revision was automatically updated to reflect the committed changes. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D8095?vs=19997&id=20056 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D8095/new/ REVISION DETAIL https://phab.mercurial-scm.org/D8095 AFFECTED FILES mercurial/tags.py tests/test-tags.t CHANGE DETAILS To: valentin.gatienbaron, #hg-reviewers, pulkit Cc: mercurial-devel diff --git a/tests/test-tags.t b/tests/test-tags.t --- a/tests/test-tags.t +++ b/tests/test-tags.t @@ -371,25 +371,19 @@ 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> tags exited 0 after * seconds (glob) 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> blackbox -l 6 -Junk data + missing cache entries results in hg further corrupting the -cache, then failing. +On junk data + missing cache entries, hg also overwrites the junk. $ rm -f .hg/cache/tags2-visible $ truncate .hg/cache/hgtagsfnodes1 -s -10 $ hg debugtagscache | tail -2 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d - 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8af31de17fab7ffffffffffffffffffff + 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 missing/invalid $ hg tags - abort: data/.hgtags.i@0c04f2a8af31: no match found! - [255] + tip 5:8dbfe60eff30 + bar 1:78391a272241 $ hg debugtagscache | tail -2 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d - 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8af31de17fab7ffffffffffffffffffff -# fix up the cache - $ rm .hg/cache/hgtagsfnodes1 - $ hg tags -q - tip - bar + 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8af31de17fab7422878ee5a2dadbc943d #if unix-permissions no-root Errors writing to .hgtags fnodes cache are silently ignored diff --git a/mercurial/tags.py b/mercurial/tags.py --- a/mercurial/tags.py +++ b/mercurial/tags.py @@ -720,15 +720,18 @@ self._dirtyoffset = None - if rawlen < wantedlen: - self._dirtyoffset = rawlen - self._raw.extend(b'\xff' * (wantedlen - rawlen)) - elif rawlen > wantedlen: + rawlentokeep = min(wantedlen, (rawlen / _fnodesrecsize) * _fnodesrecsize) + if rawlen > rawlentokeep: # There's no easy way to truncate array instances. This seems # slightly less evil than copying a potentially large array slice. - for i in range(rawlen - wantedlen): + for i in range(rawlen - rawlentokeep): self._raw.pop() - self._dirtyoffset = len(self._raw) + rawlen = len(self._raw) + self._dirtyoffset = rawlen + if rawlen < wantedlen: + if self._dirtyoffset is None: + self._dirtyoffset = rawlen + self._raw.extend(b'\xff' * (wantedlen - rawlen)) def getfnode(self, node, computemissing=True): """Obtain the filenode of the .hgtags file at a specified revision.