2019-11-01 22:33:28 +03:00
|
|
|
# Portions Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
# drawdag.py - convert ASCII revision DAG to actual changesets
|
|
|
|
#
|
2019-11-01 22:33:28 +03:00
|
|
|
# Copyright Matt Mackall <mpm@selenic.com> and others
|
2016-11-09 19:01:34 +03:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
"""
|
|
|
|
create changesets from an ASCII graph for testing purpose.
|
|
|
|
|
|
|
|
For example, given the following input::
|
|
|
|
|
|
|
|
c d
|
|
|
|
|/
|
|
|
|
b
|
|
|
|
|
|
|
|
|
a
|
|
|
|
|
|
|
|
4 changesets and 4 local tags will be created.
|
|
|
|
`hg log -G -T "{rev} {desc} (tag: {tags})"` will output::
|
|
|
|
|
|
|
|
o 3 d (tag: d tip)
|
|
|
|
|
|
|
|
|
| o 2 c (tag: c)
|
|
|
|
|/
|
|
|
|
o 1 b (tag: b)
|
|
|
|
|
|
|
|
|
o 0 a (tag: a)
|
|
|
|
|
|
|
|
For root nodes (nodes without parents) in the graph, they can be revsets
|
|
|
|
pointing to existing nodes. The ASCII graph could also have disconnected
|
|
|
|
components with same names referring to the same changeset.
|
|
|
|
|
|
|
|
Therefore, given the repo having the 4 changesets (and tags) above, with the
|
|
|
|
following ASCII graph as input::
|
|
|
|
|
|
|
|
foo bar bar foo
|
|
|
|
| / | |
|
|
|
|
ancestor(c,d) a baz
|
|
|
|
|
|
|
|
The result (`hg log -G -T "{desc}"`) will look like::
|
|
|
|
|
|
|
|
o foo
|
|
|
|
|\
|
|
|
|
+---o bar
|
|
|
|
| | |
|
|
|
|
| o | baz
|
|
|
|
| /
|
|
|
|
+---o d
|
|
|
|
| |
|
|
|
|
+---o c
|
|
|
|
| |
|
|
|
|
o | b
|
|
|
|
|/
|
|
|
|
o a
|
|
|
|
|
|
|
|
Note that if you take the above `hg log` output directly as input. It will work
|
|
|
|
as expected - the result would be an isomorphic graph::
|
|
|
|
|
|
|
|
o foo
|
|
|
|
|\
|
|
|
|
| | o d
|
|
|
|
| |/
|
|
|
|
| | o c
|
|
|
|
| |/
|
|
|
|
| | o bar
|
|
|
|
| |/|
|
|
|
|
| o | b
|
|
|
|
| |/
|
|
|
|
o / baz
|
|
|
|
/
|
|
|
|
o a
|
|
|
|
|
|
|
|
This is because 'o' is specially handled in the input: instead of using 'o' as
|
|
|
|
the node name, the word to the right will be used.
|
2017-06-27 10:01:17 +03:00
|
|
|
|
|
|
|
Some special comments could have side effects:
|
|
|
|
|
|
|
|
- Create obsmarkers
|
|
|
|
# replace: A -> B -> C -> D # chained 1 to 1 replacements
|
|
|
|
# split: A -> B, C # 1 to many
|
|
|
|
# prune: A, B, C # many to nothing
|
2016-11-09 19:01:34 +03:00
|
|
|
"""
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import itertools
|
2017-08-14 17:02:38 +03:00
|
|
|
import re
|
2016-11-09 19:01:34 +03:00
|
|
|
|
2018-12-13 21:41:53 +03:00
|
|
|
from . import (
|
2019-12-17 05:10:38 +03:00
|
|
|
bookmarks,
|
2018-12-13 21:41:53 +03:00
|
|
|
context,
|
|
|
|
error,
|
|
|
|
mutation,
|
|
|
|
node,
|
|
|
|
obsolete,
|
|
|
|
pycompat,
|
|
|
|
scmutil,
|
2019-03-08 14:01:10 +03:00
|
|
|
visibility,
|
2018-12-13 21:41:53 +03:00
|
|
|
)
|
2018-01-30 04:19:34 +03:00
|
|
|
from .i18n import _
|
2019-12-17 05:10:38 +03:00
|
|
|
from .node import hex
|
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
|
|
|
|
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
_pipechars = "\\/+-|"
|
|
|
|
_nonpipechars = "".join(
|
|
|
|
chr(i) for i in range(33, 127) if pycompat.bytechr(i) not in _pipechars
|
2016-11-09 19:01:34 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _isname(ch):
|
|
|
|
"""char -> bool. return True if ch looks like part of a name, False
|
|
|
|
otherwise"""
|
|
|
|
return ch in _nonpipechars
|
|
|
|
|
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
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
def _parseasciigraph(text):
|
2017-08-23 17:51:26 +03:00
|
|
|
r"""str -> {str : [str]}. convert the ASCII graph to edges
|
|
|
|
|
|
|
|
>>> import pprint
|
2017-08-23 08:23:16 +03:00
|
|
|
>>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
|
2020-01-28 21:21:58 +03:00
|
|
|
... for k, v in _parseasciigraph(r'''
|
2017-08-23 17:51:26 +03:00
|
|
|
... G
|
|
|
|
... |
|
|
|
|
... I D C F # split: B -> E, F, G
|
|
|
|
... \ \| | # replace: C -> D -> H
|
|
|
|
... H B E # prune: F, I
|
|
|
|
... \|/
|
|
|
|
... A
|
|
|
|
... ''').items()})
|
|
|
|
{'A': [],
|
|
|
|
'B': ['A'],
|
|
|
|
'C': ['B'],
|
|
|
|
'D': ['B'],
|
|
|
|
'E': ['A'],
|
|
|
|
'F': ['E'],
|
|
|
|
'G': ['F'],
|
|
|
|
'H': ['A'],
|
|
|
|
'I': ['H']}
|
2017-08-23 08:23:16 +03:00
|
|
|
>>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
|
2020-01-28 21:21:58 +03:00
|
|
|
... for k, v in _parseasciigraph(r'''
|
2017-08-23 17:51:26 +03:00
|
|
|
... o foo
|
|
|
|
... |\
|
|
|
|
... +---o bar
|
|
|
|
... | | |
|
|
|
|
... | o | baz
|
|
|
|
... | /
|
|
|
|
... +---o d
|
|
|
|
... | |
|
|
|
|
... +---o c
|
|
|
|
... | |
|
|
|
|
... o | b
|
|
|
|
... |/
|
|
|
|
... o a
|
|
|
|
... ''').items()})
|
|
|
|
{'a': [],
|
|
|
|
'b': ['a'],
|
|
|
|
'bar': ['b', 'a'],
|
|
|
|
'baz': [],
|
|
|
|
'c': ['b'],
|
|
|
|
'd': ['b'],
|
|
|
|
'foo': ['baz', 'b']}
|
|
|
|
"""
|
2016-11-09 19:01:34 +03:00
|
|
|
lines = text.splitlines()
|
|
|
|
edges = collections.defaultdict(list) # {node: []}
|
|
|
|
|
|
|
|
def get(y, x):
|
|
|
|
"""(int, int) -> char. give a coordinate, return the char. return a
|
|
|
|
space for anything out of range"""
|
|
|
|
if x < 0 or y < 0:
|
2020-01-28 21:21:58 +03:00
|
|
|
return " "
|
2016-11-09 19:01:34 +03:00
|
|
|
try:
|
2020-01-28 21:21:58 +03:00
|
|
|
return lines[y][x : x + 1] or " "
|
2016-11-09 19:01:34 +03:00
|
|
|
except IndexError:
|
2020-01-28 21:21:58 +03:00
|
|
|
return " "
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
def getname(y, x):
|
|
|
|
"""(int, int) -> str. like get(y, x) but concatenate left and right
|
|
|
|
parts. if name is an 'o', try to replace it to the right"""
|
2020-01-28 21:21:58 +03:00
|
|
|
result = ""
|
2016-11-09 19:01:34 +03:00
|
|
|
for i in itertools.count(0):
|
|
|
|
ch = get(y, x - i)
|
|
|
|
if not _isname(ch):
|
|
|
|
break
|
|
|
|
result = ch + result
|
|
|
|
for i in itertools.count(1):
|
|
|
|
ch = get(y, x + i)
|
|
|
|
if not _isname(ch):
|
|
|
|
break
|
|
|
|
result += ch
|
2020-01-28 21:21:58 +03:00
|
|
|
if result == "o":
|
2016-11-09 19:01:34 +03:00
|
|
|
# special handling, find the name to the right
|
2020-01-28 21:21:58 +03:00
|
|
|
result = ""
|
2016-11-09 19:01:34 +03:00
|
|
|
for i in itertools.count(2):
|
|
|
|
ch = get(y, x + i)
|
2020-01-28 21:21:58 +03:00
|
|
|
if ch == " " or ch in _pipechars:
|
2016-11-09 19:01:34 +03:00
|
|
|
if result or x + i >= len(lines[y]):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
result += ch
|
2020-01-28 21:21:58 +03:00
|
|
|
return result or "o"
|
2016-11-09 19:01:34 +03:00
|
|
|
return result
|
|
|
|
|
|
|
|
def parents(y, x):
|
|
|
|
"""(int, int) -> [str]. follow the ASCII edges at given position,
|
|
|
|
return a list of parents"""
|
2017-02-11 03:56:29 +03:00
|
|
|
visited = {(y, x)}
|
2016-11-09 19:01:34 +03:00
|
|
|
visit = []
|
|
|
|
result = []
|
|
|
|
|
|
|
|
def follow(y, x, expected):
|
|
|
|
"""conditionally append (y, x) to visit array, if it's a char
|
|
|
|
in excepted. 'o' in expected means an '_isname' test.
|
|
|
|
if '-' (or '+') is not in excepted, and get(y, x) is '-' (or '+'),
|
|
|
|
the next line (y + 1, x) will be checked instead."""
|
|
|
|
ch = get(y, x)
|
2020-01-28 21:21:58 +03:00
|
|
|
if any(ch == c and c not in expected for c in ("-", "+")):
|
2016-11-09 19:01:34 +03:00
|
|
|
y += 1
|
|
|
|
return follow(y + 1, x, expected)
|
2020-01-28 21:21:58 +03:00
|
|
|
if ch in expected or ("o" in expected and _isname(ch)):
|
2016-11-09 19:01:34 +03:00
|
|
|
visit.append((y, x))
|
|
|
|
|
|
|
|
# -o- # starting point:
|
|
|
|
# /|\ # follow '-' (horizontally), and '/|\' (to the bottom)
|
2020-01-28 21:21:58 +03:00
|
|
|
follow(y + 1, x, "|")
|
|
|
|
follow(y + 1, x - 1, "/")
|
|
|
|
follow(y + 1, x + 1, "\\")
|
|
|
|
follow(y, x - 1, "-")
|
|
|
|
follow(y, x + 1, "-")
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
while visit:
|
|
|
|
y, x = visit.pop()
|
|
|
|
if (y, x) in visited:
|
|
|
|
continue
|
|
|
|
visited.add((y, x))
|
|
|
|
ch = get(y, x)
|
|
|
|
if _isname(ch):
|
|
|
|
result.append(getname(y, x))
|
|
|
|
continue
|
2020-01-28 21:21:58 +03:00
|
|
|
elif ch == "|":
|
|
|
|
follow(y + 1, x, "/|o")
|
|
|
|
follow(y + 1, x - 1, "/")
|
|
|
|
follow(y + 1, x + 1, "\\")
|
|
|
|
elif ch == "+":
|
|
|
|
follow(y, x - 1, "-")
|
|
|
|
follow(y, x + 1, "-")
|
|
|
|
follow(y + 1, x - 1, "/")
|
|
|
|
follow(y + 1, x + 1, "\\")
|
|
|
|
follow(y + 1, x, "|")
|
|
|
|
elif ch == "\\":
|
|
|
|
follow(y + 1, x + 1, "\\|o")
|
|
|
|
elif ch == "/":
|
|
|
|
follow(y + 1, x - 1, "/|o")
|
|
|
|
elif ch == "-":
|
|
|
|
follow(y, x - 1, "-+o")
|
|
|
|
follow(y, x + 1, "-+o")
|
2016-11-09 19:01:34 +03:00
|
|
|
return result
|
|
|
|
|
|
|
|
for y, line in enumerate(lines):
|
2017-08-23 08:23:16 +03:00
|
|
|
for x, ch in enumerate(pycompat.bytestr(line)):
|
2020-01-28 21:21:58 +03:00
|
|
|
if ch == "#": # comment
|
2016-11-09 19:01:34 +03:00
|
|
|
break
|
|
|
|
if _isname(ch):
|
|
|
|
edges[getname(y, x)] += parents(y, x)
|
|
|
|
|
|
|
|
return dict(edges)
|
|
|
|
|
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
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
class simplefilectx(object):
|
2018-02-07 01:18:18 +03:00
|
|
|
def __init__(self, path, data, renamed=None):
|
2016-11-09 19:01:34 +03:00
|
|
|
self._data = data
|
|
|
|
self._path = path
|
2018-02-07 01:18:18 +03:00
|
|
|
self._renamed = renamed
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
def data(self):
|
|
|
|
return self._data
|
|
|
|
|
2017-05-17 20:48:56 +03:00
|
|
|
def filenode(self):
|
|
|
|
return None
|
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
def path(self):
|
|
|
|
return self._path
|
|
|
|
|
|
|
|
def renamed(self):
|
2018-02-07 01:18:18 +03:00
|
|
|
if self._renamed:
|
|
|
|
return (self._renamed, node.nullid)
|
2016-11-09 19:01:34 +03:00
|
|
|
return None
|
|
|
|
|
|
|
|
def flags(self):
|
2020-01-28 21:21:58 +03:00
|
|
|
return ""
|
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
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
class simplecommitctx(context.committablectx):
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
def __init__(self, repo, name, parentctxs, filemap, mutationspec, date):
|
2018-06-29 21:19:56 +03:00
|
|
|
added = []
|
|
|
|
removed = []
|
|
|
|
for path, data in filemap.items():
|
|
|
|
# check "(renamed from)". mark the source as removed
|
|
|
|
m = re.search("\(renamed from (.+)\)\s*\Z", data, re.S)
|
|
|
|
if m:
|
|
|
|
removed.append(m.group(1))
|
|
|
|
# check "(removed)"
|
|
|
|
if re.match("\A\s*\(removed\)\s*\Z", data, re.S):
|
|
|
|
removed.append(path)
|
|
|
|
else:
|
|
|
|
if path in removed:
|
|
|
|
raise error.Abort(_("%s: both added and removed") % path)
|
|
|
|
added.append(path)
|
2020-01-28 21:21:58 +03:00
|
|
|
extra = {"branch": "default"}
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
mutinfo = None
|
|
|
|
if mutationspec is not None:
|
|
|
|
predctxs, cmd, split = mutationspec
|
|
|
|
mutinfo = {
|
|
|
|
"mutpred": ",".join(
|
|
|
|
[mutation.identfromnode(p.node()) for p in predctxs]
|
|
|
|
),
|
|
|
|
"mutdate": date,
|
|
|
|
"mutuser": repo.ui.config("mutation", "user") or repo.ui.username(),
|
|
|
|
"mutop": cmd,
|
|
|
|
}
|
2018-12-13 21:41:53 +03:00
|
|
|
if split:
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
mutinfo["mutsplit"] = ",".join(
|
2019-03-27 14:45:35 +03:00
|
|
|
[mutation.identfromnode(s.node()) for s in split]
|
|
|
|
)
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
if mutation.recording(repo):
|
|
|
|
extra.update(mutinfo)
|
2016-11-09 19:01:34 +03:00
|
|
|
opts = {
|
2018-06-29 21:19:56 +03:00
|
|
|
"changes": scmutil.status([], added, removed, [], [], [], []),
|
2019-03-09 07:14:40 +03:00
|
|
|
"date": date,
|
2018-12-13 21:41:53 +03:00
|
|
|
"extra": extra,
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
"mutinfo": mutinfo,
|
2016-11-09 19:01:34 +03:00
|
|
|
}
|
|
|
|
super(simplecommitctx, self).__init__(self, name, **opts)
|
|
|
|
self._repo = repo
|
2018-06-29 21:19:56 +03:00
|
|
|
self._filemap = filemap
|
2016-11-09 19:01:34 +03:00
|
|
|
self._parents = parentctxs
|
|
|
|
while len(self._parents) < 2:
|
|
|
|
self._parents.append(repo[node.nullid])
|
|
|
|
|
|
|
|
def filectx(self, key):
|
2018-06-29 21:19:56 +03:00
|
|
|
data = self._filemap[key]
|
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
|
|
|
m = re.match("\A(.*) \((?:renamed|copied) from (.+)\)\s*\Z", data, re.S)
|
2018-02-07 01:18:18 +03:00
|
|
|
if m:
|
|
|
|
data = m.group(1)
|
|
|
|
renamed = m.group(2)
|
|
|
|
else:
|
|
|
|
renamed = None
|
|
|
|
return simplefilectx(key, data, renamed)
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
def commit(self):
|
|
|
|
return self._repo.commitctx(self)
|
|
|
|
|
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
|
|
|
|
2018-12-13 21:41:53 +03:00
|
|
|
def _walkgraph(edges, extraedges):
|
|
|
|
"""yield node, parents in topologically order
|
|
|
|
|
|
|
|
``edges`` is a dict containing a mapping of each node to its parent nodes.
|
|
|
|
|
|
|
|
``extraedges`` is a dict containing other constraints on the ordering, e.g.
|
|
|
|
if commit B was created by amending commit A, then this dict should have B
|
|
|
|
-> A to ensure A is created before B.
|
|
|
|
"""
|
2016-11-09 19:01:34 +03:00
|
|
|
visible = set(edges.keys())
|
|
|
|
remaining = {} # {str: [str]}
|
2017-08-23 08:23:16 +03:00
|
|
|
for k, vs in edges.items():
|
2018-12-13 21:41:53 +03:00
|
|
|
vs = vs[:]
|
|
|
|
if k in extraedges:
|
2018-12-13 21:41:53 +03:00
|
|
|
vs.extend(list(extraedges[k]))
|
2016-11-09 19:01:34 +03:00
|
|
|
for v in vs:
|
|
|
|
if v not in remaining:
|
|
|
|
remaining[v] = []
|
2018-12-13 21:41:53 +03:00
|
|
|
remaining[k] = vs
|
2016-11-09 19:01:34 +03:00
|
|
|
while remaining:
|
|
|
|
leafs = [k for k, v in remaining.items() if not v]
|
|
|
|
if not leafs:
|
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 error.Abort(_("the graph has cycles"))
|
2016-11-09 19:01:34 +03:00
|
|
|
for leaf in sorted(leafs):
|
|
|
|
if leaf in visible:
|
|
|
|
yield leaf, edges[leaf]
|
|
|
|
del remaining[leaf]
|
2017-08-23 08:23:16 +03:00
|
|
|
for k, v in remaining.items():
|
2016-11-09 19:01:34 +03:00
|
|
|
if leaf in v:
|
|
|
|
v.remove(leaf)
|
|
|
|
|
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
|
|
|
|
2017-08-14 17:02:38 +03:00
|
|
|
def _getcomments(text):
|
2017-08-23 17:51:26 +03:00
|
|
|
"""
|
2017-08-23 08:23:16 +03:00
|
|
|
>>> [pycompat.sysstr(s) for s in _getcomments(br'''
|
2017-08-23 17:51:26 +03:00
|
|
|
... G
|
|
|
|
... |
|
|
|
|
... I D C F # split: B -> E, F, G
|
|
|
|
... \ \| | # replace: C -> D -> H
|
|
|
|
... H B E # prune: F, I
|
|
|
|
... \|/
|
|
|
|
... A
|
|
|
|
... ''')]
|
|
|
|
['split: B -> E, F, G', 'replace: C -> D -> H', 'prune: F, I']
|
|
|
|
"""
|
2017-08-14 17:02:38 +03:00
|
|
|
for line in text.splitlines():
|
2020-01-28 21:21:58 +03:00
|
|
|
if " # " not in line:
|
2017-08-14 17:02:38 +03:00
|
|
|
continue
|
2020-01-28 21:21:58 +03:00
|
|
|
yield line.split(" # ", 1)[1].split(" # ")[0].strip()
|
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
|
|
|
|
2017-08-14 17:02:38 +03:00
|
|
|
|
2018-12-13 21:41:53 +03:00
|
|
|
def drawdag(repo, text, **opts):
|
2018-01-30 04:19:34 +03:00
|
|
|
"""given an ASCII graph as text, create changesets in repo.
|
2016-11-09 19:01:34 +03:00
|
|
|
|
|
|
|
The ASCII graph is like what :hg:`log -G` outputs, with each `o` replaced
|
|
|
|
to the name of the node. The command will create dummy changesets and local
|
|
|
|
tags with those names to make the dummy changesets easier to be referred
|
|
|
|
to.
|
|
|
|
|
|
|
|
If the name of a node is a single character 'o', It will be replaced by the
|
|
|
|
word to the right. This makes it easier to reuse
|
|
|
|
:hg:`log -G -T '{desc}'` outputs.
|
|
|
|
|
|
|
|
For root (no parents) nodes, revset can be used to query existing repo.
|
|
|
|
Note that the revset cannot have confusing characters which can be seen as
|
|
|
|
the part of the graph edges, like `|/+-\`.
|
|
|
|
"""
|
|
|
|
# parse the graph and make sure len(parents) <= 2 for each node
|
|
|
|
edges = _parseasciigraph(text)
|
2017-08-23 08:23:16 +03:00
|
|
|
for k, v in edges.items():
|
2016-11-09 19:01:34 +03:00
|
|
|
if len(v) > 2:
|
2020-01-28 21:21:58 +03:00
|
|
|
raise error.Abort(_("%s: too many parents: %s") % (k, " ".join(v)))
|
2016-11-09 19:01:34 +03:00
|
|
|
|
2017-08-14 17:02:38 +03:00
|
|
|
# parse comments to get extra file content instructions
|
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
|
|
|
files = collections.defaultdict(dict) # {(name, path): content}
|
2017-08-14 17:02:38 +03:00
|
|
|
comments = list(_getcomments(text))
|
2020-01-28 21:21:58 +03:00
|
|
|
filere = re.compile(r"^(\w+)/([\w/]+)\s*=\s*(.*)$", re.M)
|
|
|
|
for name, path, content in filere.findall("\n".join(comments)):
|
|
|
|
content = content.replace(r"\n", "\n").replace(r"\1", "\1")
|
2018-02-07 01:18:18 +03:00
|
|
|
files[name][path] = content
|
2017-08-14 17:02:38 +03:00
|
|
|
|
2019-03-09 07:14:40 +03:00
|
|
|
# parse commits like "X: date=1 0" to specify dates
|
|
|
|
dates = {}
|
2020-01-28 21:21:58 +03:00
|
|
|
datere = re.compile(r"^(\w+) has date\s*[= ]([0-9 ]+)$", re.M)
|
|
|
|
for name, date in datere.findall("\n".join(comments)):
|
2019-03-09 07:14:40 +03:00
|
|
|
dates[name] = date
|
|
|
|
|
2018-12-21 04:48:28 +03:00
|
|
|
# do not create default files? (ex. commit A has file "A")
|
|
|
|
defaultfiles = not any("drawdag.defaultfiles=false" in c for c in comments)
|
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
committed = {None: node.nullid} # {name: node}
|
|
|
|
|
|
|
|
# for leaf nodes, try to find existing nodes in repo
|
2017-08-23 08:23:16 +03:00
|
|
|
for name, parents in edges.items():
|
2016-11-09 19:01:34 +03:00
|
|
|
if len(parents) == 0:
|
|
|
|
try:
|
2018-12-13 21:41:53 +03:00
|
|
|
committed[name] = scmutil.revsingle(repo, name).node()
|
2016-11-09 19:01:34 +03:00
|
|
|
except error.RepoLookupError:
|
|
|
|
pass
|
|
|
|
|
2018-12-13 21:41:53 +03:00
|
|
|
# parse special comments
|
|
|
|
obsmarkers = []
|
|
|
|
mutations = {}
|
|
|
|
for comment in comments:
|
|
|
|
rels = [] # obsolete relationships
|
2020-01-28 21:21:58 +03:00
|
|
|
args = comment.split(":", 1)
|
2018-12-13 21:41:53 +03:00
|
|
|
if len(args) <= 1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
cmd = args[0].strip()
|
|
|
|
arg = args[1].strip()
|
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
if cmd in ("replace", "rebase", "amend"):
|
|
|
|
nodes = [n.strip() for n in arg.split("->")]
|
2018-12-13 21:41:53 +03:00
|
|
|
for i in range(len(nodes) - 1):
|
|
|
|
pred, succ = nodes[i], nodes[i + 1]
|
|
|
|
rels.append((pred, (succ,)))
|
|
|
|
if succ in mutations:
|
|
|
|
raise error.Abort(
|
|
|
|
_("%s: multiple mutations: from %s and %s")
|
|
|
|
% (succ, pred, mutations[succ][0])
|
|
|
|
)
|
2018-12-13 21:41:53 +03:00
|
|
|
mutations[succ] = ([pred], cmd, None)
|
2020-01-28 21:21:58 +03:00
|
|
|
elif cmd in ("split",):
|
|
|
|
pred, succs = arg.split("->")
|
2018-12-13 21:41:53 +03:00
|
|
|
pred = pred.strip()
|
2020-01-28 21:21:58 +03:00
|
|
|
succs = [s.strip() for s in succs.split(",")]
|
2018-12-13 21:41:53 +03:00
|
|
|
rels.append((pred, succs))
|
|
|
|
for succ in succs:
|
|
|
|
if succ in mutations:
|
|
|
|
raise error.Abort(
|
|
|
|
_("%s: multiple mutations: from %s and %s")
|
|
|
|
% (succ, pred, mutations[succ][0])
|
|
|
|
)
|
|
|
|
for i in range(len(succs) - 1):
|
|
|
|
parent = succs[i]
|
|
|
|
child = succs[i + 1]
|
|
|
|
if child not in edges or parent not in edges[child]:
|
|
|
|
raise error.Abort(
|
|
|
|
_("%s: split targets must be a stack: %s is not a parent of %s")
|
|
|
|
% (pred, parent, child)
|
|
|
|
)
|
2018-12-13 21:41:53 +03:00
|
|
|
mutations[succs[-1]] = ([pred], cmd, succs[:-1])
|
2020-01-28 21:21:58 +03:00
|
|
|
elif cmd in ("fold",):
|
|
|
|
preds, succ = arg.split("->")
|
|
|
|
preds = [p.strip() for p in preds.split(",")]
|
2018-12-13 21:41:53 +03:00
|
|
|
succ = succ.strip()
|
|
|
|
for pred in preds:
|
|
|
|
rels.append((pred, (succ,)))
|
|
|
|
if succ in mutations:
|
|
|
|
raise error.Abort(
|
|
|
|
_("%s: multiple mutations: from %s and %s")
|
|
|
|
% (succ, ", ".join(preds), mutations[succ][0])
|
|
|
|
)
|
|
|
|
for i in range(len(preds) - 1):
|
|
|
|
parent = preds[i]
|
|
|
|
child = preds[i + 1]
|
|
|
|
if child not in edges or parent not in edges[child]:
|
|
|
|
raise error.Abort(
|
|
|
|
_("%s: fold sources must be a stack: %s is not a parent of %s")
|
|
|
|
% (succ, parent, child)
|
|
|
|
)
|
|
|
|
mutations[succ] = (preds, cmd, None)
|
2020-01-28 21:21:58 +03:00
|
|
|
elif cmd in ("prune",):
|
|
|
|
for n in arg.split(","):
|
2018-12-13 21:41:53 +03:00
|
|
|
rels.append((n.strip(), ()))
|
2020-01-28 21:21:58 +03:00
|
|
|
elif cmd in ("revive",):
|
|
|
|
for n in arg.split(","):
|
2018-12-13 21:41:53 +03:00
|
|
|
rels.append((n.strip(), (n.strip(),)))
|
2018-12-13 21:41:53 +03:00
|
|
|
if rels:
|
|
|
|
obsmarkers.append((cmd, rels))
|
|
|
|
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
# Only record mutations if mutation is enabled.
|
2018-12-13 21:41:53 +03:00
|
|
|
mutationedges = {}
|
2019-12-17 05:10:38 +03:00
|
|
|
mutationpreds = set()
|
mutation: make the mutationstore the source of truth for mutation entries
Summary:
Previously the mutation commit extras were the source of truth for mutation
information, and the mutation store served as a kind of cache. This turned out
to be less useful than expected, as oftentimes commits are missing, and the
store is better indexed, so in practice using the store as the source of truth
is better.
This change makes the mutationstore the (sole) source of truth for mutation
data. The extras are kept, but they are now only useful as human-readable
debug information, and to ensure the commit hash is unique.
Collecting the mutation information during commit creation is now done through
a new `mutinfo` object. This is a dict with the same keys as the mutation
extras, for simplicity, but it is now passed through the `committablectx` and
used to generate the mutation store entry directly.
The `mutation.enabled` config option is now used to control all aspects of
enabling mutation.
The `mutation.record` config option is now only used to indicate whether the
mutation extras should also added to the commit. Generally this should be set
to `true`, however the option is retained so that mutation extras can be
stripped by running `hg amend --config mutation.record=false`, which no longer
has the side-effect of not recording mutation information to the store.
The "remote commit" mutation record origin is now obsolete, and won't be
generated anymore.
Pushrebase now relies on the obsmarker information coming back from the server
in order to correctly generate mutation information. We will need to change
this so that the server returns mutation records before we can fully deprecate
obsmarkers.
Reviewed By: DurhamG
Differential Revision: D19410650
fbshipit-source-id: 8d7094e4bfd8d8e97916898d899a8debd339485f
2020-01-16 12:01:10 +03:00
|
|
|
if mutation.enabled(repo):
|
2018-12-13 21:41:53 +03:00
|
|
|
# For mutation recording to work, we must include the mutations
|
|
|
|
# as extra edges when walking the DAG.
|
2018-12-13 21:41:53 +03:00
|
|
|
for succ, (preds, cmd, split) in mutations.items():
|
|
|
|
succs = {succ}
|
2019-12-17 05:10:38 +03:00
|
|
|
mutationpreds.update(preds)
|
2018-12-13 21:41:53 +03:00
|
|
|
if split:
|
|
|
|
succs.update(split)
|
|
|
|
for s in succs:
|
|
|
|
mutationedges.setdefault(s, set()).update(preds)
|
2018-12-13 21:41:53 +03:00
|
|
|
else:
|
|
|
|
mutationedges = {}
|
|
|
|
mutations = {}
|
|
|
|
|
2016-11-09 19:01:34 +03:00
|
|
|
# commit in topological order
|
2018-12-13 21:41:53 +03:00
|
|
|
for name, parents in _walkgraph(edges, mutationedges):
|
2016-11-09 19:01:34 +03:00
|
|
|
if name in committed:
|
|
|
|
continue
|
|
|
|
pctxs = [repo[committed[n]] for n in parents]
|
drawdag: include files from both parents in merge commits
Consider a graph like this:
D
|\
B C
|/
A
drawdag will add a file called A in commit A, file B in B, file C in
C. That's fine and expected. In merge commits like D, I would expect
the files and their contents to be taken from the parent commits, so
commit D in this example would have files A, B, and C. However,
drawdag will instead add the file D compared to the first
parent. Depending on whether B or C got a smaller nodeid, the contents
of D would be {A, B, D} or {A, C, D}. This patch changes it to to be
{A, B, C}.
Differential Revision: https://phab.mercurial-scm.org/D92
2017-07-15 08:32:58 +03:00
|
|
|
pctxs.sort(key=lambda c: c.node())
|
|
|
|
added = {}
|
|
|
|
if len(parents) > 1:
|
|
|
|
# If it's a merge, take the files and contents from the parents
|
|
|
|
for f in pctxs[1].manifest():
|
|
|
|
if f not in pctxs[0].manifest():
|
|
|
|
added[f] = pctxs[1][f].data()
|
|
|
|
else:
|
2018-12-21 04:48:28 +03:00
|
|
|
# If it's not a merge, add a single file, if defaultfiles is set
|
|
|
|
if defaultfiles:
|
|
|
|
added[name] = name
|
2017-08-14 17:02:38 +03:00
|
|
|
# add extra file contents in comments
|
|
|
|
for path, content in files.get(name, {}).items():
|
|
|
|
added[path] = content
|
2018-12-13 21:41:53 +03:00
|
|
|
commitmutations = None
|
|
|
|
if name in mutations:
|
2018-12-13 21:41:53 +03:00
|
|
|
preds, cmd, split = mutations[name]
|
2018-12-13 21:41:53 +03:00
|
|
|
if split is not None:
|
|
|
|
split = [repo[committed[s]] for s in split]
|
2018-12-13 21:41:53 +03:00
|
|
|
commitmutations = ([repo[committed[p]] for p in preds], cmd, split)
|
2018-12-13 21:41:53 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
date = dates.get(name, "0 0")
|
2019-03-09 07:14:40 +03:00
|
|
|
ctx = simplecommitctx(repo, name, pctxs, added, commitmutations, date)
|
2016-11-09 19:01:34 +03:00
|
|
|
n = ctx.commit()
|
|
|
|
committed[name] = n
|
2019-12-17 05:10:38 +03:00
|
|
|
if name not in mutationpreds:
|
|
|
|
with repo.wlock(), repo.lock(), repo.transaction("bookmark") as tr:
|
|
|
|
bookmarks.addbookmarks(repo, tr, [name], hex(n), True, True)
|
2017-06-27 10:01:17 +03:00
|
|
|
|
|
|
|
# handle special comments
|
2020-01-28 21:21:58 +03:00
|
|
|
with repo.wlock(), repo.lock(), repo.transaction("drawdag"):
|
2017-06-27 10:01:17 +03:00
|
|
|
getctx = lambda x: repo.unfiltered()[committed[x.strip()]]
|
2019-03-08 14:01:10 +03:00
|
|
|
if obsolete.isenabled(repo, obsolete.createmarkersopt):
|
|
|
|
for cmd, markers in obsmarkers:
|
|
|
|
obsrels = [(getctx(p), [getctx(s) for s in ss]) for p, ss in markers]
|
|
|
|
if obsrels:
|
|
|
|
obsolete.createmarkers(repo, obsrels, date=(0, 0), operation=cmd)
|
|
|
|
if visibility.tracking(repo):
|
|
|
|
hidenodes = set()
|
|
|
|
revivenodes = set()
|
|
|
|
for cmd, markers in obsmarkers:
|
|
|
|
for p, ss in markers:
|
|
|
|
if cmd == "revive":
|
|
|
|
revivenodes.add(getctx(p).node())
|
|
|
|
else:
|
|
|
|
hidenodes.add(getctx(p).node())
|
|
|
|
visibility.remove(repo, hidenodes - revivenodes)
|
2018-12-13 21:41:53 +03:00
|
|
|
|
|
|
|
if opts.get("print"):
|
|
|
|
for name, n in sorted(committed.items()):
|
|
|
|
if name:
|
|
|
|
repo.ui.write("%s %s\n" % (node.short(n), name))
|