comparison hgext3rd/topic/__init__.py @ 6759:bdf99d434b06 mercurial-5.9

test-compat: merge mercurial-6.0 into mercurial-5.9
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 11 Apr 2024 12:05:06 -0300
parents afa6de693c9f 107c5af631a7
children 045db43f35b1
comparison
equal deleted inserted replaced
6717:afa6de693c9f 6759:bdf99d434b06
177 exchange, 177 exchange,
178 extensions, 178 extensions,
179 hg, 179 hg,
180 localrepo, 180 localrepo,
181 lock as lockmod, 181 lock as lockmod,
182 logcmdutil,
182 merge, 183 merge,
183 namespaces, 184 namespaces,
184 node, 185 node,
185 obsolete, 186 obsolete,
186 obsutil, 187 obsutil,
235 # default color to help log output and thg 236 # default color to help log output and thg
236 # (first pick I could think off, update as needed 237 # (first pick I could think off, update as needed
237 b'log.topic': b'green_background', 238 b'log.topic': b'green_background',
238 } 239 }
239 240
240 __version__ = b'1.1.2.dev0' 241 __version__ = b'1.1.3.dev0'
241 242
242 testedwith = b'4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7' 243 testedwith = b'4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7'
243 minimumhgversion = b'4.9' 244 minimumhgversion = b'4.9'
244 buglink = b'https://bz.mercurial-scm.org/' 245 buglink = b'https://bz.mercurial-scm.org/'
245 246
292 configitem(b'experimental', b'tns-allow-rewrite', 293 configitem(b'experimental', b'tns-allow-rewrite',
293 default=configitems.dynamicdefault, 294 default=configitems.dynamicdefault,
294 ) 295 )
295 configitem(b'experimental', b'tns-default-pull-namespaces', 296 configitem(b'experimental', b'tns-default-pull-namespaces',
296 default=configitems.dynamicdefault, 297 default=configitems.dynamicdefault,
298 )
299 configitem(b'experimental', b'tns-reject-push',
300 default=False,
297 ) 301 )
298 configitem(b'experimental', b'topic-mode.server', 302 configitem(b'experimental', b'topic-mode.server',
299 default=configitems.dynamicdefault, 303 default=configitems.dynamicdefault,
300 ) 304 )
301 configitem(b'experimental', b'topic.server-gate-topic-changesets', 305 configitem(b'experimental', b'topic.server-gate-topic-changesets',
713 namespaces.add(c.topic_namespace()) 717 namespaces.add(c.topic_namespace())
714 namespaces.remove(b'none') 718 namespaces.remove(b'none')
715 self._topic_namespaces = namespaces 719 self._topic_namespaces = namespaces
716 return namespaces 720 return namespaces
717 721
718 @property 722 def wlock(self, wait=True):
719 def currenttns(self): 723 wlock = super(topicrepo, self).wlock(wait=wait)
720 tns = self.vfs.tryread(b'topic-namespace')
721 # we should definitely drop this at some point, but it depends on 724 # we should definitely drop this at some point, but it depends on
722 # our own release schedule, not core's, so here's hg 1.0 725 # our own release schedule, not core's, so here's hg 1.0
723 # hg <= 1.0 (cfa08c88a5c4) 726 # hg <= 1.0 (cfa08c88a5c4)
724 if tns == b'none': 727 if wlock is not None and wlock.held:
725 try: 728 try:
726 with self.wlock(wait=False): 729 if self.vfs.read(b'topic-namespace') == b'none':
727 try: 730 repo.vfs.unlinkpath(b'topic-namespace')
728 # we make sure the file contains what we expect 731 except IOError as err:
729 if self.vfs.read(b'topic-namespace') == b'none': 732 if err.errno != errno.ENOENT:
730 repo.vfs.unlinkpath(b'topic-namespace') 733 raise
731 except IOError as err: 734 return wlock
732 if err.errno != errno.ENOENT: 735
733 raise 736 @property
734 except error.LockError: 737 def currenttns(self):
735 # if we cannot acquire wdir lock, then we shouldn't do 738 tns = self.vfs.tryread(b'topic-namespace') or b'none'
736 # anything at all, since it'd be unsafe to modify wdir
737 pass
738 elif tns == b'':
739 # technically, if user creates an empty file, it should be
740 # handled differently than non-existing file, but the
741 # distinction is probably not that important
742 tns = b'none'
743 return encoding.tolocal(tns) 739 return encoding.tolocal(tns)
744 740
745 @util.propertycache 741 @util.propertycache
746 def _topiccache(self): 742 def _topiccache(self):
747 return {} 743 return {}
918 if util.safehasattr(tr, '_validator'): 914 if util.safehasattr(tr, '_validator'):
919 # hg <= 5.3 (36f08ae87ef6) 915 # hg <= 5.3 (36f08ae87ef6)
920 tr._validator = validator 916 tr._validator = validator
921 else: 917 else:
922 tr.addvalidator(b'000-reject-publish', _validate_publish) 918 tr.addvalidator(b'000-reject-publish', _validate_publish)
919
920 if self.ui.configbool(b'experimental', b'tns-reject-push'):
921 if util.safehasattr(tr, '_validator'):
922 # hg <= 5.3 (36f08ae87ef6)
923 origvalidator_publish = tr._validator
924
925 def _validate_csets_with_tns(tr2):
926 repo = reporef()
927 flow.reject_csets_with_tns(repo, tr2)
928
929 def validator(tr2):
930 _validate_csets_with_tns(tr2)
931 return origvalidator_publish(tr2)
932
933 if util.safehasattr(tr, '_validator'):
934 # hg <= 5.3 (36f08ae87ef6)
935 tr._validator = validator
936 else:
937 tr.addvalidator(b'000-reject-csets-with-tns', _validate_csets_with_tns)
923 938
924 if util.safehasattr(tr, '_validator'): 939 if util.safehasattr(tr, '_validator'):
925 # hg <= 5.3 (36f08ae87ef6) 940 # hg <= 5.3 (36f08ae87ef6)
926 origvalidator_affected_tns = tr._validator 941 origvalidator_affected_tns = tr._validator
927 942
1909 def debugtopicnamespaces(ui, repo, **opts): 1924 def debugtopicnamespaces(ui, repo, **opts):
1910 """list repository namespaces""" 1925 """list repository namespaces"""
1911 for tns in repo.topic_namespaces: 1926 for tns in repo.topic_namespaces:
1912 ui.write(b'%s\n' % (tns,)) 1927 ui.write(b'%s\n' % (tns,))
1913 1928
1929 @command(b'debug-default-topic-namespace', [
1930 (b'', b'none', True, b'find changesets with topic-namespace=none'),
1931 (b'', b'default', False, b'find changesets with topic-namespace=default'),
1932 (b'', b'clear', False, b'remove topic namespace from commit extras'),
1933 ] + commands.formatteropts)
1934 def debugdefaulttns(ui, repo, **opts):
1935 """list changesets with the default topic namespace in commit extras"""
1936 opts = pycompat.byteskwargs(opts)
1937 condition = []
1938 if opts[b'none']:
1939 condition += [b'extra("topic-namespace", "none")']
1940 if opts[b'default']:
1941 condition += [b'extra("topic-namespace", "default")']
1942 if not condition:
1943 condition = [b'none()']
1944 revs = repo.revs(b'not public() and not obsolete() and (%lr)', condition)
1945 if opts[b'clear']:
1946 with repo.wlock(), repo.lock(), repo.transaction(b'debug-default-topic-namespace'):
1947 successors = {}
1948 for rev in revs:
1949 _clear_tns_extras(ui, repo, rev, successors)
1950 scmutil.cleanupnodes(repo, successors, b'debug-default-topic-namespace')
1951 return
1952 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
1953 logcmdutil.displayrevs(ui, repo, revs, displayer, None)
1954
1955 def _clear_tns_extras(ui, repo, rev, successors):
1956 ctx = repo[rev]
1957
1958 if len(ctx.parents()) > 1:
1959 # ctx.files() isn't reliable for merges, so fall back to the
1960 # slower repo.status() method
1961 st = ctx.p1().status(ctx)
1962 files = set(st.modified) | set(st.added) | set(st.removed)
1963 else:
1964 files = set(ctx.files())
1965
1966 def filectxfn(repo, unused, path):
1967 try:
1968 return ctx[path]
1969 except error.ManifestLookupError:
1970 return None
1971
1972 extra = ctx.extra().copy()
1973 del extra[b'topic-namespace']
1974
1975 p1 = ctx.p1().node()
1976 p2 = ctx.p2().node()
1977 if p1 in successors:
1978 p1 = successors[p1][0]
1979 if p2 in successors:
1980 p2 = successors[p2][0]
1981 mc = context.memctx(repo,
1982 (p1, p2),
1983 ctx.description(),
1984 files,
1985 filectxfn,
1986 user=ctx.user(),
1987 date=ctx.date(),
1988 extra=extra)
1989
1990 overrides = {(b'phases', b'new-commit'): ctx.phase()}
1991 with repo.ui.configoverride(overrides, b'debug-default-topic-namespace'):
1992 newnode = repo.commitctx(mc)
1993
1994 successors[ctx.node()] = (newnode,)
1995
1914 @command(b'debug-parse-fqbn', commands.formatteropts, _(b'FQBN'), optionalrepo=True) 1996 @command(b'debug-parse-fqbn', commands.formatteropts, _(b'FQBN'), optionalrepo=True)
1915 def debugparsefqbn(ui, repo, fqbn, **opts): 1997 def debugparsefqbn(ui, repo, fqbn, **opts):
1916 """parse branch//namespace/topic string into its components""" 1998 """parse branch//namespace/topic string into its components"""
1917 branch, tns, topic = common.parsefqbn(fqbn) 1999 branch, tns, topic = common.parsefqbn(fqbn)
1918 opts = pycompat.byteskwargs(opts) 2000 opts = pycompat.byteskwargs(opts)