annotate mercurial/metadata.py @ 45660:e66db30f95a8

salvaged: explicitly skip salvaged file while encoding This is a temporary measure to avoid diverging test cases (between commit time sidedata and upgraded sidedata) while we implement salvaged tracking in the different cases. This will be dropped soon. Differential Revision: https://phab.mercurial-scm.org/D9122
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 30 Sep 2020 12:46:49 +0200
parents a475db79d84d
children cf474af69766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 # metadata.py -- code related to various metadata computation and access.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 #
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 # Copyright 2019 Google, Inc <martinvonz@google.com>
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 # Copyright 2020 Pierre-Yves David <pierre-yves.david@octobus.net>
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 #
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 from __future__ import absolute_import, print_function
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10 import multiprocessing
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
11 import struct
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13 from . import (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14 error,
44941
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
15 node,
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16 pycompat,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
17 util,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
18 )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
20 from .revlogutils import (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21 flagutil as sidedataflag,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 sidedata as sidedatamod,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
23 )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
26 class ChangingFiles(object):
45621
646a676f5365 changing-files: fix docstring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45613
diff changeset
27 """A class recording the changes made to files by a changeset
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
28
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
29 Actions performed on files are gathered into 3 sets:
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
30
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
31 - added: files actively added in the changeset.
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
32 - merged: files whose history got merged
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
33 - removed: files removed in the revision
45659
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
34 - salvaged: files that might have been deleted by a merge but were not
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
35 - touched: files affected by the merge
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
36
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
37 and copies information is held by 2 mappings
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
38
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
39 - copied_from_p1: {"<new-name>": "<source-name-in-p1>"} mapping for copies
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
40 - copied_from_p2: {"<new-name>": "<source-name-in-p2>"} mapping for copies
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
41
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
42 See their inline help for details.
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
43 """
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
44
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
45 def __init__(
45589
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
46 self,
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
47 touched=None,
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
48 added=None,
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
49 removed=None,
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
50 merged=None,
45659
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
51 salvaged=None,
45589
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
52 p1_copies=None,
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
53 p2_copies=None,
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
54 ):
45589
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
55 self._added = set(() if added is None else added)
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
56 self._merged = set(() if merged is None else merged)
45589
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
57 self._removed = set(() if removed is None else removed)
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
58 self._touched = set(() if touched is None else touched)
45659
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
59 self._salvaged = set(() if salvaged is None else salvaged)
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
60 self._touched.update(self._added)
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
61 self._touched.update(self._merged)
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
62 self._touched.update(self._removed)
45589
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
63 self._p1_copies = dict(() if p1_copies is None else p1_copies)
3d5b2b8e93fd changing-files: move default constructor value to None
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45571
diff changeset
64 self._p2_copies = dict(() if p2_copies is None else p2_copies)
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
65
45507
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
66 def __eq__(self, other):
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
67 return (
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
68 self.added == other.added
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
69 and self.merged == other.merged
45507
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
70 and self.removed == other.removed
45659
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
71 and self.salvaged == other.salvaged
45507
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
72 and self.touched == other.touched
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
73 and self.copied_from_p1 == other.copied_from_p1
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
74 and self.copied_from_p2 == other.copied_from_p2
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
75 )
df87821081ee changing-files: implement equality checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45506
diff changeset
76
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
77 @util.propertycache
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
78 def added(self):
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
79 """files actively added in the changeset
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
80
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
81 Any file present in that revision that was absent in all the changeset's
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
82 parents.
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
83
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
84 In case of merge, this means a file absent in one of the parents but
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
85 existing in the other will *not* be contained in this set. (They were
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
86 added by an ancestor)
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
87 """
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
88 return frozenset(self._added)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
89
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
90 def mark_added(self, filename):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
91 if 'added' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
92 del self.added
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
93 self._added.add(filename)
45622
42bb6c4f8106 changing-files: always use `mark_touched` to update the touched set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45621
diff changeset
94 self.mark_touched(filename)
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
95
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
96 def update_added(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
97 for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
98 self.mark_added(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
99
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
100 @util.propertycache
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
101 def merged(self):
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
102 """files actively merged during a merge
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
103
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
104 Any modified files which had modification on both size that needed merging.
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
105
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
106 In this case a new filenode was created and it has two parents.
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
107 """
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
108 return frozenset(self._merged)
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
109
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
110 def mark_merged(self, filename):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
111 if 'merged' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
112 del self.merged
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
113 self._merged.add(filename)
45622
42bb6c4f8106 changing-files: always use `mark_touched` to update the touched set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45621
diff changeset
114 self.mark_touched(filename)
45611
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
115
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
116 def update_merged(self, filenames):
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
117 for f in filenames:
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
118 self.mark_merged(f)
e5578dbe36cb changing-files: add the ability to track merged files too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45589
diff changeset
119
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
120 @util.propertycache
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
121 def removed(self):
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
122 """files actively removed by the changeset
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
123
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
124 In case of merge this will only contain the set of files removing "new"
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
125 content. For any file absent in the current changeset:
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
126
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
127 a) If the file exists in both parents, it is clearly "actively" removed
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
128 by this changeset.
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
129
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
130 b) If a file exists in only one parent and in none of the common
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
131 ancestors, then the file was newly added in one of the merged branches
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
132 and then got "actively" removed.
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
133
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
134 c) If a file exists in only one parent and at least one of the common
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
135 ancestors using the same filenode, then the file was unchanged on one
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
136 side and deleted on the other side. The merge "passively" propagated
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
137 that deletion, but didn't "actively" remove the file. In this case the
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
138 file is *not* included in the `removed` set.
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
139
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
140 d) If a file exists in only one parent and at least one of the common
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
141 ancestors using a different filenode, then the file was changed on one
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
142 side and removed on the other side. The merge process "actively"
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
143 decided to drop the new change and delete the file. Unlike in the
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
144 previous case, (c), the file included in the `removed` set.
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
145
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
146 Summary table for merge:
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
147
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
148 case | exists in parents | exists in gca || removed
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
149 (a) | both | * || yes
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
150 (b) | one | none || yes
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
151 (c) | one | same filenode || no
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
152 (d) | one | new filenode || yes
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
153 """
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
154 return frozenset(self._removed)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
155
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
156 def mark_removed(self, filename):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
157 if 'removed' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
158 del self.removed
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
159 self._removed.add(filename)
45622
42bb6c4f8106 changing-files: always use `mark_touched` to update the touched set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45621
diff changeset
160 self.mark_touched(filename)
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
161
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
162 def update_removed(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
163 for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
164 self.mark_removed(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
165
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
166 @util.propertycache
45659
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
167 def salvaged(self):
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
168 """files that might have been deleted by a merge, but still exists.
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
169
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
170 During a merge, the manifest merging might select some files for
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
171 removal, or for a removed/changed conflict. If at commit time the file
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
172 still exists, its removal was "reverted" and the file is "salvaged"
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
173 """
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
174 return frozenset(self._salvaged)
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
175
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
176 def mark_salvaged(self, filename):
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
177 if "salvaged" in vars(self):
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
178 del self.salvaged
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
179 self._salvaged.add(filename)
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
180 self.mark_touched(filename)
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
181
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
182 def update_salvaged(self, filenames):
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
183 for f in filenames:
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
184 self.mark_salvaged(f)
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
185
a475db79d84d changing-files: add a "salvaged" set to track file that were not removed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45635
diff changeset
186 @util.propertycache
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
187 def touched(self):
45506
1f50bcc96595 changing-files: document the various sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45325
diff changeset
188 """files either actively modified, added or removed"""
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
189 return frozenset(self._touched)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
190
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
191 def mark_touched(self, filename):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
192 if 'touched' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
193 del self.touched
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
194 self._touched.add(filename)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
195
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
196 def update_touched(self, filenames):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
197 for f in filenames:
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
198 self.mark_touched(f)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
199
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
200 @util.propertycache
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
201 def copied_from_p1(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
202 return self._p1_copies.copy()
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
203
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
204 def mark_copied_from_p1(self, source, dest):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
205 if 'copied_from_p1' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
206 del self.copied_from_p1
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
207 self._p1_copies[dest] = source
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
208
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
209 def update_copies_from_p1(self, copies):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
210 for dest, source in copies.items():
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
211 self.mark_copied_from_p1(source, dest)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
212
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
213 @util.propertycache
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
214 def copied_from_p2(self):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
215 return self._p2_copies.copy()
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
216
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
217 def mark_copied_from_p2(self, source, dest):
45623
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
218 if 'copied_from_p2' in vars(self):
d31483377673 changing-files: cache the various property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45622
diff changeset
219 del self.copied_from_p2
45323
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
220 self._p2_copies[dest] = source
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
221
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
222 def update_copies_from_p2(self, copies):
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
223 for dest, source in copies.items():
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
224 self.mark_copied_from_p2(source, dest)
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
225
aea6a812f7cb commitctx: return a richer object from _prepare_files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44942
diff changeset
226
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
227 def computechangesetfilesadded(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
228 """return the list of files added in a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
229 """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
230 added = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
231 for f in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
232 if not any(f in p for p in ctx.parents()):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
233 added.append(f)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
234 return added
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
235
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
236
44941
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
237 def get_removal_filter(ctx, x=None):
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
238 """return a function to detect files "wrongly" detected as `removed`
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
239
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
240 When a file is removed relative to p1 in a merge, this
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
241 function determines whether the absence is due to a
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
242 deletion from a parent, or whether the merge commit
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
243 itself deletes the file. We decide this by doing a
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
244 simplified three way merge of the manifest entry for
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
245 the file. There are two ways we decide the merge
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
246 itself didn't delete a file:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
247 - neither parent (nor the merge) contain the file
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
248 - exactly one parent contains the file, and that
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
249 parent has the same filelog entry as the merge
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
250 ancestor (or all of them if there two). In other
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
251 words, that parent left the file unchanged while the
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
252 other one deleted it.
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
253 One way to think about this is that deleting a file is
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
254 similar to emptying it, so the list of changed files
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
255 should be similar either way. The computation
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
256 described above is not done directly in _filecommit
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
257 when creating the list of changed files, however
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
258 it does something very similar by comparing filelog
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
259 nodes.
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
260 """
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
261
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
262 if x is not None:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
263 p1, p2, m1, m2 = x
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
264 else:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
265 p1 = ctx.p1()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
266 p2 = ctx.p2()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
267 m1 = p1.manifest()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
268 m2 = p2.manifest()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
269
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
270 @util.cachefunc
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
271 def mas():
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
272 p1n = p1.node()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
273 p2n = p2.node()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
274 cahs = ctx.repo().changelog.commonancestorsheads(p1n, p2n)
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
275 if not cahs:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
276 cahs = [node.nullrev]
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
277 return [ctx.repo()[r].manifest() for r in cahs]
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
278
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
279 def deletionfromparent(f):
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
280 if f in m1:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
281 return f not in m2 and all(
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
282 f in ma and ma.find(f) == m1.find(f) for ma in mas()
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
283 )
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
284 elif f in m2:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
285 return all(f in ma and ma.find(f) == m2.find(f) for ma in mas())
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
286 else:
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
287 return True
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
288
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
289 return deletionfromparent
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
290
edd08aa193fb files: extract code for extra filtering of the `removed` entry into copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44940
diff changeset
291
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
292 def computechangesetfilesremoved(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
293 """return the list of files removed in a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
294 """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
295 removed = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
296 for f in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
297 if f not in ctx:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
298 removed.append(f)
44942
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
299 if removed:
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
300 rf = get_removal_filter(ctx)
25512a65cefd metadata: filter the `removed` set to only contains relevant data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44941
diff changeset
301 removed = [r for r in removed if not rf(r)]
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
302 return removed
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
303
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
304
45613
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
305 def computechangesetfilesmerged(ctx):
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
306 """return the list of files merged in a changeset
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
307 """
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
308 merged = []
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
309 if len(ctx.parents()) < 2:
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
310 return merged
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
311 for f in ctx.files():
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
312 if f in ctx:
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
313 fctx = ctx[f]
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
314 parents = fctx._filelog.parents(fctx._filenode)
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
315 if parents[1] != node.nullid:
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
316 merged.append(f)
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
317 return merged
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
318
ddcee0b0fd67 changing-files: add a utility to compute the merged files post-commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45611
diff changeset
319
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
320 def computechangesetcopies(ctx):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
321 """return the copies data for a changeset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
322
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
323 The copies data are returned as a pair of dictionnary (p1copies, p2copies).
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
324
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
325 Each dictionnary are in the form: `{newname: oldname}`
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
326 """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
327 p1copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
328 p2copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
329 p1 = ctx.p1()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
330 p2 = ctx.p2()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
331 narrowmatch = ctx._repo.narrowmatch()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
332 for dst in ctx.files():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
333 if not narrowmatch(dst) or dst not in ctx:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
334 continue
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
335 copied = ctx[dst].renamed()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
336 if not copied:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
337 continue
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
338 src, srcnode = copied
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
339 if src in p1 and p1[src].filenode() == srcnode:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
340 p1copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
341 elif src in p2 and p2[src].filenode() == srcnode:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
342 p2copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
343 return p1copies, p2copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
344
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
345
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
346 def encodecopies(files, copies):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
347 items = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
348 for i, dst in enumerate(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
349 if dst in copies:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
350 items.append(b'%d\0%s' % (i, copies[dst]))
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
351 if len(items) != len(copies):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
352 raise error.ProgrammingError(
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
353 b'some copy targets missing from file list'
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
354 )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
355 return b"\n".join(items)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
356
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
357
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
358 def decodecopies(files, data):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
359 try:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
360 copies = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
361 if not data:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
362 return copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
363 for l in data.split(b'\n'):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
364 strindex, src = l.split(b'\0')
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
365 i = int(strindex)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
366 dst = files[i]
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
367 copies[dst] = src
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
368 return copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
369 except (ValueError, IndexError):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
370 # Perhaps someone had chosen the same key name (e.g. "p1copies") and
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
371 # used different syntax for the value.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
372 return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
373
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
374
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
375 def encodefileindices(files, subset):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
376 subset = set(subset)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
377 indices = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
378 for i, f in enumerate(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
379 if f in subset:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
380 indices.append(b'%d' % i)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
381 return b'\n'.join(indices)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
382
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
383
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
384 def decodefileindices(files, data):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
385 try:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
386 subset = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
387 if not data:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
388 return subset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
389 for strindex in data.split(b'\n'):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
390 i = int(strindex)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
391 if i < 0 or i >= len(files):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
392 return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
393 subset.append(files[i])
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
394 return subset
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
395 except (ValueError, IndexError):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
396 # Perhaps someone had chosen the same key name (e.g. "added") and
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
397 # used different syntax for the value.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
398 return None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
399
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
400
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
401 # see mercurial/helptext/internals/revlogs.txt for details about the format
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
402
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
403 ACTION_MASK = int("111" "00", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
404 # note: untouched file used as copy source will as `000` for this mask.
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
405 ADDED_FLAG = int("001" "00", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
406 MERGED_FLAG = int("010" "00", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
407 REMOVED_FLAG = int("011" "00", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
408 # `100` is reserved for future use
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
409 TOUCHED_FLAG = int("101" "00", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
410
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
411 COPIED_MASK = int("11", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
412 COPIED_FROM_P1_FLAG = int("10", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
413 COPIED_FROM_P2_FLAG = int("11", 2)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
414
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
415 # structure is <flag><filename-end><copy-source>
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
416 INDEX_HEADER = struct.Struct(">L")
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
417 INDEX_ENTRY = struct.Struct(">bLL")
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
418
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
419
45569
64d18e9e8508 sidedata: rename `encode_copies_sidedata` to `encode_files_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45507
diff changeset
420 def encode_files_sidedata(files):
45660
e66db30f95a8 salvaged: explicitly skip salvaged file while encoding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45659
diff changeset
421 all_files = set(files.touched - files.salvaged)
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
422 all_files.update(files.copied_from_p1.values())
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
423 all_files.update(files.copied_from_p2.values())
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
424 all_files = sorted(all_files)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
425 file_idx = {f: i for (i, f) in enumerate(all_files)}
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
426 file_idx[None] = 0
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
427
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
428 chunks = [INDEX_HEADER.pack(len(all_files))]
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
429
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
430 filename_length = 0
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
431 for f in all_files:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
432 filename_size = len(f)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
433 filename_length += filename_size
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
434 flag = 0
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
435 if f in files.added:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
436 flag |= ADDED_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
437 elif f in files.merged:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
438 flag |= MERGED_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
439 elif f in files.removed:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
440 flag |= REMOVED_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
441 elif f in files.touched:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
442 flag |= TOUCHED_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
443
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
444 copy = None
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
445 if f in files.copied_from_p1:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
446 flag |= COPIED_FROM_P1_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
447 copy = files.copied_from_p1.get(f)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
448 elif f in files.copied_from_p2:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
449 copy = files.copied_from_p2.get(f)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
450 flag |= COPIED_FROM_P2_FLAG
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
451 copy_idx = file_idx[copy]
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
452 chunks.append(INDEX_ENTRY.pack(flag, filename_length, copy_idx))
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
453 chunks.extend(all_files)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
454 return {sidedatamod.SD_FILES: b''.join(chunks)}
45325
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
455
c6eea5804551 commitctx: extract sidedata encoding inside its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45323
diff changeset
456
45635
9003e6524f78 changing-files: drop the now useless changelogrevision argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45634
diff changeset
457 def decode_files_sidedata(sidedata):
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
458 md = ChangingFiles()
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
459 raw = sidedata.get(sidedatamod.SD_FILES)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
460
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
461 if raw is None:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
462 return md
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
463
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
464 copies = []
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
465 all_files = []
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
466
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
467 assert len(raw) >= INDEX_HEADER.size
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
468 total_files = INDEX_HEADER.unpack_from(raw, 0)[0]
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
469
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
470 offset = INDEX_HEADER.size
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
471 file_offset_base = offset + (INDEX_ENTRY.size * total_files)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
472 file_offset_last = file_offset_base
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
473
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
474 assert len(raw) >= file_offset_base
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
475
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
476 for idx in range(total_files):
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
477 flag, file_end, copy_idx = INDEX_ENTRY.unpack_from(raw, offset)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
478 file_end += file_offset_base
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
479 filename = raw[file_offset_last:file_end]
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
480 filesize = file_end - file_offset_last
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
481 assert len(filename) == filesize
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
482 offset += INDEX_ENTRY.size
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
483 file_offset_last = file_end
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
484 all_files.append(filename)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
485 if flag & ACTION_MASK == ADDED_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
486 md.mark_added(filename)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
487 elif flag & ACTION_MASK == MERGED_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
488 md.mark_merged(filename)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
489 elif flag & ACTION_MASK == REMOVED_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
490 md.mark_removed(filename)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
491 elif flag & ACTION_MASK == TOUCHED_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
492 md.mark_touched(filename)
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
493
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
494 copied = None
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
495 if flag & COPIED_MASK == COPIED_FROM_P1_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
496 copied = md.mark_copied_from_p1
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
497 elif flag & COPIED_MASK == COPIED_FROM_P2_FLAG:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
498 copied = md.mark_copied_from_p2
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
499
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
500 if copied is not None:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
501 copies.append((copied, filename, copy_idx))
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
502
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
503 for copied, filename, copy_idx in copies:
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
504 copied(all_files[copy_idx], filename)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
505
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
506 return md
45571
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
507
7543b5072e84 sidedata: add a `decode_files_sidedata` function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45569
diff changeset
508
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
509 def _getsidedata(srcrepo, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
510 ctx = srcrepo[rev]
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
511 filescopies = computechangesetcopies(ctx)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
512 filesadded = computechangesetfilesadded(ctx)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
513 filesremoved = computechangesetfilesremoved(ctx)
45634
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
514 filesmerged = computechangesetfilesmerged(ctx)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
515 files = ChangingFiles()
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
516 files.update_touched(ctx.files())
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
517 files.update_added(filesadded)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
518 files.update_removed(filesremoved)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
519 files.update_merged(filesmerged)
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
520 files.update_copies_from_p1(filescopies[0])
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
521 files.update_copies_from_p2(filescopies[1])
9a6b409b8ebc changing-files: rework the way we store changed files in side-data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45623
diff changeset
522 return encode_files_sidedata(files)
44940
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
523
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
524
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
525 def getsidedataadder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
526 use_w = srcrepo.ui.configbool(b'experimental', b'worker.repository-upgrade')
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
527 if pycompat.iswindows or not use_w:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
528 return _get_simple_sidedata_adder(srcrepo, destrepo)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
529 else:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
530 return _get_worker_sidedata_adder(srcrepo, destrepo)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
531
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
532
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
533 def _sidedata_worker(srcrepo, revs_queue, sidedata_queue, tokens):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
534 """The function used by worker precomputing sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
535
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
536 It read an input queue containing revision numbers
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
537 It write in an output queue containing (rev, <sidedata-map>)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
538
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
539 The `None` input value is used as a stop signal.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
540
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
541 The `tokens` semaphore is user to avoid having too many unprocessed
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
542 entries. The workers needs to acquire one token before fetching a task.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
543 They will be released by the consumer of the produced data.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
544 """
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
545 tokens.acquire()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
546 rev = revs_queue.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
547 while rev is not None:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
548 data = _getsidedata(srcrepo, rev)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
549 sidedata_queue.put((rev, data))
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
550 tokens.acquire()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
551 rev = revs_queue.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
552 # processing of `None` is completed, release the token.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
553 tokens.release()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
554
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
555
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
556 BUFF_PER_WORKER = 50
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
557
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
558
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
559 def _get_worker_sidedata_adder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
560 """The parallel version of the sidedata computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
561
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
562 This code spawn a pool of worker that precompute a buffer of sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
563 before we actually need them"""
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
564 # avoid circular import copies -> scmutil -> worker -> copies
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
565 from . import worker
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
566
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
567 nbworkers = worker._numworkers(srcrepo.ui)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
568
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
569 tokens = multiprocessing.BoundedSemaphore(nbworkers * BUFF_PER_WORKER)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
570 revsq = multiprocessing.Queue()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
571 sidedataq = multiprocessing.Queue()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
572
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
573 assert srcrepo.filtername is None
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
574 # queue all tasks beforehand, revision numbers are small and it make
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
575 # synchronisation simpler
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
576 #
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
577 # Since the computation for each node can be quite expensive, the overhead
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
578 # of using a single queue is not revelant. In practice, most computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
579 # are fast but some are very expensive and dominate all the other smaller
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
580 # cost.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
581 for r in srcrepo.changelog.revs():
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
582 revsq.put(r)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
583 # queue the "no more tasks" markers
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
584 for i in range(nbworkers):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
585 revsq.put(None)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
586
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
587 allworkers = []
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
588 for i in range(nbworkers):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
589 args = (srcrepo, revsq, sidedataq, tokens)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
590 w = multiprocessing.Process(target=_sidedata_worker, args=args)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
591 allworkers.append(w)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
592 w.start()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
593
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
594 # dictionnary to store results for revision higher than we one we are
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
595 # looking for. For example, if we need the sidedatamap for 42, and 43 is
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
596 # received, when shelve 43 for later use.
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
597 staging = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
598
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
599 def sidedata_companion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
600 sidedata = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
601 if util.safehasattr(revlog, b'filteredrevs'): # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
602 # Is the data previously shelved ?
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
603 sidedata = staging.pop(rev, None)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
604 if sidedata is None:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
605 # look at the queued result until we find the one we are lookig
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
606 # for (shelve the other ones)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
607 r, sidedata = sidedataq.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
608 while r != rev:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
609 staging[r] = sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
610 r, sidedata = sidedataq.get()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
611 tokens.release()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
612 return False, (), sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
613
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
614 return sidedata_companion
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
615
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
616
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
617 def _get_simple_sidedata_adder(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
618 """The simple version of the sidedata computation
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
619
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
620 It just compute it in the same thread on request"""
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
621
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
622 def sidedatacompanion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
623 sidedata = {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
624 if util.safehasattr(revlog, 'filteredrevs'): # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
625 sidedata = _getsidedata(srcrepo, rev)
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
626 return False, (), sidedata
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
627
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
628 return sidedatacompanion
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
629
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
630
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
631 def getsidedataremover(srcrepo, destrepo):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
632 def sidedatacompanion(revlog, rev):
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
633 f = ()
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
634 if util.safehasattr(revlog, 'filteredrevs'): # this is a changelog
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
635 if revlog.flags(rev) & sidedataflag.REVIDX_SIDEDATA:
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
636 f = (
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
637 sidedatamod.SD_P1COPIES,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
638 sidedatamod.SD_P2COPIES,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
639 sidedatamod.SD_FILESADDED,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
640 sidedatamod.SD_FILESREMOVED,
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
641 )
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
642 return False, f, {}
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
643
4c1d39215034 metadata: move computation related to files touched in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
644 return sidedatacompanion