changeset 6657:1c998ed77597 stable

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.
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 19 Jan 2024 14:29:35 -0300
parents d3668c704d40
children 5e6fa2dd796a
files hgext3rd/topic/__init__.py tests/test-namespaces.t
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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