# HG changeset patch # User Anton Shestakov # Date 1705685375 10800 # Node ID 1c998ed775973dae766b3e911a4a2af520ac6240 # Parent d3668c704d407bfb0ea16fd116a68e694d3f0cf5 topic: remove .hg/topic-namespace file if it has the default value See the comment in the test file for the rationale behind this patch. diff -r d3668c704d40 -r 1c998ed77597 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Thu Jan 18 14:32:41 2024 -0300 +++ b/hgext3rd/topic/__init__.py Fri Jan 19 14:29:35 2024 -0300 @@ -157,6 +157,7 @@ from __future__ import absolute_import +import errno import functools import re import time @@ -716,7 +717,29 @@ @property def currenttns(self): - tns = self.vfs.tryread(b'topic-namespace') or b'none' + tns = self.vfs.tryread(b'topic-namespace') + # we should definitely drop this at some point, but it depends on + # our own release schedule, not core's, so here's hg 1.0 + # hg <= 1.0 (cfa08c88a5c4) + if tns == b'none': + try: + with self.wlock(wait=False): + try: + # we make sure the file contains what we expect + if self.vfs.read(b'topic-namespace') == b'none': + repo.vfs.unlinkpath(b'topic-namespace') + except IOError as err: + if err.errno != errno.ENOENT: + raise + except error.LockError: + # if we cannot acquire wdir lock, then we shouldn't do + # anything at all, since it'd be unsafe to modify wdir + pass + elif tns == b'': + # technically, if user creates an empty file, it should be + # handled differently than non-existing file, but the + # distinction is probably not that important + tns = b'none' return encoding.tolocal(tns) @util.propertycache diff -r d3668c704d40 -r 1c998ed77597 tests/test-namespaces.t --- a/tests/test-namespaces.t Thu Jan 18 14:32:41 2024 -0300 +++ b/tests/test-namespaces.t Fri Jan 19 14:29:35 2024 -0300 @@ -88,6 +88,20 @@ $ hg branches stable//alice/feature 0:69c7dbf6acd1 +Removing topic namespace file if it contains the default value + +The default value changed from b'default' to b'none' in 11.1.0, this is a +safeguard against accidentally putting the new default tns value into commit +extras with an old version of topic extension + + $ printf 'none' > .hg/topic-namespace + $ test -f .hg/topic-namespace + $ hg ci -m '' + nothing changed + [1] + $ test -f .hg/topic-namespace + [1] + Updating to a revision with a namespace should activate it $ hg up null