author | David Schleimer <dschleimer@fb.com> |
Tue, 04 Dec 2012 12:54:18 -0800 | |
changeset 18039 | 2c2564280900 |
parent 18001 | e02feadd15ea |
child 18068 | 4bec77e62c00 |
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" |
13744acc4ad7
obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17774
diff
changeset
|
49 |
case. If two independants operation rewrite the same changeset A in to A' and |
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 |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
87 |
from i18n import _ |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
88 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
89 |
_pack = struct.pack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
90 |
_unpack = struct.unpack |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
91 |
|
17429
72fa4ef2245f
declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
92 |
_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
|
93 |
|
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17405
diff
changeset
|
94 |
# 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
|
95 |
# 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
|
96 |
_enabled = False |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
97 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
98 |
# data used for parsing and writing |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
99 |
_fmversion = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
100 |
_fmfixed = '>BIB20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
101 |
_fmnode = '20s' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
102 |
_fmfsize = struct.calcsize(_fmfixed) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
103 |
_fnodesize = struct.calcsize(_fmnode) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
104 |
|
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
105 |
### 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
|
106 |
|
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
107 |
## bumpedfix flag |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
108 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
109 |
# 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
|
110 |
# "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
|
111 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
112 |
# 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
|
113 |
# |`: |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
114 |
# | o A |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
115 |
# |/ |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
116 |
# o Z |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
117 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
118 |
# 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
|
119 |
# 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
|
120 |
# 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
|
121 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
122 |
# o Ad |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
123 |
# |`: |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
124 |
# | x A' |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
125 |
# |'| |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
126 |
# o | A |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
127 |
# |/ |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
128 |
# o Z |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
129 |
# |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
130 |
# 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
|
131 |
# as bumped too, we add the `bumpedfix` flag to the marker. <A', (Ad,)>. |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
132 |
# This flag mean that the successors are an interdiff that fix the bumped |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
133 |
# situation, breaking the transitivity of "bumped" here. |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
134 |
bumpedfix = 1 |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
135 |
|
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
136 |
def _readmarkers(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
137 |
"""Read and enumerate markers from raw data""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
138 |
off = 0 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
139 |
diskversion = _unpack('>B', data[off:off + 1])[0] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
140 |
off += 1 |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
141 |
if diskversion != _fmversion: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
142 |
raise util.Abort(_('parsing obsolete marker: unknown version %r') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
143 |
% diskversion) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
144 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
145 |
# Loop on markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
146 |
l = len(data) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
147 |
while off + _fmfsize <= l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
148 |
# read fixed part |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
149 |
cur = data[off:off + _fmfsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
150 |
off += _fmfsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
151 |
nbsuc, mdsize, flags, pre = _unpack(_fmfixed, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
152 |
# read replacement |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
153 |
sucs = () |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
154 |
if nbsuc: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
155 |
s = (_fnodesize * nbsuc) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
156 |
cur = data[off:off + s] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
157 |
sucs = _unpack(_fmnode * nbsuc, cur) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
158 |
off += s |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
159 |
# read metadata |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
160 |
# (metadata will be decoded on demand) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
161 |
metadata = data[off:off + mdsize] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
162 |
if len(metadata) != mdsize: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
163 |
raise util.Abort(_('parsing obsolete marker: metadata is too ' |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
164 |
'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
|
165 |
% (mdsize, len(metadata))) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
166 |
off += mdsize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
167 |
yield (pre, sucs, flags, metadata) |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
168 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
169 |
def encodemeta(meta): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
170 |
"""Return encoded metadata string to string mapping. |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
171 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
172 |
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
|
173 |
for key, value in meta.iteritems(): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
174 |
if ':' in key or '\0' in key: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
175 |
raise ValueError("':' and '\0' are forbidden in metadata key'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
176 |
if '\0' in value: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
177 |
raise ValueError("':' are forbidden in metadata value'") |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
178 |
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
|
179 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
180 |
def decodemeta(data): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
181 |
"""Return string to string dictionary from encoded version.""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
182 |
d = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
183 |
for l in data.split('\0'): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
184 |
if l: |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
185 |
key, value = l.split(':') |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
186 |
d[key] = value |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
187 |
return d |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
188 |
|
17072
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
189 |
class marker(object): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
190 |
"""Wrap obsolete marker raw data""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
191 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
192 |
def __init__(self, repo, data): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
193 |
# 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
|
194 |
self._repo = repo |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
195 |
self._data = data |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
196 |
self._decodedmeta = None |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
197 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
198 |
def precnode(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
199 |
"""Precursor changeset node identifier""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
200 |
return self._data[0] |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
201 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
202 |
def succnodes(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
203 |
"""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
|
204 |
return self._data[1] |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
205 |
|
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
206 |
def metadata(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
207 |
"""Decoded metadata dictionary""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
208 |
if self._decodedmeta is None: |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
209 |
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
|
210 |
return self._decodedmeta |
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 date(self): |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
213 |
"""Creation date as (unixtime, offset)""" |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
214 |
parts = self.metadata()['date'].split(' ') |
517af63ba382
obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents:
17071
diff
changeset
|
215 |
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
|
216 |
|
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
217 |
class obsstore(object): |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
218 |
"""Store obsolete markers |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
219 |
|
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
220 |
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
|
221 |
- 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
|
222 |
- 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
|
223 |
""" |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
224 |
|
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
|
225 |
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
|
226 |
# 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
|
227 |
self.caches = {} |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
228 |
self._all = [] |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
229 |
# new markers to serialize |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
230 |
self.precursors = {} |
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
if data: |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
235 |
self._load(_readmarkers(data)) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
236 |
|
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
237 |
def __iter__(self): |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
238 |
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
|
239 |
|
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
240 |
def __nonzero__(self): |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
241 |
return bool(self._all) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
242 |
|
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
243 |
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
|
244 |
"""obsolete: add a new obsolete marker |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
245 |
|
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
246 |
* ensuring it is hashable |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
247 |
* check mandatory metadata |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
248 |
* encode metadata |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
249 |
""" |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
250 |
if metadata is None: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
251 |
metadata = {} |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
252 |
if len(prec) != 20: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
253 |
raise ValueError(prec) |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
254 |
for succ in succs: |
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
255 |
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
|
256 |
raise ValueError(succ) |
17071
11f26e2669aa
command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents:
17070
diff
changeset
|
257 |
marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata)) |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
258 |
self.add(transaction, [marker]) |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
259 |
|
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
260 |
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
|
261 |
"""Add new markers to the store |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
262 |
|
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
raise util.Abort('obsolete feature is not enabled on this repo') |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
267 |
new = [m for m in markers if m not in self._all] |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
try: |
17195
48c232873a54
obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents:
17126
diff
changeset
|
271 |
# 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
|
272 |
# 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
|
273 |
# 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
|
274 |
# 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
|
275 |
# some platforms (issue3543). |
17429
72fa4ef2245f
declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
276 |
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
|
277 |
offset = f.tell() |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
278 |
transaction.add('obsstore', offset) |
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
279 |
# 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
|
280 |
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
|
281 |
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
|
282 |
finally: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
283 |
# 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
|
284 |
# 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
|
285 |
f.close() |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
286 |
self._load(new) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
287 |
# 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
|
288 |
self.caches.clear() |
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
289 |
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
|
290 |
|
17524 | 291 |
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
|
292 |
markers = _readmarkers(data) |
17524 | 293 |
self.add(transaction, markers) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
294 |
|
17220
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
295 |
def _load(self, markers): |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
296 |
for mark in markers: |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
297 |
self._all.append(mark) |
bdac214a4705
obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents:
17219
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
'invalid successors nullid')) |
17070
ad0d6c2b3279
obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
305 |
|
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
306 |
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
|
307 |
# 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
|
308 |
# markers exchange. |
17219
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
309 |
if addheader: |
494a970f68de
obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents:
17213
diff
changeset
|
310 |
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
|
311 |
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
|
312 |
yield _encodeonemarker(marker) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
313 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
314 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
315 |
def _encodeonemarker(marker): |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
316 |
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
|
317 |
nbsuc = len(sucs) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
data.extend(sucs) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
321 |
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
|
322 |
|
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
323 |
# 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
|
324 |
# 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
|
325 |
# - the version header |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
326 |
# - the base85 encoding |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
327 |
_maxpayload = 5300 |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
328 |
|
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
329 |
def listmarkers(repo): |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
330 |
"""List markers over pushkey""" |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
331 |
if not repo.obsstore: |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
332 |
return {} |
17295
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
333 |
keys = {} |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
334 |
parts = [] |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
335 |
currentlen = _maxpayload * 2 # ensure we create a new part |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
336 |
for marker in repo.obsstore: |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
337 |
nextdata = _encodeonemarker(marker) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
338 |
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
|
339 |
currentpart = [] |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
340 |
currentlen = 0 |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
341 |
parts.append(currentpart) |
1f08ecc7febb
pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17253
diff
changeset
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
return keys |
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
348 |
|
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
349 |
def pushmarker(repo, key, old, new): |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
350 |
"""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
|
351 |
if not key.startswith('dump'): |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
352 |
repo.ui.warn(_('unknown key: %r') % key) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
353 |
return 0 |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
354 |
if old: |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
355 |
repo.ui.warn(_('unexpected old value') % key) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
356 |
return 0 |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
357 |
data = base85.b85decode(new) |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
358 |
lock = repo.lock() |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
359 |
try: |
17126
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
360 |
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
|
361 |
try: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
362 |
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
|
363 |
tr.close() |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
364 |
return 1 |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
365 |
finally: |
8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17125
diff
changeset
|
366 |
tr.release() |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
367 |
finally: |
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
17073
diff
changeset
|
368 |
lock.release() |
17073
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
369 |
|
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
370 |
def allmarkers(repo): |
3a79a5682af1
obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents:
17072
diff
changeset
|
371 |
"""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
|
372 |
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
|
373 |
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
|
374 |
|
17076
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
375 |
def precursormarkers(ctx): |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
376 |
"""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
|
377 |
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
|
378 |
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
|
379 |
|
75f4180509a4
obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents:
17075
diff
changeset
|
380 |
def successormarkers(ctx): |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
381 |
"""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
|
382 |
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
|
383 |
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
|
384 |
|
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
385 |
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
|
386 |
"""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
|
387 |
|
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
388 |
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
|
389 |
|
17537 | 390 |
This is a linear yield unsuited to detecting split changesets.""" |
17827
612db9d7e76a
obsolete: have `allsuccessors` takes a list of nodes
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17826
diff
changeset
|
391 |
remaining = set(nodes) |
17213
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
392 |
seen = set(remaining) |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
393 |
while remaining: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
394 |
current = remaining.pop() |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
395 |
yield current |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
396 |
for mark in obsstore.successors.get(current, ()): |
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
397 |
# ignore marker flagged with with specified flag |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
398 |
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
|
399 |
continue |
17213
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
400 |
for suc in mark[1]: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
401 |
if suc not in seen: |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
402 |
seen.add(suc) |
7eb5aa1f83fd
obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17200
diff
changeset
|
403 |
remaining.add(suc) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
404 |
|
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
405 |
def _knownrevs(repo, nodes): |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
406 |
"""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
|
407 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
408 |
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
|
409 |
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
|
410 |
for n in nodes: |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
411 |
rev = torev(n) |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
412 |
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
|
413 |
yield rev |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
414 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
415 |
# 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
|
416 |
cachefuncs = {} |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
417 |
def cachefor(name): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
418 |
"""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
|
419 |
def decorator(func): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
420 |
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
|
421 |
cachefuncs[name] = func |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
422 |
return func |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
423 |
return decorator |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
424 |
|
17825
3cc06457f15e
obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17776
diff
changeset
|
425 |
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
|
426 |
"""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
|
427 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
428 |
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
|
429 |
repo = repo.unfiltered() |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
430 |
if not repo.obsstore: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
431 |
return () |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
436 |
# 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
|
437 |
# |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
438 |
# - new changeset is added: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
439 |
# - public phase is changed |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
440 |
# - obsolescence marker are added |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
441 |
# - 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
|
442 |
def clearobscaches(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
443 |
"""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
|
444 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
445 |
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
|
446 |
repo. |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
447 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
448 |
(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
|
449 |
clearing)""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
450 |
# 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
|
451 |
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
|
452 |
repo.obsstore.caches.clear() |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
453 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
454 |
@cachefor('obsolete') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
455 |
def _computeobsoleteset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
456 |
"""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
|
457 |
obs = set() |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
458 |
nm = repo.changelog.nodemap |
17776
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
459 |
for node in repo.obsstore.successors: |
072812e9f570
obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17775
diff
changeset
|
460 |
rev = nm.get(node) |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
461 |
if rev is not None: |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
462 |
obs.add(rev) |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
463 |
return set(repo.revs('%ld - public()', obs)) |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
464 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
465 |
@cachefor('unstable') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
466 |
def _computeunstableset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
467 |
"""the set of non obsolete revisions with obsolete parents""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
468 |
return set(repo.revs('(obsolete()::) - obsolete()')) |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
469 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
470 |
@cachefor('suspended') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
471 |
def _computesuspendedset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
472 |
"""the set of obsolete parents with non obsolete descendants""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
473 |
return set(repo.revs('obsolete() and obsolete()::unstable()')) |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
474 |
|
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
475 |
@cachefor('extinct') |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
476 |
def _computeextinctset(repo): |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
477 |
"""the set of obsolete parents without non obsolete descendants""" |
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17429
diff
changeset
|
478 |
return set(repo.revs('obsolete() - obsolete()::unstable()')) |
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
|
479 |
|
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
480 |
|
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
481 |
@cachefor('bumped') |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
482 |
def _computebumpedset(repo): |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
483 |
"""the set of revs trying to obsolete public revisions""" |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
484 |
# get all possible bumped changesets |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
485 |
tonode = repo.changelog.node |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
486 |
publicnodes = (tonode(r) for r in repo.revs('public()')) |
17831
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
487 |
successors = allsuccessors(repo.obsstore, publicnodes, |
70b08df24fef
obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17828
diff
changeset
|
488 |
ignoreflags=bumpedfix) |
17828
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
489 |
# revision public or already obsolete don't count as bumped |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
490 |
query = '%ld - obsolete() - public()' |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
491 |
return set(repo.revs(query, _knownrevs(repo, successors))) |
9495be4126ef
obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
492 |
|
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
|
493 |
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
|
494 |
"""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
|
495 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
496 |
<relations> must be an iterable of (<old>, (<new>, ...)) tuple. |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
497 |
`old` and `news` are changectx. |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
498 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
499 |
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
|
500 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
|
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
504 |
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
|
505 |
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
|
506 |
""" |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
507 |
# 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
|
508 |
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
|
509 |
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
|
510 |
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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
try: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
516 |
for prec, sucs in relations: |
f85816af6294
obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17469
diff
changeset
|
517 |
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
|
518 |
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
|
519 |
% 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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
raise util.Abort("changeset %s cannot obsolete itself" % 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
|
524 |
repo.obsstore.create(tr, nprec, nsucs, flag, 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
|
525 |
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
|
526 |
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
|
527 |
tr.release() |