diff hgext3rd/topic/__init__.py @ 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 991d78f5c401
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