author | Pierre-Yves David <pierre-yves.david@fb.com> |
Fri, 28 Mar 2014 17:00:13 -0700 | |
changeset 20863 | 876c17336b4e |
parent 20599 | dad29624b056 |
child 21024 | 7731a2281cf0 |
permissions | -rw-r--r-- |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
1 |
# obsolete.py - obsolete markers handling |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
2 |
# |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
3 |
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
4 |
# Logilab SA <contact@logilab.fr> |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
5 |
# |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
7 |
# GNU General Public License version 2 or any later version. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
8 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
9 |
"""Obsolete markers handling |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
10 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
11 |
An obsolete marker maps an old changeset to a list of new |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
12 |
changesets. If the list of new changesets is empty, the old changeset |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
13 |
is said to be "killed". Otherwise, the old changeset is being |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
14 |
"replaced" by the new changesets. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
15 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
16 |
Obsolete markers can be used to record and distribute changeset graph |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
17 |
transformations performed by history rewriting operations, and help |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
18 |
building new tools to reconciliate conflicting rewriting actions. To |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
19 |
facilitate conflicts resolution, markers include various annotations |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
20 |
besides old and news changeset identifiers, such as creation date or |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
21 |
author name. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
22 |
|
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
23 |
The old obsoleted changeset is called "precursor" and possible replacements are |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
24 |
called "successors". Markers that used changeset X as a precursors are called |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
25 |
"successor markers of X" because they hold information about the successors of |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
26 |
X. Markers that use changeset Y as a successors are call "precursor markers of |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
27 |
Y" because they hold information about the precursors of Y. |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
28 |
|
17775
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
29 |
Examples: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
30 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
31 |
- When changeset A is replacement by a changeset A', one marker is stored: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
32 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
33 |
(A, (A')) |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
34 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
35 |
- When changesets A and B are folded into a new changeset C two markers are |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
36 |
stored: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
37 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
38 |
(A, (C,)) and (B, (C,)) |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
39 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
40 |
- When changeset A is simply "pruned" from the graph, a marker in create: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
41 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
42 |
(A, ()) |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
43 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
44 |
- When changeset A is split into B and C, a single marker are used: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
45 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
46 |
(A, (C, C)) |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
47 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
48 |
We use a single marker to distinct the "split" case from the "divergence" |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
49 |
case. If two independents operation rewrite the same changeset A in to A' and |
17775
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
50 |
A'' when have an error case: divergent rewriting. We can detect it because |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
51 |
two markers will be created independently: |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
52 |
|
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
53 |
(A, (B,)) and (A, (C,)) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
54 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
55 |
Format |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
56 |
------ |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
57 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
58 |
Markers are stored in an append-only file stored in |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
59 |
'.hg/store/obsstore'. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
60 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
61 |
The file starts with a version header: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
62 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
63 |
- 1 unsigned byte: version number, starting at zero. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
64 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
65 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
66 |
The header is followed by the markers. Each marker is made of: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
67 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
68 |
- 1 unsigned byte: number of new changesets "R", could be zero. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
69 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
70 |
- 1 unsigned 32-bits integer: metadata size "M" in bytes. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
71 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
72 |
- 1 byte: a bit field. It is reserved for flags used in obsolete |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
73 |
markers common operations, to avoid repeated decoding of metadata |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
74 |
entries. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
75 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
76 |
- 20 bytes: obsoleted changeset identifier. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
77 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
78 |
- N*20 bytes: new changesets identifiers. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
79 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
80 |
- M bytes: metadata as a sequence of nul-terminated strings. Each |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
81 |
string contains a key and a value, separated by a color ':', without |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
82 |
additional encoding. Keys cannot contain '\0' or ':' and values |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
83 |
cannot contain '\0'. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
84 |
""" |
17200
19f5dec2d61f
obsolete: os.SEEK_END first appeared in Python 2.5
Adrian Buehlmann <adrian@cadifra.com>
parents:
17195
diff
changeset
|
85 |
import struct |
17774
0496d4f73cf4
obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17537
diff
changeset
|
86 |
import util, base85, node |
20207
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
87 |
import phases |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
88 |
from i18n import _ |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
89 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
90 |
_pack = struct.pack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
91 |
_unpack = struct.unpack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
92 |
|
17429
72fa4ef2245f
declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
93 |
_SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5 |
72fa4ef2245f
declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
94 |
|
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17405
diff
changeset
|
95 |
# the obsolete feature is not mature enough to be enabled by default. |
17296
a1f8869f2eee
obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17295
diff
changeset
|
96 |
# you have to rely on third party extension extension to enable this. |
a1f8869f2eee
obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17295
diff
changeset
|
97 |
_enabled = False |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
98 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
99 |
# data used for parsing and writing |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
100 |
_fmversion = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
101 |
_fmfixed = '>BIB20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
102 |
_fmnode = '20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
103 |
_fmfsize = struct.calcsize(_fmfixed) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
104 |
_fnodesize = struct.calcsize(_fmnode) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
105 |
|
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
106 |
### obsolescence marker flag |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
107 |
|
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
108 |
## bumpedfix flag |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
109 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
110 |
# When a changeset A' succeed to a changeset A which became public, we call A' |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
111 |
# "bumped" because it's a successors of a public changesets |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
112 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
113 |
# o A' (bumped) |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
114 |
# |`: |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
115 |
# | o A |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
116 |
# |/ |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
117 |
# o Z |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
118 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
119 |
# The way to solve this situation is to create a new changeset Ad as children |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
120 |
# of A. This changeset have the same content than A'. So the diff from A to A' |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
121 |
# is the same than the diff from A to Ad. Ad is marked as a successors of A' |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
122 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
123 |
# o Ad |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
124 |
# |`: |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
125 |
# | x A' |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
126 |
# |'| |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
127 |
# o | A |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
128 |
# |/ |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
129 |
# o Z |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
130 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
131 |
# But by transitivity Ad is also a successors of A. To avoid having Ad marked |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
132 |
# as bumped too, we add the `bumpedfix` flag to the marker. <A', (Ad,)>. |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
133 |
# This flag mean that the successors express the changes between the public and |
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
134 |
# bumped version and fix the situation, breaking the transitivity of |
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
135 |
# "bumped" here. |
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
136 |
bumpedfix = 1 |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
137 |
|
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
138 |
def _readmarkers(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
139 |
"""Read and enumerate markers from raw data""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
140 |
off = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
141 |
diskversion = _unpack('>B', data[off:off + 1])[0] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
142 |
off += 1 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
143 |
if diskversion != _fmversion: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
144 |
raise util.Abort(_('parsing obsolete marker: unknown version %r') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
145 |
% diskversion) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
146 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
147 |
# Loop on markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
148 |
l = len(data) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
149 |
while off + _fmfsize <= l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
150 |
# read fixed part |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
151 |
cur = data[off:off + _fmfsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
152 |
off += _fmfsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
153 |
nbsuc, mdsize, flags, pre = _unpack(_fmfixed, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
154 |
# read replacement |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
155 |
sucs = () |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
156 |
if nbsuc: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
157 |
s = (_fnodesize * nbsuc) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
158 |
cur = data[off:off + s] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
159 |
sucs = _unpack(_fmnode * nbsuc, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
160 |
off += s |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
161 |
# read metadata |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
162 |
# (metadata will be decoded on demand) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
163 |
metadata = data[off:off + mdsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
164 |
if len(metadata) != mdsize: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
165 |
raise util.Abort(_('parsing obsolete marker: metadata is too ' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
166 |
'short, %d bytes expected, got %d') |
17253
67f56ff5afcd
obsolete: fix decoding error message arguments
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17220
diff
changeset
|
167 |
% (mdsize, len(metadata))) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
168 |
off += mdsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
169 |
yield (pre, sucs, flags, metadata) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
170 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
171 |
def encodemeta(meta): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
172 |
"""Return encoded metadata string to string mapping. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
173 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
174 |
Assume no ':' in key and no '\0' in both key and value.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
175 |
for key, value in meta.iteritems(): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
176 |
if ':' in key or '\0' in key: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
177 |
raise ValueError("':' and '\0' are forbidden in metadata key'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
178 |
if '\0' in value: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
179 |
raise ValueError("':' are forbidden in metadata value'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
180 |
return '\0'.join(['%s:%s' % (k, meta[k]) for k in sorted(meta)]) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
181 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
182 |
def decodemeta(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
183 |
"""Return string to string dictionary from encoded version.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
184 |
d = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
185 |
for l in data.split('\0'): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
186 |
if l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
187 |
key, value = l.split(':') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
188 |
d[key] = value |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
189 |
return d |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
190 |
|
17072
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
191 |
class marker(object): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
192 |
"""Wrap obsolete marker raw data""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
193 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
194 |
def __init__(self, repo, data): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
195 |
# the repo argument will be used to create changectx in later version |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
196 |
self._repo = repo |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
197 |
self._data = data |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
198 |
self._decodedmeta = None |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
199 |
|
20031
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
200 |
def __hash__(self): |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
201 |
return hash(self._data) |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
202 |
|
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
203 |
def __eq__(self, other): |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
204 |
if type(other) != type(self): |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
205 |
return False |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
206 |
return self._data == other._data |
6c1adf2067bb
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler <raf@durin42.com>
parents:
20030
diff
changeset
|
207 |
|
17072
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
208 |
def precnode(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
209 |
"""Precursor changeset node identifier""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
210 |
return self._data[0] |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
211 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
212 |
def succnodes(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
213 |
"""List of successor changesets node identifiers""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
214 |
return self._data[1] |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
215 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
216 |
def metadata(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
217 |
"""Decoded metadata dictionary""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
218 |
if self._decodedmeta is None: |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
219 |
self._decodedmeta = decodemeta(self._data[3]) |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
220 |
return self._decodedmeta |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
221 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
222 |
def date(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
223 |
"""Creation date as (unixtime, offset)""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
224 |
parts = self.metadata()['date'].split(' ') |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
225 |
return (float(parts[0]), int(parts[1])) |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
226 |
|
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
227 |
class obsstore(object): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
228 |
"""Store obsolete markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
229 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
230 |
Markers can be accessed with two mappings: |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
231 |
- precursors[x] -> set(markers on precursors edges of x) |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
232 |
- successors[x] -> set(markers on successors edges of x) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
233 |
""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
234 |
|
17124
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
235 |
def __init__(self, sopener): |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
236 |
# caches for various obsolescence related cache |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
237 |
self.caches = {} |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
238 |
self._all = [] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
239 |
# new markers to serialize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
240 |
self.precursors = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
241 |
self.successors = {} |
17124
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
242 |
self.sopener = sopener |
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
243 |
data = sopener.tryread('obsstore') |
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
244 |
if data: |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
245 |
self._load(_readmarkers(data)) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
246 |
|
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
247 |
def __iter__(self): |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
248 |
return iter(self._all) |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
249 |
|
20585
f3c8db3d6d66
obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20584
diff
changeset
|
250 |
def __len__(self): |
f3c8db3d6d66
obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20584
diff
changeset
|
251 |
return len(self._all) |
f3c8db3d6d66
obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20584
diff
changeset
|
252 |
|
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
253 |
def __nonzero__(self): |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
254 |
return bool(self._all) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
255 |
|
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
256 |
def create(self, transaction, prec, succs=(), flag=0, metadata=None): |
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
257 |
"""obsolete: add a new obsolete marker |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
258 |
|
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
259 |
* ensuring it is hashable |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
260 |
* check mandatory metadata |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
261 |
* encode metadata |
20516
3af218cf2007
obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20476
diff
changeset
|
262 |
|
3af218cf2007
obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20476
diff
changeset
|
263 |
If you are a human writing code creating marker you want to use the |
3af218cf2007
obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20476
diff
changeset
|
264 |
`createmarkers` function in this module instead. |
20584
224a058f7cd1
obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20549
diff
changeset
|
265 |
|
224a058f7cd1
obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20549
diff
changeset
|
266 |
return True if a new marker have been added, False if the markers |
224a058f7cd1
obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20549
diff
changeset
|
267 |
already existed (no op). |
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
268 |
""" |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
269 |
if metadata is None: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
270 |
metadata = {} |
18904
e9331e979d7a
obsolete: ensure all markers have a date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18644
diff
changeset
|
271 |
if 'date' not in metadata: |
e9331e979d7a
obsolete: ensure all markers have a date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18644
diff
changeset
|
272 |
metadata['date'] = "%d %d" % util.makedate() |
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
273 |
if len(prec) != 20: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
274 |
raise ValueError(prec) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
275 |
for succ in succs: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
276 |
if len(succ) != 20: |
17117
217bfb10e6db
obsolete: fix error message at marker creation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17076
diff
changeset
|
277 |
raise ValueError(succ) |
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
278 |
marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata)) |
20584
224a058f7cd1
obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20549
diff
changeset
|
279 |
return bool(self.add(transaction, [marker])) |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
280 |
|
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
281 |
def add(self, transaction, markers): |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
282 |
"""Add new markers to the store |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
283 |
|
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
284 |
Take care of filtering duplicate. |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
285 |
Return the number of new marker.""" |
17296
a1f8869f2eee
obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17295
diff
changeset
|
286 |
if not _enabled: |
a1f8869f2eee
obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17295
diff
changeset
|
287 |
raise util.Abort('obsolete feature is not enabled on this repo') |
20028
28445179df90
obsolete: stop doing membership test on list
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19951
diff
changeset
|
288 |
known = set(self._all) |
20030
5931489b65e0
obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20028
diff
changeset
|
289 |
new = [] |
5931489b65e0
obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20028
diff
changeset
|
290 |
for m in markers: |
5931489b65e0
obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20028
diff
changeset
|
291 |
if m not in known: |
5931489b65e0
obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20028
diff
changeset
|
292 |
known.add(m) |
5931489b65e0
obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20028
diff
changeset
|
293 |
new.append(m) |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
294 |
if new: |
17125
95d785ccb4e5
obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17124
diff
changeset
|
295 |
f = self.sopener('obsstore', 'ab') |
17124
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
296 |
try: |
17195
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
297 |
# Whether the file's current position is at the begin or at |
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
298 |
# the end after opening a file for appending is implementation |
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
299 |
# defined. So we must seek to the end before calling tell(), |
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
300 |
# or we may get a zero offset for non-zero sized files on |
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
301 |
# some platforms (issue3543). |
17429
72fa4ef2245f
declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
302 |
f.seek(0, _SEEK_END) |
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
303 |
offset = f.tell() |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
304 |
transaction.add('obsstore', offset) |
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
305 |
# offset == 0: new file - add the version header |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
306 |
for bytes in _encodemarkers(new, offset == 0): |
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
307 |
f.write(bytes) |
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
308 |
finally: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
309 |
# XXX: f.close() == filecache invalidation == obsstore rebuilt. |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
310 |
# call 'filecacheentry.refresh()' here |
17124
f1b7683f3f95
obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17117
diff
changeset
|
311 |
f.close() |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
312 |
self._load(new) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
313 |
# new marker *may* have changed several set. invalidate the cache. |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
314 |
self.caches.clear() |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
315 |
return len(new) |
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
316 |
|
17524 | 317 |
def mergemarkers(self, transaction, data): |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
318 |
markers = _readmarkers(data) |
17524 | 319 |
self.add(transaction, markers) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
320 |
|
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
321 |
def _load(self, markers): |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
322 |
for mark in markers: |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
323 |
self._all.append(mark) |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
324 |
pre, sucs = mark[:2] |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
325 |
self.successors.setdefault(pre, set()).add(mark) |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
326 |
for suc in sucs: |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
327 |
self.precursors.setdefault(suc, set()).add(mark) |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
328 |
if node.nullid in self.precursors: |
17774
0496d4f73cf4
obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17537
diff
changeset
|
329 |
raise util.Abort(_('bad obsolescence marker detected: ' |
0496d4f73cf4
obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17537
diff
changeset
|
330 |
'invalid successors nullid')) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
331 |
|
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
332 |
def _encodemarkers(markers, addheader=False): |
17125
95d785ccb4e5
obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17124
diff
changeset
|
333 |
# Kept separate from flushmarkers(), it will be reused for |
95d785ccb4e5
obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17124
diff
changeset
|
334 |
# markers exchange. |
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
335 |
if addheader: |
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
336 |
yield _pack('>B', _fmversion) |
17125
95d785ccb4e5
obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17124
diff
changeset
|
337 |
for marker in markers: |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
338 |
yield _encodeonemarker(marker) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
339 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
340 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
341 |
def _encodeonemarker(marker): |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
342 |
pre, sucs, flags, metadata = marker |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
343 |
nbsuc = len(sucs) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
344 |
format = _fmfixed + (_fmnode * nbsuc) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
345 |
data = [nbsuc, len(metadata), flags, pre] |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
346 |
data.extend(sucs) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
347 |
return _pack(format, *data) + metadata |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
348 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
349 |
# arbitrary picked to fit into 8K limit from HTTP server |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
350 |
# you have to take in account: |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
351 |
# - the version header |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
352 |
# - the base85 encoding |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
353 |
_maxpayload = 5300 |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
354 |
|
20599
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
355 |
def _pushkeyescape(markers): |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
356 |
"""encode markers into a dict suitable for pushkey exchange |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
357 |
|
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
358 |
- binary data is base86 encoded |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
359 |
- splitted in chunks less than 5300 bytes""" |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
360 |
keys = {} |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
361 |
parts = [] |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
362 |
currentlen = _maxpayload * 2 # ensure we create a new part |
20599
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
363 |
for marker in markers: |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
364 |
nextdata = _encodeonemarker(marker) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
365 |
if (len(nextdata) + currentlen > _maxpayload): |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
366 |
currentpart = [] |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
367 |
currentlen = 0 |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
368 |
parts.append(currentpart) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
369 |
currentpart.append(nextdata) |
17304
0368fc55d572
obsolete: properly increment currentlen when building pushkey payload
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17298
diff
changeset
|
370 |
currentlen += len(nextdata) |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
371 |
for idx, part in enumerate(reversed(parts)): |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
372 |
data = ''.join([_pack('>B', _fmversion)] + part) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
373 |
keys['dump%i' % idx] = base85.b85encode(data) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
374 |
return keys |
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
375 |
|
20599
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
376 |
def listmarkers(repo): |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
377 |
"""List markers over pushkey""" |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
378 |
if not repo.obsstore: |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
379 |
return {} |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
380 |
return _pushkeyescape(repo.obsstore) |
dad29624b056
obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20585
diff
changeset
|
381 |
|
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
382 |
def pushmarker(repo, key, old, new): |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
383 |
"""Push markers over pushkey""" |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
384 |
if not key.startswith('dump'): |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
385 |
repo.ui.warn(_('unknown key: %r') % key) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
386 |
return 0 |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
387 |
if old: |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
388 |
repo.ui.warn(_('unexpected old value') % key) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
389 |
return 0 |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
390 |
data = base85.b85decode(new) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
391 |
lock = repo.lock() |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
392 |
try: |
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
393 |
tr = repo.transaction('pushkey: obsolete markers') |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
394 |
try: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
395 |
repo.obsstore.mergemarkers(tr, data) |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
396 |
tr.close() |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
397 |
return 1 |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
398 |
finally: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
399 |
tr.release() |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
400 |
finally: |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
401 |
lock.release() |
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
402 |
|
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
403 |
def allmarkers(repo): |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
404 |
"""all obsolete markers known in a repository""" |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
405 |
for markerdata in repo.obsstore: |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
406 |
yield marker(repo, markerdata) |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
407 |
|
17076
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
408 |
def precursormarkers(ctx): |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
409 |
"""obsolete marker marking this changeset as a successors""" |
17076
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
410 |
for data in ctx._repo.obsstore.precursors.get(ctx.node(), ()): |
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
411 |
yield marker(ctx._repo, data) |
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
412 |
|
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
413 |
def successormarkers(ctx): |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
414 |
"""obsolete marker making this changeset obsolete""" |
17076
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
415 |
for data in ctx._repo.obsstore.successors.get(ctx.node(), ()): |
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
416 |
yield marker(ctx._repo, data) |
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
417 |
|
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
418 |
def allsuccessors(obsstore, nodes, ignoreflags=0): |
17827
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
419 |
"""Yield node for every successor of <nodes>. |
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
420 |
|
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
421 |
Some successors may be unknown locally. |
17213
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
422 |
|
20204
b0c14c5d44b1
obsolete: improve allsuccessors doc string
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20203
diff
changeset
|
423 |
This is a linear yield unsuited to detecting split changesets. It includes |
b0c14c5d44b1
obsolete: improve allsuccessors doc string
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20203
diff
changeset
|
424 |
initial nodes too.""" |
17827
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
425 |
remaining = set(nodes) |
17213
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
426 |
seen = set(remaining) |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
427 |
while remaining: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
428 |
current = remaining.pop() |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
429 |
yield current |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
430 |
for mark in obsstore.successors.get(current, ()): |
20203
509768fc7542
obsolete: fix bad comment
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20031
diff
changeset
|
431 |
# ignore marker flagged with specified flag |
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
432 |
if mark[2] & ignoreflags: |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
433 |
continue |
17213
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
434 |
for suc in mark[1]: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
435 |
if suc not in seen: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
436 |
seen.add(suc) |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
437 |
remaining.add(suc) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
438 |
|
20206
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
439 |
def allprecursors(obsstore, nodes, ignoreflags=0): |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
440 |
"""Yield node for every precursors of <nodes>. |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
441 |
|
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
442 |
Some precursors may be unknown locally. |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
443 |
|
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
444 |
This is a linear yield unsuited to detecting folded changesets. It includes |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
445 |
initial nodes too.""" |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
446 |
|
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
447 |
remaining = set(nodes) |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
448 |
seen = set(remaining) |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
449 |
while remaining: |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
450 |
current = remaining.pop() |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
451 |
yield current |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
452 |
for mark in obsstore.precursors.get(current, ()): |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
453 |
# ignore marker flagged with specified flag |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
454 |
if mark[2] & ignoreflags: |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
455 |
continue |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
456 |
suc = mark[0] |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
457 |
if suc not in seen: |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
458 |
seen.add(suc) |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
459 |
remaining.add(suc) |
cdcbe103b69a
obsolete: add an allprecursors method mirroring allsuccessors one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20204
diff
changeset
|
460 |
|
18984
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
461 |
def foreground(repo, nodes): |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
462 |
"""return all nodes in the "foreground" of other node |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
463 |
|
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
464 |
The foreground of a revision is anything reachable using parent -> children |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19618
diff
changeset
|
465 |
or precursor -> successor relation. It is very similar to "descendant" but |
18984
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
466 |
augmented with obsolescence information. |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
467 |
|
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19618
diff
changeset
|
468 |
Beware that possible obsolescence cycle may result if complex situation. |
18984
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
469 |
""" |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
470 |
repo = repo.unfiltered() |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
471 |
foreground = set(repo.set('%ln::', nodes)) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
472 |
if repo.obsstore: |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
473 |
# We only need this complicated logic if there is obsolescence |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
474 |
# XXX will probably deserve an optimised revset. |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
475 |
nm = repo.changelog.nodemap |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
476 |
plen = -1 |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
477 |
# compute the whole set of successors or descendants |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
478 |
while len(foreground) != plen: |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
479 |
plen = len(foreground) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
480 |
succs = set(c.node() for c in foreground) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
481 |
mutable = [c.node() for c in foreground if c.mutable()] |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
482 |
succs.update(allsuccessors(repo.obsstore, mutable)) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
483 |
known = (n for n in succs if n in nm) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
484 |
foreground = set(repo.set('%ln::', known)) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
485 |
return set(c.node() for c in foreground) |
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
486 |
|
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18904
diff
changeset
|
487 |
|
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
488 |
def successorssets(repo, initialnode, cache=None): |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
489 |
"""Return all set of successors of initial nodes |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
490 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
491 |
The successors set of a changeset A are a group of revisions that succeed |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
492 |
A. It succeeds A as a consistent whole, each revision being only a partial |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
493 |
replacement. The successors set contains non-obsolete changesets only. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
494 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
495 |
This function returns the full list of successor sets which is why it |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
496 |
returns a list of tuples and not just a single tuple. Each tuple is a valid |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
497 |
successors set. Not that (A,) may be a valid successors set for changeset A |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
498 |
(see below). |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
499 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
500 |
In most cases, a changeset A will have a single element (e.g. the changeset |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
501 |
A is replaced by A') in its successors set. Though, it is also common for a |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
502 |
changeset A to have no elements in its successor set (e.g. the changeset |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
503 |
has been pruned). Therefore, the returned list of successors sets will be |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
504 |
[(A',)] or [], respectively. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
505 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
506 |
When a changeset A is split into A' and B', however, it will result in a |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
507 |
successors set containing more than a single element, i.e. [(A',B')]. |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
508 |
Divergent changesets will result in multiple successors sets, i.e. [(A',), |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
509 |
(A'')]. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
510 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
511 |
If a changeset A is not obsolete, then it will conceptually have no |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
512 |
successors set. To distinguish this from a pruned changeset, the successor |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
513 |
set will only contain itself, i.e. [(A,)]. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
514 |
|
20277
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
515 |
Finally, successors unknown locally are considered to be pruned (obsoleted |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
516 |
without any successors). |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
517 |
|
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
518 |
The optional `cache` parameter is a dictionary that may contain precomputed |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
519 |
successors sets. It is meant to reuse the computation of a previous call to |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
520 |
`successorssets` when multiple calls are made at the same time. The cache |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
521 |
dictionary is updated in place. The caller is responsible for its live |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
522 |
spawn. Code that makes multiple calls to `successorssets` *must* use this |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
523 |
cache mechanism or suffer terrible performances. |
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
524 |
|
c05b968d05eb
obsolete: clarify documentation for succcessorssets
Sean Farley <sean.michael.farley@gmail.com>
parents:
20207
diff
changeset
|
525 |
""" |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
526 |
|
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
527 |
succmarkers = repo.obsstore.successors |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
528 |
|
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
529 |
# Stack of nodes we search successors sets for |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
530 |
toproceed = [initialnode] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
531 |
# set version of above list for fast loop detection |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
532 |
# element added to "toproceed" must be added here |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
533 |
stackedset = set(toproceed) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
534 |
if cache is None: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
535 |
cache = {} |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
536 |
|
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
537 |
# This while loop is the flattened version of a recursive search for |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
538 |
# successors sets |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
539 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
540 |
# def successorssets(x): |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
541 |
# successors = directsuccessors(x) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
542 |
# ss = [[]] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
543 |
# for succ in directsuccessors(x): |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
544 |
# # product as in itertools cartesian product |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
545 |
# ss = product(ss, successorssets(succ)) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
546 |
# return ss |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
547 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
548 |
# But we can not use plain recursive calls here: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
549 |
# - that would blow the python call stack |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
550 |
# - obsolescence markers may have cycles, we need to handle them. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
551 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
552 |
# The `toproceed` list act as our call stack. Every node we search |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
553 |
# successors set for are stacked there. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
554 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
555 |
# The `stackedset` is set version of this stack used to check if a node is |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
556 |
# already stacked. This check is used to detect cycles and prevent infinite |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
557 |
# loop. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
558 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
559 |
# successors set of all nodes are stored in the `cache` dictionary. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
560 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
561 |
# After this while loop ends we use the cache to return the successors sets |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
562 |
# for the node requested by the caller. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
563 |
while toproceed: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
564 |
# Every iteration tries to compute the successors sets of the topmost |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
565 |
# node of the stack: CURRENT. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
566 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
567 |
# There are four possible outcomes: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
568 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
569 |
# 1) We already know the successors sets of CURRENT: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
570 |
# -> mission accomplished, pop it from the stack. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
571 |
# 2) Node is not obsolete: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
572 |
# -> the node is its own successors sets. Add it to the cache. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
573 |
# 3) We do not know successors set of direct successors of CURRENT: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
574 |
# -> We add those successors to the stack. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
575 |
# 4) We know successors sets of all direct successors of CURRENT: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
576 |
# -> We can compute CURRENT successors set and add it to the |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
577 |
# cache. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
578 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
579 |
current = toproceed[-1] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
580 |
if current in cache: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
581 |
# case (1): We already know the successors sets |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
582 |
stackedset.remove(toproceed.pop()) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
583 |
elif current not in succmarkers: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
584 |
# case (2): The node is not obsolete. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
585 |
if current in repo: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
586 |
# We have a valid last successors. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
587 |
cache[current] = [(current,)] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
588 |
else: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
589 |
# Final obsolete version is unknown locally. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
590 |
# Do not count that as a valid successors |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
591 |
cache[current] = [] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
592 |
else: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
593 |
# cases (3) and (4) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
594 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
595 |
# We proceed in two phases. Phase 1 aims to distinguish case (3) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
596 |
# from case (4): |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
597 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
598 |
# For each direct successors of CURRENT, we check whether its |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
599 |
# successors sets are known. If they are not, we stack the |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
600 |
# unknown node and proceed to the next iteration of the while |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
601 |
# loop. (case 3) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
602 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
603 |
# During this step, we may detect obsolescence cycles: a node |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
604 |
# with unknown successors sets but already in the call stack. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
605 |
# In such a situation, we arbitrary set the successors sets of |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
606 |
# the node to nothing (node pruned) to break the cycle. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
607 |
# |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
608 |
# If no break was encountered we proceed to phase 2. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
609 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
610 |
# Phase 2 computes successors sets of CURRENT (case 4); see details |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
611 |
# in phase 2 itself. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
612 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
613 |
# Note the two levels of iteration in each phase. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
614 |
# - The first one handles obsolescence markers using CURRENT as |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
615 |
# precursor (successors markers of CURRENT). |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
616 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
617 |
# Having multiple entry here means divergence. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
618 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
619 |
# - The second one handles successors defined in each marker. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
620 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
621 |
# Having none means pruned node, multiple successors means split, |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
622 |
# single successors are standard replacement. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
623 |
# |
18365
4148414da120
obsolete: process markers in a stable order
Mads Kiilerich <mads@kiilerich.com>
parents:
18277
diff
changeset
|
624 |
for mark in sorted(succmarkers[current]): |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
625 |
for suc in mark[1]: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
626 |
if suc not in cache: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
627 |
if suc in stackedset: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
628 |
# cycle breaking |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
629 |
cache[suc] = [] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
630 |
else: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
631 |
# case (3) If we have not computed successors sets |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
632 |
# of one of those successors we add it to the |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
633 |
# `toproceed` stack and stop all work for this |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
634 |
# iteration. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
635 |
toproceed.append(suc) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
636 |
stackedset.add(suc) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
637 |
break |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
638 |
else: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
639 |
continue |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
640 |
break |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
641 |
else: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
642 |
# case (4): we know all successors sets of all direct |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
643 |
# successors |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
644 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
645 |
# Successors set contributed by each marker depends on the |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
646 |
# successors sets of all its "successors" node. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
647 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
648 |
# Each different marker is a divergence in the obsolescence |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
649 |
# history. It contributes successors sets distinct from other |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
650 |
# markers. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
651 |
# |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
652 |
# Within a marker, a successor may have divergent successors |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
653 |
# sets. In such a case, the marker will contribute multiple |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
654 |
# divergent successors sets. If multiple successors have |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18365
diff
changeset
|
655 |
# divergent successors sets, a cartesian product is used. |
18069
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
656 |
# |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
657 |
# At the end we post-process successors sets to remove |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
658 |
# duplicated entry and successors set that are strict subset of |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
659 |
# another one. |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
660 |
succssets = [] |
18365
4148414da120
obsolete: process markers in a stable order
Mads Kiilerich <mads@kiilerich.com>
parents:
18277
diff
changeset
|
661 |
for mark in sorted(succmarkers[current]): |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
662 |
# successors sets contributed by this marker |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
663 |
markss = [[]] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
664 |
for suc in mark[1]: |
18069
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
665 |
# cardinal product with previous successors |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
666 |
productresult = [] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
667 |
for prefix in markss: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
668 |
for suffix in cache[suc]: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
669 |
newss = list(prefix) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
670 |
for part in suffix: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
671 |
# do not duplicated entry in successors set |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
672 |
# first entry wins. |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
673 |
if part not in newss: |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
674 |
newss.append(part) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
675 |
productresult.append(newss) |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
676 |
markss = productresult |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
677 |
succssets.extend(markss) |
18069
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
678 |
# remove duplicated and subset |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
679 |
seen = [] |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
680 |
final = [] |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
681 |
candidate = sorted(((set(s), s) for s in succssets if s), |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
682 |
key=lambda x: len(x[1]), reverse=True) |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
683 |
for setversion, listversion in candidate: |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
684 |
for seenset in seen: |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
685 |
if setversion.issubset(seenset): |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
686 |
break |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
687 |
else: |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
688 |
final.append(listversion) |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
689 |
seen.append(setversion) |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
690 |
final.reverse() # put small successors set first |
f84e731cbd20
obsolete: drop successors sets which are subset of another one
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18068
diff
changeset
|
691 |
cache[current] = final |
18068
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
692 |
return cache[initialnode] |
4bec77e62c00
obsolete: compute successors set
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18001
diff
changeset
|
693 |
|
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
694 |
def _knownrevs(repo, nodes): |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
695 |
"""yield revision numbers of known nodes passed in parameters |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
696 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
697 |
Unknown revisions are silently ignored.""" |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
698 |
torev = repo.changelog.nodemap.get |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
699 |
for n in nodes: |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
700 |
rev = torev(n) |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
701 |
if rev is not None: |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
702 |
yield rev |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
703 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
704 |
# mapping of 'set-name' -> <function to compute this set> |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
705 |
cachefuncs = {} |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
706 |
def cachefor(name): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
707 |
"""Decorator to register a function as computing the cache for a set""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
708 |
def decorator(func): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
709 |
assert name not in cachefuncs |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
710 |
cachefuncs[name] = func |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
711 |
return func |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
712 |
return decorator |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
713 |
|
17825
3cc06457f15e
obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17776
diff
changeset
|
714 |
def getrevs(repo, name): |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
715 |
"""Return the set of revision that belong to the <name> set |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
716 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
717 |
Such access may compute the set and cache it for future use""" |
18001
e02feadd15ea
clfilter: unfilter computation of obsolescence related computation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17831
diff
changeset
|
718 |
repo = repo.unfiltered() |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
719 |
if not repo.obsstore: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
720 |
return () |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
721 |
if name not in repo.obsstore.caches: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
722 |
repo.obsstore.caches[name] = cachefuncs[name](repo) |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
723 |
return repo.obsstore.caches[name] |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
724 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
725 |
# To be simple we need to invalidate obsolescence cache when: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
726 |
# |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
727 |
# - new changeset is added: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
728 |
# - public phase is changed |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
729 |
# - obsolescence marker are added |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
730 |
# - strip is used a repo |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
731 |
def clearobscaches(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
732 |
"""Remove all obsolescence related cache from a repo |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
733 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
734 |
This remove all cache in obsstore is the obsstore already exist on the |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
735 |
repo. |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
736 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
737 |
(We could be smarter here given the exact event that trigger the cache |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
738 |
clearing)""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
739 |
# only clear cache is there is obsstore data in this repo |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
740 |
if 'obsstore' in repo._filecache: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
741 |
repo.obsstore.caches.clear() |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
742 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
743 |
@cachefor('obsolete') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
744 |
def _computeobsoleteset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
745 |
"""the set of obsolete revisions""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
746 |
obs = set() |
18271
67872e939945
performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18101
diff
changeset
|
747 |
getrev = repo.changelog.nodemap.get |
67872e939945
performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18101
diff
changeset
|
748 |
getphase = repo._phasecache.phase |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
749 |
for node in repo.obsstore.successors: |
18271
67872e939945
performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18101
diff
changeset
|
750 |
rev = getrev(node) |
67872e939945
performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18101
diff
changeset
|
751 |
if rev is not None and getphase(repo, rev): |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
752 |
obs.add(rev) |
18271
67872e939945
performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18101
diff
changeset
|
753 |
return obs |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
754 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
755 |
@cachefor('unstable') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
756 |
def _computeunstableset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
757 |
"""the set of non obsolete revisions with obsolete parents""" |
18275
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
758 |
# revset is not efficient enough here |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
759 |
# we do (obsolete()::) - obsolete() by hand |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
760 |
obs = getrevs(repo, 'obsolete') |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
761 |
if not obs: |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
762 |
return set() |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
763 |
cl = repo.changelog |
9818f22785b7
performance: speedup computation of unstable revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18271
diff
changeset
|
764 |
return set(r for r in cl.descendants(obs) if r not in obs) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
765 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
766 |
@cachefor('suspended') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
767 |
def _computesuspendedset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
768 |
"""the set of obsolete parents with non obsolete descendants""" |
18276
834ef7e70d0f
performance: speedup computation of suspended revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18275
diff
changeset
|
769 |
suspended = repo.changelog.ancestors(getrevs(repo, 'unstable')) |
834ef7e70d0f
performance: speedup computation of suspended revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18275
diff
changeset
|
770 |
return set(r for r in getrevs(repo, 'obsolete') if r in suspended) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
771 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
772 |
@cachefor('extinct') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
773 |
def _computeextinctset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
774 |
"""the set of obsolete parents without non obsolete descendants""" |
18277
a58260bc101f
performance: speedup computation of extinct revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18276
diff
changeset
|
775 |
return getrevs(repo, 'obsolete') - getrevs(repo, 'suspended') |
17474
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
776 |
|
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
777 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
778 |
@cachefor('bumped') |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
779 |
def _computebumpedset(repo): |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
780 |
"""the set of revs trying to obsolete public revisions""" |
20207
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
781 |
bumped = set() |
20549
2025315cfb0c
comments: fix minor spelling issues found with spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20517
diff
changeset
|
782 |
# utils function (avoid attribute lookup in the loop) |
20207
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
783 |
phase = repo._phasecache.phase # would be faster to grab the full list |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
784 |
public = phases.public |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
785 |
cl = repo.changelog |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
786 |
torev = cl.nodemap.get |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
787 |
obs = getrevs(repo, 'obsolete') |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
788 |
for rev in repo: |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
789 |
# We only evaluate mutable, non-obsolete revision |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
790 |
if (public < phase(repo, rev)) and (rev not in obs): |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
791 |
node = cl.node(rev) |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
792 |
# (future) A cache of precursors may worth if split is very common |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
793 |
for pnode in allprecursors(repo.obsstore, [node], |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
794 |
ignoreflags=bumpedfix): |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
795 |
prev = torev(pnode) # unfiltered! but so is phasecache |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
796 |
if (prev is not None) and (phase(repo, prev) <= public): |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
797 |
# we have a public precursors |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
798 |
bumped.add(rev) |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
799 |
break # Next draft! |
cd62532c62a1
obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20206
diff
changeset
|
800 |
return bumped |
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
801 |
|
18070
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
802 |
@cachefor('divergent') |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
803 |
def _computedivergentset(repo): |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
804 |
"""the set of rev that compete to be the final successors of some revision. |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
805 |
""" |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
806 |
divergent = set() |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
807 |
obsstore = repo.obsstore |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
808 |
newermap = {} |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
809 |
for ctx in repo.set('(not public()) - obsolete()'): |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
810 |
mark = obsstore.precursors.get(ctx.node(), ()) |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
811 |
toprocess = set(mark) |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
812 |
while toprocess: |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
813 |
prec = toprocess.pop()[0] |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
814 |
if prec not in newermap: |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
815 |
successorssets(repo, prec, newermap) |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
816 |
newer = [n for n in newermap[prec] if n] |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
817 |
if len(newer) > 1: |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
818 |
divergent.add(ctx.rev()) |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
819 |
break |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
820 |
toprocess.update(obsstore.precursors.get(prec, ())) |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
821 |
return divergent |
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
822 |
|
af632936d3d9
obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18069
diff
changeset
|
823 |
|
17474
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
824 |
def createmarkers(repo, relations, flag=0, metadata=None): |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
825 |
"""Add obsolete markers between changesets in a repo |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
826 |
|
20517
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
827 |
<relations> must be an iterable of (<old>, (<new>, ...)[,{metadata}]) |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
828 |
tuple. `old` and `news` are changectx. metadata is an optional dictionnary |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
829 |
containing metadata for this marker only. It is merged with the global |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
830 |
metadata specified through the `metadata` argument of this function, |
17474
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
831 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
832 |
Trying to obsolete a public changeset will raise an exception. |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
833 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
834 |
Current user and date are used except if specified otherwise in the |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
835 |
metadata attribute. |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
836 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
837 |
This function operates within a transaction of its own, but does |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
838 |
not take any lock on the repo. |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
839 |
""" |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
840 |
# prepare metadata |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
841 |
if metadata is None: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
842 |
metadata = {} |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
843 |
if 'date' not in metadata: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
844 |
metadata['date'] = '%i %i' % util.makedate() |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
845 |
if 'user' not in metadata: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
846 |
metadata['user'] = repo.ui.username() |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
847 |
tr = repo.transaction('add-obsolescence-marker') |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
848 |
try: |
20517
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
849 |
for rel in relations: |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
850 |
prec = rel[0] |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
851 |
sucs = rel[1] |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
852 |
localmetadata = metadata.copy() |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
853 |
if 2 < len(rel): |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
854 |
localmetadata.update(rel[2]) |
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
855 |
|
17474
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
856 |
if not prec.mutable(): |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
857 |
raise util.Abort("cannot obsolete immutable changeset: %s" |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
858 |
% prec) |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
859 |
nprec = prec.node() |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
860 |
nsucs = tuple(s.node() for s in sucs) |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
861 |
if nprec in nsucs: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
862 |
raise util.Abort("changeset %s cannot obsolete itself" % prec) |
20517
2158e8f3cbd2
createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20516
diff
changeset
|
863 |
repo.obsstore.create(tr, nprec, nsucs, flag, localmetadata) |
18101
a464deecc9dd
clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18070
diff
changeset
|
864 |
repo.filteredrevcache.clear() |
17474
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
865 |
tr.close() |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
866 |
finally: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
867 |
tr.release() |