2012-12-19 17:43:33 +04:00
|
|
|
# branchmap.py - logic to computes, maintain and stores branchmap for local repo
|
|
|
|
#
|
|
|
|
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
2012-12-20 16:37:37 +04:00
|
|
|
|
2015-08-08 05:51:55 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2019-02-23 07:58:37 +03:00
|
|
|
from . import scmutil
|
|
|
|
from .node import nullid, nullrev
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2013-11-06 23:38:34 +04:00
|
|
|
|
2012-12-20 17:45:17 +04:00
|
|
|
def updatecache(repo):
|
2018-10-18 16:15:40 +03:00
|
|
|
# Don't write the branchmap if it's disabled.
|
2019-02-23 07:58:37 +03:00
|
|
|
# The original logic has unnecessary steps, ex. it calculates the "served"
|
|
|
|
# repoview as an attempt to build branchcache for "visible". And then
|
|
|
|
# calculates "immutable" for calculating "served", recursively.
|
|
|
|
#
|
|
|
|
# Just use a shortcut path that construct the branchcache directly.
|
|
|
|
partial = repo._branchcaches.get(repo.filtername)
|
|
|
|
if partial is None:
|
|
|
|
partial = branchcache()
|
|
|
|
partial.update(repo, None)
|
|
|
|
repo._branchcaches[repo.filtername] = partial
|
2012-12-22 04:44:42 +04:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2012-12-22 04:44:42 +04:00
|
|
|
class branchcache(dict):
|
2013-11-16 08:18:08 +04:00
|
|
|
"""A dict like object that hold branches heads cache.
|
|
|
|
|
|
|
|
This cache is used to avoid costly computations to determine all the
|
|
|
|
branch heads of a repo.
|
|
|
|
|
|
|
|
The cache is serialized on disk in the following format:
|
|
|
|
|
|
|
|
<tip hex node> <tip rev number> [optional filtered repo hex hash]
|
2013-09-16 12:08:29 +04:00
|
|
|
<branch head hex node> <open/closed state> <branch name>
|
|
|
|
<branch head hex node> <open/closed state> <branch name>
|
2013-11-16 08:18:08 +04:00
|
|
|
...
|
|
|
|
|
|
|
|
The first line is used to check if the cache is still valid. If the
|
|
|
|
branch cache is for a filtered repo view, an optional third hash is
|
|
|
|
included that hashes the hashes of all filtered revisions.
|
2013-09-16 12:08:29 +04:00
|
|
|
|
|
|
|
The open/closed state is represented by a single letter 'o' or 'c'.
|
|
|
|
This field can be used to avoid changelog reads when determining if a
|
|
|
|
branch head closes a branch or not.
|
2013-11-16 08:18:08 +04:00
|
|
|
"""
|
2012-12-22 04:44:42 +04:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
entries=(),
|
|
|
|
tipnode=nullid,
|
|
|
|
tiprev=nullrev,
|
|
|
|
filteredhash=None,
|
|
|
|
closednodes=None,
|
|
|
|
):
|
2012-12-22 04:59:05 +04:00
|
|
|
super(branchcache, self).__init__(entries)
|
|
|
|
self.tipnode = tipnode
|
2012-12-22 05:06:26 +04:00
|
|
|
self.tiprev = tiprev
|
2013-01-01 04:11:18 +04:00
|
|
|
self.filteredhash = filteredhash
|
2013-09-16 12:08:29 +04:00
|
|
|
# closednodes is a set of nodes that close their branch. If the branch
|
|
|
|
# cache has been updated, it may contain nodes that are no longer
|
|
|
|
# heads.
|
|
|
|
if closednodes is None:
|
|
|
|
self._closednodes = set()
|
|
|
|
else:
|
|
|
|
self._closednodes = closednodes
|
2013-01-01 04:11:18 +04:00
|
|
|
|
2012-12-24 05:49:59 +04:00
|
|
|
def validfor(self, repo):
|
2013-02-10 21:24:29 +04:00
|
|
|
"""Is the cache content valid regarding a repo
|
2012-12-24 05:49:59 +04:00
|
|
|
|
2013-02-10 21:24:29 +04:00
|
|
|
- False when cached tipnode is unknown or if we detect a strip.
|
2012-12-24 05:49:59 +04:00
|
|
|
- True when cache is up to date or a subset of current repo."""
|
|
|
|
try:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return (self.tipnode == repo.changelog.node(self.tiprev)) and (
|
|
|
|
self.filteredhash == scmutil.filteredhash(repo, self.tiprev)
|
|
|
|
)
|
2012-12-24 05:49:59 +04:00
|
|
|
except IndexError:
|
|
|
|
return False
|
|
|
|
|
2013-09-16 12:08:29 +04:00
|
|
|
def _branchtip(self, heads):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"""Return tuple with last open head in heads and false,
|
|
|
|
otherwise return last closed head and true."""
|
2013-09-16 12:08:29 +04:00
|
|
|
tip = heads[-1]
|
|
|
|
closed = True
|
|
|
|
for h in reversed(heads):
|
|
|
|
if h not in self._closednodes:
|
|
|
|
tip = h
|
|
|
|
closed = False
|
|
|
|
break
|
|
|
|
return tip, closed
|
|
|
|
|
|
|
|
def branchtip(self, branch):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"""Return the tipmost open head on branch head, otherwise return the
|
2013-11-22 00:17:18 +04:00
|
|
|
tipmost closed head on branch.
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
Raise KeyError for unknown branch."""
|
2013-09-16 12:08:29 +04:00
|
|
|
return self._branchtip(self[branch])[0]
|
|
|
|
|
2017-08-31 18:24:08 +03:00
|
|
|
def iteropen(self, nodes):
|
|
|
|
return (n for n in nodes if n not in self._closednodes)
|
|
|
|
|
2013-09-16 12:08:29 +04:00
|
|
|
def branchheads(self, branch, closed=False):
|
|
|
|
heads = self[branch]
|
|
|
|
if not closed:
|
2017-08-31 18:24:08 +03:00
|
|
|
heads = list(self.iteropen(heads))
|
2013-09-16 12:08:29 +04:00
|
|
|
return heads
|
|
|
|
|
2013-09-16 12:08:29 +04:00
|
|
|
def iterbranches(self):
|
|
|
|
for bn, heads in self.iteritems():
|
|
|
|
yield (bn, heads) + self._branchtip(heads)
|
|
|
|
|
2013-01-02 04:40:42 +04:00
|
|
|
def copy(self):
|
|
|
|
"""return an deep copy of the branchcache object"""
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return branchcache(
|
|
|
|
self, self.tipnode, self.tiprev, self.filteredhash, self._closednodes
|
|
|
|
)
|
2012-12-24 05:49:59 +04:00
|
|
|
|
2013-01-08 04:28:39 +04:00
|
|
|
def update(self, repo, revgen):
|
2012-12-22 20:08:15 +04:00
|
|
|
"""Given a branchhead cache, self, that may have extra nodes or be
|
2014-01-07 02:26:49 +04:00
|
|
|
missing heads, and a generator of nodes that are strictly a superset of
|
2012-12-22 20:08:15 +04:00
|
|
|
heads missing, this function updates self to be correct.
|
|
|
|
"""
|
2018-10-18 17:22:17 +03:00
|
|
|
# Behave differently if the cache is disabled.
|
2019-02-23 07:58:37 +03:00
|
|
|
cl = repo.changelog
|
|
|
|
tonode = cl.node
|
|
|
|
|
|
|
|
if self.tiprev == len(cl) - 1 and self.validfor(repo):
|
2018-10-18 17:22:17 +03:00
|
|
|
return
|
|
|
|
|
2019-02-23 07:58:37 +03:00
|
|
|
# Since we have no branches, the default branch heads are equal to
|
|
|
|
# cl.headrevs(). Note: cl.headrevs() is already sorted and it may return
|
|
|
|
# -1.
|
|
|
|
branchheads = [i for i in cl.headrevs() if i >= 0]
|
2014-03-23 04:14:37 +04:00
|
|
|
|
2019-02-23 07:58:37 +03:00
|
|
|
if not branchheads:
|
|
|
|
if "default" in self:
|
|
|
|
del self["default"]
|
|
|
|
tiprev = -1
|
|
|
|
else:
|
|
|
|
self["default"] = [tonode(rev) for rev in branchheads]
|
|
|
|
tiprev = branchheads[-1]
|
|
|
|
self.tipnode = cl.node(tiprev)
|
|
|
|
self.tiprev = tiprev
|
|
|
|
self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
repo.ui.log(
|
2019-02-23 07:58:37 +03:00
|
|
|
"branchcache", "perftweaks updated %s branch cache\n", repo.filtername
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|