Mercurial > hg
annotate mercurial/mergestate.py @ 48815:e9ca736f5b52
cext: remove Python 2 file handling code
Differential Revision: https://phab.mercurial-scm.org/D12226
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Feb 2022 15:45:51 -0700 |
parents | 93d6f0e7ba2f |
children | 6000f5b25c9b |
rev | line source |
---|---|
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
1 from __future__ import absolute_import |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
2 |
45381
ede4c121239e
mergestate: use collections.defaultdict(dict) for _stateextras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45302
diff
changeset
|
3 import collections |
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
4 import errno |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
5 import shutil |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
6 import struct |
48712
773ad0f5152d
merge-actions: gather all created action into a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48711
diff
changeset
|
7 import weakref |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
8 |
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
9 from .i18n import _ |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
10 from .node import ( |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
11 bin, |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
12 hex, |
46843
728d89f6f9b1
refactor: prefer checks against nullrev over nullid
Joerg Sonnenberger <joerg@bec.de>
parents:
46781
diff
changeset
|
13 nullrev, |
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
14 ) |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
15 from . import ( |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26570
diff
changeset
|
16 error, |
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
17 filemerge, |
30519
20a42325fdef
py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30486
diff
changeset
|
18 pycompat, |
25959
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
19 util, |
892d601f0d44
merge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25844
diff
changeset
|
20 ) |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43798
diff
changeset
|
21 from .utils import hashutil |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
22 |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
23 _pack = struct.pack |
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
24 _unpack = struct.unpack |
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
25 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
26 |
20593
3678707e4017
merge: add "other" file node in the merge state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20592
diff
changeset
|
27 def _droponode(data): |
3678707e4017
merge: add "other" file node in the merge state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20592
diff
changeset
|
28 # used for compatibility for v1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
29 bits = data.split(b'\0') |
20593
3678707e4017
merge: add "other" file node in the merge state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20592
diff
changeset
|
30 bits = bits[:-2] + bits[-1:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
31 return b'\0'.join(bits) |
20593
3678707e4017
merge: add "other" file node in the merge state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20592
diff
changeset
|
32 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
33 |
44871
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
34 def _filectxorabsent(hexnode, ctx, f): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
35 if hexnode == ctx.repo().nodeconstants.nullhex: |
44871
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
36 return filemerge.absentfilectx(ctx, f) |
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
37 else: |
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
38 return ctx[f] |
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
39 |
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
40 |
37109
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
41 # Merge state record types. See ``mergestate`` docs for more. |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
42 |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
43 #### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
44 # merge records which records metadata about a current merge |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
45 # exists only once in a mergestate |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
46 ##### |
37109
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
47 RECORD_LOCAL = b'L' |
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
48 RECORD_OTHER = b'O' |
45161
9abdc0bd2ab9
mergestate: add comments about couple of record types and minor reorder
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45160
diff
changeset
|
49 # record merge labels |
9abdc0bd2ab9
mergestate: add comments about couple of record types and minor reorder
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45160
diff
changeset
|
50 RECORD_LABELS = b'l' |
9abdc0bd2ab9
mergestate: add comments about couple of record types and minor reorder
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45160
diff
changeset
|
51 |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
52 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
53 # record extra information about files, with one entry containing info about one |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
54 # file. Hence, multiple of them can exists |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
55 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
56 RECORD_FILE_VALUES = b'f' |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
57 |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
58 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
59 # merge records which represents state of individual merges of files/folders |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
60 # These are top level records for each entry containing merge related info. |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
61 # Each record of these has info about one file. Hence multiple of them can |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
62 # exists |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
63 ##### |
37109
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
64 RECORD_MERGED = b'F' |
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
65 RECORD_CHANGEDELETE_CONFLICT = b'C' |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
66 # the path was dir on one side of merge and file on another |
37109
a532b2f54f95
merge: use constants for merge state record types
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37107
diff
changeset
|
67 RECORD_PATH_CONFLICT = b'P' |
45161
9abdc0bd2ab9
mergestate: add comments about couple of record types and minor reorder
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45160
diff
changeset
|
68 |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
69 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
70 # possible state which a merge entry can have. These are stored inside top-level |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
71 # merge records mentioned just above. |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
72 ##### |
37111
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
73 MERGE_RECORD_UNRESOLVED = b'u' |
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
74 MERGE_RECORD_RESOLVED = b'r' |
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
75 MERGE_RECORD_UNRESOLVED_PATH = b'pu' |
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
76 MERGE_RECORD_RESOLVED_PATH = b'pr' |
44687
1b8fd4af3318
mergestate: store about files resolved in favour of other
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
77 # represents that the file was automatically merged in favor |
1b8fd4af3318
mergestate: store about files resolved in favour of other
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
78 # of other version. This info is used on commit. |
45382
0652a533fe3c
mergestate: use _stateextras instead of merge records for commit related info
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45381
diff
changeset
|
79 # This is now deprecated and commit related information is now |
0652a533fe3c
mergestate: use _stateextras instead of merge records for commit related info
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45381
diff
changeset
|
80 # stored in RECORD_FILE_VALUES |
44687
1b8fd4af3318
mergestate: store about files resolved in favour of other
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
81 MERGE_RECORD_MERGED_OTHER = b'o' |
37111
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
82 |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
83 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
84 # top level record which stores other unknown records. Multiple of these can |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
85 # exists |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
86 ##### |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
87 RECORD_OVERRIDE = b't' |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
88 |
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
89 ##### |
45271
7fc3c5fbc65f
mergestate: fix BC breakage introduced because of removal of a merge record
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45166
diff
changeset
|
90 # legacy records which are no longer used but kept to prevent breaking BC |
7fc3c5fbc65f
mergestate: fix BC breakage introduced because of removal of a merge record
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45166
diff
changeset
|
91 ##### |
7fc3c5fbc65f
mergestate: fix BC breakage introduced because of removal of a merge record
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45166
diff
changeset
|
92 # This record was release in 5.4 and usage was removed in 5.5 |
7fc3c5fbc65f
mergestate: fix BC breakage introduced because of removal of a merge record
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45166
diff
changeset
|
93 LEGACY_RECORD_RESOLVED_OTHER = b'R' |
45518
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
94 # This record was release in 3.7 and usage was removed in 5.6 |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
95 LEGACY_RECORD_DRIVER_RESOLVED = b'd' |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
96 # This record was release in 3.7 and usage was removed in 5.6 |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
97 LEGACY_MERGE_DRIVER_STATE = b'm' |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
98 # This record was release in 3.7 and usage was removed in 5.6 |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
99 LEGACY_MERGE_DRIVER_MERGE = b'D' |
45271
7fc3c5fbc65f
mergestate: fix BC breakage introduced because of removal of a merge record
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45166
diff
changeset
|
100 |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
101 CHANGE_ADDED = b'added' |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
102 CHANGE_REMOVED = b'removed' |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
103 CHANGE_MODIFIED = b'modified' |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
104 |
45163
f69253935bf8
mergestate: document mergestate records in an organized way
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45162
diff
changeset
|
105 |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
106 class MergeAction(object): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
107 """represent an "action" merge need to take for a given file |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
108 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
109 Attributes: |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
110 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
111 _short: internal representation used to identify each action |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
112 |
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
113 no_op: True if the action does affect the file content or tracking status |
48714
c5f05c0d1c8c
merge-actions: have an attribute for narrow safetiness
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48713
diff
changeset
|
114 |
c5f05c0d1c8c
merge-actions: have an attribute for narrow safetiness
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48713
diff
changeset
|
115 narrow_safe: |
c5f05c0d1c8c
merge-actions: have an attribute for narrow safetiness
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48713
diff
changeset
|
116 True if the action can be safely used for a file outside of the narrow |
c5f05c0d1c8c
merge-actions: have an attribute for narrow safetiness
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48713
diff
changeset
|
117 set |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
118 |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
119 changes: |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
120 The types of changes that this actions involves. This is a work in |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
121 progress and not all actions have one yet. In addition, some requires |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
122 user changes and cannot be fully decided. The value currently available |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
123 are: |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
124 |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
125 - ADDED: the files is new in both parents |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
126 - REMOVED: the files existed in one parent and is getting removed |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
127 - MODIFIED: the files existed in at least one parent and is getting changed |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
128 """ |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
129 |
48712
773ad0f5152d
merge-actions: gather all created action into a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48711
diff
changeset
|
130 ALL_ACTIONS = weakref.WeakSet() |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
131 NO_OP_ACTIONS = weakref.WeakSet() |
48712
773ad0f5152d
merge-actions: gather all created action into a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48711
diff
changeset
|
132 |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
133 def __init__(self, short, no_op=False, narrow_safe=False, changes=None): |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
134 self._short = short |
48712
773ad0f5152d
merge-actions: gather all created action into a set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48711
diff
changeset
|
135 self.ALL_ACTIONS.add(self) |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
136 self.no_op = no_op |
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
137 if self.no_op: |
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
138 self.NO_OP_ACTIONS.add(self) |
48714
c5f05c0d1c8c
merge-actions: have an attribute for narrow safetiness
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48713
diff
changeset
|
139 self.narrow_safe = narrow_safe |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
140 self.changes = changes |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
141 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
142 def __hash__(self): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
143 return hash(self._short) |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
144 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
145 def __repr__(self): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
146 return 'MergeAction<%s>' % self._short.decode('ascii') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
147 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
148 def __bytes__(self): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
149 return self._short |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
150 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
151 def __eq__(self, other): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
152 if other is None: |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
153 return False |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
154 assert isinstance(other, MergeAction) |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
155 return self._short == other._short |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
156 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
157 def __lt__(self, other): |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
158 return self._short < other._short |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
159 |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
160 |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
161 ACTION_FORGET = MergeAction(b'f', narrow_safe=True, changes=CHANGE_REMOVED) |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
162 ACTION_REMOVE = MergeAction(b'r', narrow_safe=True, changes=CHANGE_REMOVED) |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
163 ACTION_ADD = MergeAction(b'a', narrow_safe=True, changes=CHANGE_ADDED) |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
164 ACTION_GET = MergeAction(b'g', narrow_safe=True, changes=CHANGE_MODIFIED) |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
165 ACTION_PATH_CONFLICT = MergeAction(b'p') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
166 ACTION_PATH_CONFLICT_RESOLVE = MergeAction('pr') |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
167 ACTION_ADD_MODIFIED = MergeAction( |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
168 b'am', narrow_safe=True, changes=CHANGE_ADDED |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
169 ) # not 100% about the changes value here |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
170 ACTION_CREATED = MergeAction(b'c', narrow_safe=True, changes=CHANGE_ADDED) |
48711
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
171 ACTION_DELETED_CHANGED = MergeAction(b'dc') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
172 ACTION_CHANGED_DELETED = MergeAction(b'cd') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
173 ACTION_MERGE = MergeAction(b'm') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
174 ACTION_LOCAL_DIR_RENAME_GET = MergeAction(b'dg') |
9bc86adf32f6
merge-actions: make merge action a full featured object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48710
diff
changeset
|
175 ACTION_DIR_RENAME_MOVE_LOCAL = MergeAction(b'dm') |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
176 ACTION_KEEP = MergeAction(b'k', no_op=True) |
45467
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
177 # the file was absent on local side before merge and we should |
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
178 # keep it absent (absent means file not present, it can be a result |
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
179 # of file deletion, rename etc.) |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
180 ACTION_KEEP_ABSENT = MergeAction(b'ka', no_op=True) |
45524
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
181 # the file is absent on the ancestor and remote side of the merge |
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
182 # hence this file is new and we should keep it |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48712
diff
changeset
|
183 ACTION_KEEP_NEW = MergeAction(b'kn', no_op=True) |
48715
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
184 ACTION_EXEC = MergeAction(b'e', narrow_safe=True, changes=CHANGE_MODIFIED) |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
185 ACTION_CREATED_MERGE = MergeAction( |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
186 b'cm', narrow_safe=True, changes=CHANGE_ADDED |
7d073df49a54
merge-actions: add some information about the "changes" the action do
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48714
diff
changeset
|
187 ) |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
188 |
45525
590a840fa367
mergestate: define NO_OP_ACTION in module scope instead of inside mergeresult
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45524
diff
changeset
|
189 |
48710
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
190 # Used by concert to detect situation it does not like, not sure what the exact |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
191 # criteria is |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
192 CONVERT_MERGE_ACTIONS = ( |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
193 ACTION_MERGE, |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
194 ACTION_DIR_RENAME_MOVE_LOCAL, |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
195 ACTION_CHANGED_DELETED, |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
196 ACTION_DELETED_CHANGED, |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
197 ) |
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48506
diff
changeset
|
198 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
199 |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
200 class _mergestate_base(object): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45715
diff
changeset
|
201 """track 3-way merge state of individual files |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
202 |
27022
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
203 The merge state is stored on disk when needed. Two files are used: one with |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
204 an old format (version 1), and one with a new format (version 2). Version 2 |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
205 stores a superset of the data in version 1, including new kinds of records |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
206 in the future. For more about the new format, see the documentation for |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
207 `_readrecordsv2`. |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
208 |
27022
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
209 Each record can contain arbitrary content, and has an associated type. This |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
210 `type` should be a letter. If `type` is uppercase, the record is mandatory: |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
211 versions of Mercurial that don't support it should abort. If `type` is |
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
212 lowercase, the record can be safely ignored. |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
213 |
27022
35102876d648
mergestate: move binary format documentation into _readrecordsv2
Siddharth Agarwal <sid0@fb.com>
parents:
27006
diff
changeset
|
214 Currently known records: |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
215 |
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
216 L: the node of the "local" part of the merge (hexified version) |
20591
02c60e380fd0
merge: record the "other" node in merge state
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20590
diff
changeset
|
217 O: the node of the "other" part of the merge (hexified version) |
20590
2b7d54e929b4
merge: introduce new format for the state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20589
diff
changeset
|
218 F: a file to be merged entry |
27031
8be0af32e513
mergestate: allow storing and retrieving change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27027
diff
changeset
|
219 C: a change/delete or delete/change conflict |
34545
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
220 P: a path conflict (file vs directory) |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30200
diff
changeset
|
221 f: a (filename, dictionary) tuple of optional values for a given file |
28634
3ceac01bc29f
merge: save merge part labels for later reuse
Simon Farnsworth <simonfar@fb.com>
parents:
28267
diff
changeset
|
222 l: the labels for the parts of the merge. |
26649
f618b6aa8cdd
merge.mergestate: add support for persisting a custom merge driver
Siddharth Agarwal <sid0@fb.com>
parents:
26641
diff
changeset
|
223 |
34545
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
224 Merge record states (stored in self._state, indexed by filename): |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
225 u: unresolved conflict |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
226 r: resolved conflict |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
227 pu: unresolved path conflict (file conflicts with directory) |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
228 pr: resolved path conflict |
45714
ecf6d7aa874b
mergestate: document `o` merge record state in _mergestate_base docs
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45583
diff
changeset
|
229 o: file was merged in favor of other parent of merge (DEPRECATED) |
34545
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
230 |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
231 The resolve command transitions between 'u' and 'r' for conflicts and |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
232 'pu' and 'pr' for path conflicts. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45715
diff
changeset
|
233 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
234 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
235 def __init__(self, repo): |
27005
3185c01c551c
mergestate: move _read() call to read constructor
Siddharth Agarwal <sid0@fb.com>
parents:
26991
diff
changeset
|
236 """Initialize the merge state. |
3185c01c551c
mergestate: move _read() call to read constructor
Siddharth Agarwal <sid0@fb.com>
parents:
26991
diff
changeset
|
237 |
3185c01c551c
mergestate: move _read() call to read constructor
Siddharth Agarwal <sid0@fb.com>
parents:
26991
diff
changeset
|
238 Do not use this directly! Instead call read() or clean().""" |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
239 self._repo = repo |
45496
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
240 self._state = {} |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
241 self._stateextras = collections.defaultdict(dict) |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
242 self._local = None |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
243 self._other = None |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
244 self._labels = None |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
245 # contains a mapping of form: |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
246 # {filename : (merge_return_value, action_to_be_performed} |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
247 # these are results of re-running merge process |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
248 # this dict is used to perform actions on dirstate caused by re-running |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
249 # the merge |
ef3273ac5f6e
mergestate: initialize all properties in __init__()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45495
diff
changeset
|
250 self._results = {} |
12369
6f0d9d79111f
merge: delay writing the mergestate during until commit is called
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12279
diff
changeset
|
251 self._dirty = False |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
252 |
45492
08c6d6962b2a
mergestate: split up reset() for its two use cases
Martin von Zweigbergk <martinvonz@google.com>
parents:
45491
diff
changeset
|
253 def reset(self): |
45500
f2efc44213ec
mergestate: make in-memory mergestate not clear on-disk mergestate on reset()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45499
diff
changeset
|
254 pass |
45494
9ea4b52ac6bb
mergestate: move most of of reset() into start()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45493
diff
changeset
|
255 |
9ea4b52ac6bb
mergestate: move most of of reset() into start()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45493
diff
changeset
|
256 def start(self, node, other, labels=None): |
9ea4b52ac6bb
mergestate: move most of of reset() into start()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45493
diff
changeset
|
257 self._local = node |
9ea4b52ac6bb
mergestate: move most of of reset() into start()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45493
diff
changeset
|
258 self._other = other |
9ea4b52ac6bb
mergestate: move most of of reset() into start()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45493
diff
changeset
|
259 self._labels = labels |
26768
ac68769a5985
merge.mergestate: only check for merge driver when property is accessed
Siddharth Agarwal <sid0@fb.com>
parents:
26766
diff
changeset
|
260 |
26765
45976219eb80
merge.mergestate: add a way to get the other side of the merge
Siddharth Agarwal <sid0@fb.com>
parents:
26752
diff
changeset
|
261 @util.propertycache |
44215
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
262 def local(self): |
27130
6f045b563fa5
mergestate: add a cached property accessor for the local context
Siddharth Agarwal <sid0@fb.com>
parents:
27129
diff
changeset
|
263 if self._local is None: |
44215
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
264 msg = b"local accessed but self._local isn't set" |
31646 | 265 raise error.ProgrammingError(msg) |
44215
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
266 return self._local |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
267 |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
268 @util.propertycache |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
269 def localctx(self): |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
270 return self._repo[self.local] |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
271 |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
272 @util.propertycache |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
273 def other(self): |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
274 if self._other is None: |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
275 msg = b"other accessed but self._other isn't set" |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
276 raise error.ProgrammingError(msg) |
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
277 return self._other |
27130
6f045b563fa5
mergestate: add a cached property accessor for the local context
Siddharth Agarwal <sid0@fb.com>
parents:
27129
diff
changeset
|
278 |
6f045b563fa5
mergestate: add a cached property accessor for the local context
Siddharth Agarwal <sid0@fb.com>
parents:
27129
diff
changeset
|
279 @util.propertycache |
26765
45976219eb80
merge.mergestate: add a way to get the other side of the merge
Siddharth Agarwal <sid0@fb.com>
parents:
26752
diff
changeset
|
280 def otherctx(self): |
44215
b1069b369d6e
mergestate: add accessors for local and other nodeid, not just contexts
Martin von Zweigbergk <martinvonz@google.com>
parents:
44212
diff
changeset
|
281 return self._repo[self.other] |
26649
f618b6aa8cdd
merge.mergestate: add support for persisting a custom merge driver
Siddharth Agarwal <sid0@fb.com>
parents:
26641
diff
changeset
|
282 |
21264
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
283 def active(self): |
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
284 """Whether mergestate is active. |
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
285 |
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
286 Returns True if there appears to be mergestate. This is a rough proxy |
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
287 for "is a merge in progress." |
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
288 """ |
44394
5e3402a0b868
mergestate: determine if active without looking for state files on disk
Martin von Zweigbergk <martinvonz@google.com>
parents:
44383
diff
changeset
|
289 return bool(self._local) or bool(self._state) |
21264
4e932dc5c113
resolve: abort when not applicable (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21261
diff
changeset
|
290 |
12369
6f0d9d79111f
merge: delay writing the mergestate during until commit is called
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12279
diff
changeset
|
291 def commit(self): |
20652
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
292 """Write current state on disk (if necessary)""" |
27006
9d58dc193c46
mergestate.commit: factor out making the list of records
Siddharth Agarwal <sid0@fb.com>
parents:
27005
diff
changeset
|
293 |
41155
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
294 @staticmethod |
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
295 def getlocalkey(path): |
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
296 """hash the path of a local file context for storage in the .hg/merge |
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
297 directory.""" |
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
298 |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43798
diff
changeset
|
299 return hex(hashutil.sha1(path).digest()) |
41155
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
300 |
45497
e833ff4dd0ea
mergestate: extract overridable methods for making/restoring file backups
Martin von Zweigbergk <martinvonz@google.com>
parents:
45496
diff
changeset
|
301 def _make_backup(self, fctx, localkey): |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
302 raise NotImplementedError() |
45497
e833ff4dd0ea
mergestate: extract overridable methods for making/restoring file backups
Martin von Zweigbergk <martinvonz@google.com>
parents:
45496
diff
changeset
|
303 |
e833ff4dd0ea
mergestate: extract overridable methods for making/restoring file backups
Martin von Zweigbergk <martinvonz@google.com>
parents:
45496
diff
changeset
|
304 def _restore_backup(self, fctx, localkey, flags): |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
305 raise NotImplementedError() |
45497
e833ff4dd0ea
mergestate: extract overridable methods for making/restoring file backups
Martin von Zweigbergk <martinvonz@google.com>
parents:
45496
diff
changeset
|
306 |
18338
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
307 def add(self, fcl, fco, fca, fd): |
20652
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
308 """add a new (potentially?) conflicting file the merge state |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
309 fcl: file context for local, |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
310 fco: file context for remote, |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
311 fca: file context for ancestors, |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
312 fd: file path of the resulting merge. |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
313 |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
314 note: also write the local version to the `.hg/merge` directory. |
2a4871c2511d
merge: adds documentation to the mergestate class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20651
diff
changeset
|
315 """ |
27049
0d61f7ec7f76
mergestate.add: store absentfilectxes as nullhex
Siddharth Agarwal <sid0@fb.com>
parents:
27048
diff
changeset
|
316 if fcl.isabsent(): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
317 localkey = self._repo.nodeconstants.nullhex |
27049
0d61f7ec7f76
mergestate.add: store absentfilectxes as nullhex
Siddharth Agarwal <sid0@fb.com>
parents:
27048
diff
changeset
|
318 else: |
41155
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
319 localkey = mergestate.getlocalkey(fcl.path()) |
45497
e833ff4dd0ea
mergestate: extract overridable methods for making/restoring file backups
Martin von Zweigbergk <martinvonz@google.com>
parents:
45496
diff
changeset
|
320 self._make_backup(fcl, localkey) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
321 self._state[fd] = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
322 MERGE_RECORD_UNRESOLVED, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
323 localkey, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
324 fcl.path(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
325 fca.path(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
326 hex(fca.filenode()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
327 fco.path(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
328 hex(fco.filenode()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
329 fcl.flags(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
330 ] |
45583
9f14bb4d59ea
mergestate: update _stateextras instead of reassinging
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45525
diff
changeset
|
331 self._stateextras[fd][b'ancestorlinknode'] = hex(fca.node()) |
12369
6f0d9d79111f
merge: delay writing the mergestate during until commit is called
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12279
diff
changeset
|
332 self._dirty = True |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
333 |
45159
e05a488cbed0
mergestate: rename addpath() -> addpathonflict() to prevent confusion
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44939
diff
changeset
|
334 def addpathconflict(self, path, frename, forigin): |
34545
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
335 """add a new conflicting path to the merge state |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
336 path: the path that conflicts |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
337 frename: the filename the conflicting file was renamed to |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
338 forigin: origin of the file ('l' or 'r' for local/remote) |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
339 """ |
37111
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
340 self._state[path] = [MERGE_RECORD_UNRESOLVED_PATH, frename, forigin] |
34545
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
341 self._dirty = True |
1913162854f2
merge: add pathconflict merge state
Mark Thomas <mbthomas@fb.com>
parents:
34522
diff
changeset
|
342 |
45385
05d19ca33b33
mergestate: replace `addmergedother()` with generic `addcommitinfo()` (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45382
diff
changeset
|
343 def addcommitinfo(self, path, data): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45715
diff
changeset
|
344 """stores information which is required at commit |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45715
diff
changeset
|
345 into _stateextras""" |
45385
05d19ca33b33
mergestate: replace `addmergedother()` with generic `addcommitinfo()` (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45382
diff
changeset
|
346 self._stateextras[path].update(data) |
44687
1b8fd4af3318
mergestate: store about files resolved in favour of other
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
347 self._dirty = True |
1b8fd4af3318
mergestate: store about files resolved in favour of other
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
348 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
349 def __contains__(self, dfile): |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
350 return dfile in self._state |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
351 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
352 def __getitem__(self, dfile): |
6518 | 353 return self._state[dfile][0] |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
354 |
6518 | 355 def __iter__(self): |
21268
a0b8a912ec81
merge: simplify mergestate iter
Mads Kiilerich <mads@kiilerich.com>
parents:
21266
diff
changeset
|
356 return iter(sorted(self._state)) |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
357 |
19285
feaf5749d7a4
merge: add a files method to the mergestate class
Bryan O'Sullivan <bryano@fb.com>
parents:
19226
diff
changeset
|
358 def files(self): |
feaf5749d7a4
merge: add a files method to the mergestate class
Bryan O'Sullivan <bryano@fb.com>
parents:
19226
diff
changeset
|
359 return self._state.keys() |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
360 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6425
diff
changeset
|
361 def mark(self, dfile, state): |
6518 | 362 self._state[dfile][0] = state |
12369
6f0d9d79111f
merge: delay writing the mergestate during until commit is called
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
12279
diff
changeset
|
363 self._dirty = True |
20651
c1a52dd56eb4
merge: add blank line between mergestate's method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20642
diff
changeset
|
364 |
21266
19d6fec60b81
resolve: print message when no unresolved files remain (issue4214)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21264
diff
changeset
|
365 def unresolved(self): |
19d6fec60b81
resolve: print message when no unresolved files remain (issue4214)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21264
diff
changeset
|
366 """Obtain the paths of unresolved files.""" |
19d6fec60b81
resolve: print message when no unresolved files remain (issue4214)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21264
diff
changeset
|
367 |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43104
diff
changeset
|
368 for f, entry in pycompat.iteritems(self._state): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
369 if entry[0] in ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
370 MERGE_RECORD_UNRESOLVED, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
371 MERGE_RECORD_UNRESOLVED_PATH, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
372 ): |
21266
19d6fec60b81
resolve: print message when no unresolved files remain (issue4214)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21264
diff
changeset
|
373 yield f |
19d6fec60b81
resolve: print message when no unresolved files remain (issue4214)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21264
diff
changeset
|
374 |
45715
0428978bca22
mergestate: add `allextras()` to get all extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45714
diff
changeset
|
375 def allextras(self): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46845
diff
changeset
|
376 """return all extras information stored with the mergestate""" |
45715
0428978bca22
mergestate: add `allextras()` to get all extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45714
diff
changeset
|
377 return self._stateextras |
0428978bca22
mergestate: add `allextras()` to get all extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45714
diff
changeset
|
378 |
28009
4a25e91fa55d
merge: add state extras merge state data
Durham Goode <durham@fb.com>
parents:
27951
diff
changeset
|
379 def extras(self, filename): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46845
diff
changeset
|
380 """return extras stored with the mergestate for the given filename""" |
45381
ede4c121239e
mergestate: use collections.defaultdict(dict) for _stateextras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45302
diff
changeset
|
381 return self._stateextras[filename] |
28009
4a25e91fa55d
merge: add state extras merge state data
Durham Goode <durham@fb.com>
parents:
27951
diff
changeset
|
382 |
48429
f9bc36863923
mergestate: inline `_resolve()` into `resolve()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
48428
diff
changeset
|
383 def resolve(self, dfile, wctx): |
f9bc36863923
mergestate: inline `_resolve()` into `resolve()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
48428
diff
changeset
|
384 """run merge process for dfile |
f9bc36863923
mergestate: inline `_resolve()` into `resolve()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
48428
diff
changeset
|
385 |
f9bc36863923
mergestate: inline `_resolve()` into `resolve()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
48428
diff
changeset
|
386 Returns the exit code of the merge.""" |
45518
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
387 if self[dfile] in ( |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
388 MERGE_RECORD_RESOLVED, |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
389 LEGACY_RECORD_DRIVER_RESOLVED, |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
390 ): |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
391 return 0 |
20593
3678707e4017
merge: add "other" file node in the merge state file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20592
diff
changeset
|
392 stateentry = self._state[dfile] |
41155
8c222bec97da
merge: make local file storage in the .hg/merge directory extensible
Daniel Ploch <dploch@google.com>
parents:
41050
diff
changeset
|
393 state, localkey, lfile, afile, anode, ofile, onode, flags = stateentry |
20594
ba619c50a355
resolve: use "other" changeset from merge state (issue4163)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20593
diff
changeset
|
394 octx = self._repo[self._other] |
28011
8abd9f785030
merge: add file ancestor linknode to mergestate
Durham Goode <durham@fb.com>
parents:
28009
diff
changeset
|
395 extras = self.extras(dfile) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
396 anccommitnode = extras.get(b'ancestorlinknode') |
28011
8abd9f785030
merge: add file ancestor linknode to mergestate
Durham Goode <durham@fb.com>
parents:
28009
diff
changeset
|
397 if anccommitnode: |
8abd9f785030
merge: add file ancestor linknode to mergestate
Durham Goode <durham@fb.com>
parents:
28009
diff
changeset
|
398 actx = self._repo[anccommitnode] |
8abd9f785030
merge: add file ancestor linknode to mergestate
Durham Goode <durham@fb.com>
parents:
28009
diff
changeset
|
399 else: |
8abd9f785030
merge: add file ancestor linknode to mergestate
Durham Goode <durham@fb.com>
parents:
28009
diff
changeset
|
400 actx = None |
44871
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
401 fcd = _filectxorabsent(localkey, wctx, dfile) |
17d928f8abaf
mergestate: move staticmethod _filectxorabsent to module level
Augie Fackler <augie@google.com>
parents:
44856
diff
changeset
|
402 fco = _filectxorabsent(onode, octx, ofile) |
27048
86290f6f6599
mergestate._resolve: handle change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27035
diff
changeset
|
403 # TODO: move this to filectxorabsent |
37172
daef13da66fe
context: avoid using a context object as a changeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37125
diff
changeset
|
404 fca = self._repo.filectx(afile, fileid=anode, changectx=actx) |
18338
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
405 # "premerge" x flags |
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
406 flo = fco.flags() |
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
407 fla = fca.flags() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
408 if b'x' in flags + flo + fla and b'l' not in flags + flo + fla: |
46843
728d89f6f9b1
refactor: prefer checks against nullrev over nullid
Joerg Sonnenberger <joerg@bec.de>
parents:
46781
diff
changeset
|
409 if fca.rev() == nullrev and flags != flo: |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
410 self._repo.ui.warn( |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
411 _( |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
412 b'warning: cannot merge flags for %s ' |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
413 b'without common ancestor - keeping local flags\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
414 ) |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
415 % afile |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
416 ) |
18338
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
417 elif flags == fla: |
384df4db6520
merge: merge file flags together with file content
Mads Kiilerich <mads@kiilerich.com>
parents:
18336
diff
changeset
|
418 flags = flo |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
419 # restore local |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
420 if localkey != self._repo.nodeconstants.nullhex: |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
421 self._restore_backup(wctx[dfile], localkey, flags) |
26617
dfd9811c5c9b
merge: introduce a preresolve function
Siddharth Agarwal <sid0@fb.com>
parents:
26616
diff
changeset
|
422 else: |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
423 wctx[dfile].remove(ignoremissing=True) |
48760
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
424 |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
425 if not fco.cmp(fcd): # files identical? |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
426 # If return value of merge is None, then there are no real conflict |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
427 del self._state[dfile] |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
428 self._results[dfile] = None, None |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
429 self._dirty = True |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
430 return None |
93d6f0e7ba2f
filemerge: move check for identical sides out of filemerge()
Martin von Zweigbergk <martinvonz@google.com>
parents:
48759
diff
changeset
|
431 |
48506
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
432 merge_ret, deleted = filemerge.filemerge( |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
433 self._repo, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
434 wctx, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
435 self._local, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
436 lfile, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
437 fcd, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
438 fco, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
439 fca, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
440 labels=self._labels, |
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
441 ) |
48759
d169e651066b
mergestate: use an early return for trivial merges
Martin von Zweigbergk <martinvonz@google.com>
parents:
48715
diff
changeset
|
442 |
d169e651066b
mergestate: use an early return for trivial merges
Martin von Zweigbergk <martinvonz@google.com>
parents:
48715
diff
changeset
|
443 if not merge_ret: |
37111
aa5199c7aa42
merge: use constants for merge record state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37110
diff
changeset
|
444 self.mark(dfile, MERGE_RECORD_RESOLVED) |
27035
de7bf242644e
merge.mergestate: compute dirstate action
Siddharth Agarwal <sid0@fb.com>
parents:
27034
diff
changeset
|
445 |
48506
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
446 action = None |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
447 if deleted: |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
448 if fcd.isabsent(): |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
449 # dc: local picked. Need to drop if present, which may |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
450 # happen on re-resolves. |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
451 action = ACTION_FORGET |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
452 else: |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
453 # cd: remote picked (or otherwise deleted) |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
454 action = ACTION_REMOVE |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
455 else: |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
456 if fcd.isabsent(): # dc: remote picked |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
457 action = ACTION_GET |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
458 elif fco.isabsent(): # cd: local picked |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
459 if dfile in self.localctx: |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
460 action = ACTION_ADD_MODIFIED |
27122
77d760ba8dcd
mergestate: explicitly forget 'dc' conflicts where the deleted side is picked
Siddharth Agarwal <sid0@fb.com>
parents:
27121
diff
changeset
|
461 else: |
48506
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
462 action = ACTION_ADD |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
463 # else: regular merges (no action necessary) |
608a35db186c
filemerge: stop returning always-`True` value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48430
diff
changeset
|
464 self._results[dfile] = merge_ret, action |
27035
de7bf242644e
merge.mergestate: compute dirstate action
Siddharth Agarwal <sid0@fb.com>
parents:
27034
diff
changeset
|
465 |
48428
c25a67cfc291
mergestate: make `_resolve()` do both preresolve and resolve
Martin von Zweigbergk <martinvonz@google.com>
parents:
48427
diff
changeset
|
466 return merge_ret |
2775
b550cd82f92a
Move merge code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
467 |
27076
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
468 def counts(self): |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
469 """return counts for updated, merged and removed files in this |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
470 session""" |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
471 updated, merged, removed = 0, 0, 0 |
43104
74802979dd9d
py3: define and use pycompat.itervalues()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43090
diff
changeset
|
472 for r, action in pycompat.itervalues(self._results): |
27076
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
473 if r is None: |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
474 updated += 1 |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
475 elif r == 0: |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
476 if action == ACTION_REMOVE: |
27076
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
477 removed += 1 |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
478 else: |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
479 merged += 1 |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
480 return updated, merged, removed |
09139ccf3085
mergestate: add a method to return updated/merged/removed counts
Siddharth Agarwal <sid0@fb.com>
parents:
27075
diff
changeset
|
481 |
27077
ca3fbf9dad8c
mergestate: add a function to return the number of unresolved files
Siddharth Agarwal <sid0@fb.com>
parents:
27076
diff
changeset
|
482 def unresolvedcount(self): |
ca3fbf9dad8c
mergestate: add a function to return the number of unresolved files
Siddharth Agarwal <sid0@fb.com>
parents:
27076
diff
changeset
|
483 """get unresolved count for this merge (persistent)""" |
33311
f8f716da90fa
mergestate: implement unresolvedcount() in terms of unresolved()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33310
diff
changeset
|
484 return len(list(self.unresolved())) |
27077
ca3fbf9dad8c
mergestate: add a function to return the number of unresolved files
Siddharth Agarwal <sid0@fb.com>
parents:
27076
diff
changeset
|
485 |
27079
a88a10a933b2
mergestate: add a method to compute actions to perform on dirstate
Siddharth Agarwal <sid0@fb.com>
parents:
27078
diff
changeset
|
486 def actions(self): |
a88a10a933b2
mergestate: add a method to compute actions to perform on dirstate
Siddharth Agarwal <sid0@fb.com>
parents:
27078
diff
changeset
|
487 """return lists of actions to perform on the dirstate""" |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
488 actions = { |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
489 ACTION_REMOVE: [], |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
490 ACTION_FORGET: [], |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
491 ACTION_ADD: [], |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
492 ACTION_ADD_MODIFIED: [], |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
493 ACTION_GET: [], |
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
494 } |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43104
diff
changeset
|
495 for f, (r, action) in pycompat.iteritems(self._results): |
27079
a88a10a933b2
mergestate: add a method to compute actions to perform on dirstate
Siddharth Agarwal <sid0@fb.com>
parents:
27078
diff
changeset
|
496 if action is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
497 actions[action].append((f, None, b"merge result")) |
27079
a88a10a933b2
mergestate: add a method to compute actions to perform on dirstate
Siddharth Agarwal <sid0@fb.com>
parents:
27078
diff
changeset
|
498 return actions |
a88a10a933b2
mergestate: add a method to compute actions to perform on dirstate
Siddharth Agarwal <sid0@fb.com>
parents:
27078
diff
changeset
|
499 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
500 |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
501 class mergestate(_mergestate_base): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
502 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
503 statepathv1 = b'merge/state' |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
504 statepathv2 = b'merge/state2' |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
505 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
506 @staticmethod |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
507 def clean(repo): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
508 """Initialize a brand new merge state, removing any existing state on |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
509 disk.""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
510 ms = mergestate(repo) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
511 ms.reset() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
512 return ms |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
513 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
514 @staticmethod |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
515 def read(repo): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
516 """Initialize the merge state, reading it from disk.""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
517 ms = mergestate(repo) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
518 ms._read() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
519 return ms |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
520 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
521 def _read(self): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
522 """Analyse each record content to restore a serialized state from disk |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
523 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
524 This function process "record" entry produced by the de-serialization |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
525 of on disk file. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
526 """ |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
527 unsupported = set() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
528 records = self._readrecords() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
529 for rtype, record in records: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
530 if rtype == RECORD_LOCAL: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
531 self._local = bin(record) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
532 elif rtype == RECORD_OTHER: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
533 self._other = bin(record) |
45518
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
534 elif rtype == LEGACY_MERGE_DRIVER_STATE: |
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
535 pass |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
536 elif rtype in ( |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
537 RECORD_MERGED, |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
538 RECORD_CHANGEDELETE_CONFLICT, |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
539 RECORD_PATH_CONFLICT, |
45518
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
540 LEGACY_MERGE_DRIVER_MERGE, |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
541 LEGACY_RECORD_RESOLVED_OTHER, |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
542 ): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
543 bits = record.split(b'\0') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
544 # merge entry type MERGE_RECORD_MERGED_OTHER is deprecated |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
545 # and we now store related information in _stateextras, so |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
546 # lets write to _stateextras directly |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
547 if bits[1] == MERGE_RECORD_MERGED_OTHER: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
548 self._stateextras[bits[0]][b'filenode-source'] = b'other' |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
549 else: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
550 self._state[bits[0]] = bits[1:] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
551 elif rtype == RECORD_FILE_VALUES: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
552 filename, rawextras = record.split(b'\0', 1) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
553 extraparts = rawextras.split(b'\0') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
554 extras = {} |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
555 i = 0 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
556 while i < len(extraparts): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
557 extras[extraparts[i]] = extraparts[i + 1] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
558 i += 2 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
559 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
560 self._stateextras[filename] = extras |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
561 elif rtype == RECORD_LABELS: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
562 labels = record.split(b'\0', 2) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
563 self._labels = [l for l in labels if len(l) > 0] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
564 elif not rtype.islower(): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
565 unsupported.add(rtype) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
566 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
567 if unsupported: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
568 raise error.UnsupportedMergeRecords(unsupported) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
569 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
570 def _readrecords(self): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
571 """Read merge state from disk and return a list of record (TYPE, data) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
572 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
573 We read data from both v1 and v2 files and decide which one to use. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
574 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
575 V1 has been used by version prior to 2.9.1 and contains less data than |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
576 v2. We read both versions and check if no data in v2 contradicts |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
577 v1. If there is not contradiction we can safely assume that both v1 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
578 and v2 were written at the same time and use the extract data in v2. If |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
579 there is contradiction we ignore v2 content as we assume an old version |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
580 of Mercurial has overwritten the mergestate file and left an old v2 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
581 file around. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
582 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
583 returns list of record [(TYPE, data), ...]""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
584 v1records = self._readrecordsv1() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
585 v2records = self._readrecordsv2() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
586 if self._v1v2match(v1records, v2records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
587 return v2records |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
588 else: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
589 # v1 file is newer than v2 file, use it |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
590 # we have to infer the "other" changeset of the merge |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
591 # we cannot do better than that with v1 of the format |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
592 mctx = self._repo[None].parents()[-1] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
593 v1records.append((RECORD_OTHER, mctx.hex())) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
594 # add place holder "other" file node information |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
595 # nobody is using it yet so we do no need to fetch the data |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
596 # if mctx was wrong `mctx[bits[-2]]` may fails. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
597 for idx, r in enumerate(v1records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
598 if r[0] == RECORD_MERGED: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
599 bits = r[1].split(b'\0') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
600 bits.insert(-2, b'') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
601 v1records[idx] = (r[0], b'\0'.join(bits)) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
602 return v1records |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
603 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
604 def _v1v2match(self, v1records, v2records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
605 oldv2 = set() # old format version of v2 record |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
606 for rec in v2records: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
607 if rec[0] == RECORD_LOCAL: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
608 oldv2.add(rec) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
609 elif rec[0] == RECORD_MERGED: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
610 # drop the onode data (not contained in v1) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
611 oldv2.add((RECORD_MERGED, _droponode(rec[1]))) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
612 for rec in v1records: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
613 if rec not in oldv2: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
614 return False |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
615 else: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
616 return True |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
617 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
618 def _readrecordsv1(self): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
619 """read on disk merge state for version 1 file |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
620 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
621 returns list of record [(TYPE, data), ...] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
622 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
623 Note: the "F" data from this file are one entry short |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
624 (no "other file node" entry) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
625 """ |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
626 records = [] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
627 try: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
628 f = self._repo.vfs(self.statepathv1) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
629 for i, l in enumerate(f): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
630 if i == 0: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
631 records.append((RECORD_LOCAL, l[:-1])) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
632 else: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
633 records.append((RECORD_MERGED, l[:-1])) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
634 f.close() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
635 except IOError as err: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
636 if err.errno != errno.ENOENT: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
637 raise |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
638 return records |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
639 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
640 def _readrecordsv2(self): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
641 """read on disk merge state for version 2 file |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
642 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
643 This format is a list of arbitrary records of the form: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
644 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
645 [type][length][content] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
646 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
647 `type` is a single character, `length` is a 4 byte integer, and |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
648 `content` is an arbitrary byte sequence of length `length`. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
649 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
650 Mercurial versions prior to 3.7 have a bug where if there are |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
651 unsupported mandatory merge records, attempting to clear out the merge |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
652 state with hg update --clean or similar aborts. The 't' record type |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
653 works around that by writing out what those versions treat as an |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
654 advisory record, but later versions interpret as special: the first |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
655 character is the 'real' record type and everything onwards is the data. |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
656 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
657 Returns list of records [(TYPE, data), ...].""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
658 records = [] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
659 try: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
660 f = self._repo.vfs(self.statepathv2) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
661 data = f.read() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
662 off = 0 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
663 end = len(data) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
664 while off < end: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
665 rtype = data[off : off + 1] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
666 off += 1 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
667 length = _unpack(b'>I', data[off : (off + 4)])[0] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
668 off += 4 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
669 record = data[off : (off + length)] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
670 off += length |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
671 if rtype == RECORD_OVERRIDE: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
672 rtype, record = record[0:1], record[1:] |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
673 records.append((rtype, record)) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
674 f.close() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
675 except IOError as err: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
676 if err.errno != errno.ENOENT: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
677 raise |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
678 return records |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
679 |
45501
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
680 def commit(self): |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
681 if self._dirty: |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
682 records = self._makerecords() |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
683 self._writerecords(records) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
684 self._dirty = False |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
685 |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
686 def _makerecords(self): |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
687 records = [] |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
688 records.append((RECORD_LOCAL, hex(self._local))) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
689 records.append((RECORD_OTHER, hex(self._other))) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
690 # Write out state items. In all cases, the value of the state map entry |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
691 # is written as the contents of the record. The record type depends on |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
692 # the type of state that is stored, and capital-letter records are used |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
693 # to prevent older versions of Mercurial that do not support the feature |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
694 # from loading them. |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
695 for filename, v in pycompat.iteritems(self._state): |
45518
32ce4cbaec4b
mergedriver: delete it
Martin von Zweigbergk <martinvonz@google.com>
parents:
45501
diff
changeset
|
696 if v[0] in ( |
45501
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
697 MERGE_RECORD_UNRESOLVED_PATH, |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
698 MERGE_RECORD_RESOLVED_PATH, |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
699 ): |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
700 # Path conflicts. These are stored in 'P' records. The current |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
701 # resolution state ('pu' or 'pr') is stored within the record. |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
702 records.append( |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
703 (RECORD_PATH_CONFLICT, b'\0'.join([filename] + v)) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
704 ) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
705 elif ( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
706 v[1] == self._repo.nodeconstants.nullhex |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
707 or v[6] == self._repo.nodeconstants.nullhex |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46845
diff
changeset
|
708 ): |
45501
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
709 # Change/Delete or Delete/Change conflicts. These are stored in |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
710 # 'C' records. v[1] is the local file, and is nullhex when the |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
711 # file is deleted locally ('dc'). v[6] is the remote file, and |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
712 # is nullhex when the file is deleted remotely ('cd'). |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
713 records.append( |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
714 (RECORD_CHANGEDELETE_CONFLICT, b'\0'.join([filename] + v)) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
715 ) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
716 else: |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
717 # Normal files. These are stored in 'F' records. |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
718 records.append((RECORD_MERGED, b'\0'.join([filename] + v))) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
719 for filename, extras in sorted(pycompat.iteritems(self._stateextras)): |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
720 rawextras = b'\0'.join( |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
721 b'%s\0%s' % (k, v) for k, v in pycompat.iteritems(extras) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
722 ) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
723 records.append( |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
724 (RECORD_FILE_VALUES, b'%s\0%s' % (filename, rawextras)) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
725 ) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
726 if self._labels is not None: |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
727 labels = b'\0'.join(self._labels) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
728 records.append((RECORD_LABELS, labels)) |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
729 return records |
0e75c088f0dc
mergestate: move commit() from base class to on-disk subclass
Martin von Zweigbergk <martinvonz@google.com>
parents:
45500
diff
changeset
|
730 |
45498
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
731 def _writerecords(self, records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
732 """Write current state on disk (both v1 and v2)""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
733 self._writerecordsv1(records) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
734 self._writerecordsv2(records) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
735 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
736 def _writerecordsv1(self, records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
737 """Write current state on disk in a version 1 file""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
738 f = self._repo.vfs(self.statepathv1, b'wb') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
739 irecords = iter(records) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
740 lrecords = next(irecords) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
741 assert lrecords[0] == RECORD_LOCAL |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
742 f.write(hex(self._local) + b'\n') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
743 for rtype, data in irecords: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
744 if rtype == RECORD_MERGED: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
745 f.write(b'%s\n' % _droponode(data)) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
746 f.close() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
747 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
748 def _writerecordsv2(self, records): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
749 """Write current state on disk in a version 2 file |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
750 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
751 See the docstring for _readrecordsv2 for why we use 't'.""" |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
752 # these are the records that all version 2 clients can read |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
753 allowlist = (RECORD_LOCAL, RECORD_OTHER, RECORD_MERGED) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
754 f = self._repo.vfs(self.statepathv2, b'wb') |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
755 for key, data in records: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
756 assert len(key) == 1 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
757 if key not in allowlist: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
758 key, data = RECORD_OVERRIDE, b'%s%s' % (key, data) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
759 format = b'>sI%is' % len(data) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
760 f.write(_pack(format, key, len(data), data)) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
761 f.close() |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
762 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
763 def _make_backup(self, fctx, localkey): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
764 self._repo.vfs.write(b'merge/' + localkey, fctx.data()) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
765 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
766 def _restore_backup(self, fctx, localkey, flags): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
767 with self._repo.vfs(b'merge/' + localkey) as f: |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
768 fctx.write(f.read(), flags) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
769 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
770 def reset(self): |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
771 shutil.rmtree(self._repo.vfs.join(b'merge'), True) |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
772 |
cc5f811b1f15
mergestate: extract a base class to be shared by future memmergestate
Martin von Zweigbergk <martinvonz@google.com>
parents:
45497
diff
changeset
|
773 |
45499
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
774 class memmergestate(_mergestate_base): |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
775 def __init__(self, repo): |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
776 super(memmergestate, self).__init__(repo) |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
777 self._backups = {} |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
778 |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
779 def _make_backup(self, fctx, localkey): |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
780 self._backups[localkey] = fctx.data() |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
781 |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
782 def _restore_backup(self, fctx, localkey, flags): |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
783 fctx.write(self._backups[localkey], flags) |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
784 |
19590b126764
merge: use in-memory mergestate when using in-memory context
Martin von Zweigbergk <martinvonz@google.com>
parents:
45498
diff
changeset
|
785 |
42456
87a34c767384
merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42412
diff
changeset
|
786 def recordupdates(repo, actions, branchmerge, getfiledata): |
43787
be8552f25cab
cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents:
43713
diff
changeset
|
787 """record merge actions to the dirstate""" |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
788 # remove (must come first) |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
789 for f, args, msg in actions.get(ACTION_REMOVE, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
790 if branchmerge: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
791 repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=False) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
792 else: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
793 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=False) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
794 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
795 # forget (must come first) |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
796 for f, args, msg in actions.get(ACTION_FORGET, []): |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
797 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=False) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
798 |
34548
b4955650eb57
merge: add merge action 'pr' to rename files during update
Mark Thomas <mbthomas@fb.com>
parents:
34547
diff
changeset
|
799 # resolve path conflicts |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
800 for f, args, msg in actions.get(ACTION_PATH_CONFLICT_RESOLVE, []): |
44939
818b4f19ef23
merge: move an inspection of the dirstate from record to calculate phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
44871
diff
changeset
|
801 (f0, origf0) = args |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
802 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True) |
34548
b4955650eb57
merge: add merge action 'pr' to rename files during update
Mark Thomas <mbthomas@fb.com>
parents:
34547
diff
changeset
|
803 repo.dirstate.copy(origf0, f) |
b4955650eb57
merge: add merge action 'pr' to rename files during update
Mark Thomas <mbthomas@fb.com>
parents:
34547
diff
changeset
|
804 if f0 == origf0: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
805 repo.dirstate.update_file(f0, p1_tracked=True, wc_tracked=False) |
34548
b4955650eb57
merge: add merge action 'pr' to rename files during update
Mark Thomas <mbthomas@fb.com>
parents:
34547
diff
changeset
|
806 else: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
807 repo.dirstate.update_file(f0, p1_tracked=False, wc_tracked=False) |
34548
b4955650eb57
merge: add merge action 'pr' to rename files during update
Mark Thomas <mbthomas@fb.com>
parents:
34547
diff
changeset
|
808 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
809 # re-add |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
810 for f, args, msg in actions.get(ACTION_ADD, []): |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
811 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
812 |
27131
d837da26155e
merge: add a new action type representing files to add/mark as modified
Siddharth Agarwal <sid0@fb.com>
parents:
27130
diff
changeset
|
813 # re-add/mark as modified |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
814 for f, args, msg in actions.get(ACTION_ADD_MODIFIED, []): |
27131
d837da26155e
merge: add a new action type representing files to add/mark as modified
Siddharth Agarwal <sid0@fb.com>
parents:
27130
diff
changeset
|
815 if branchmerge: |
47726
8e2e8d0a9a56
mergestate: use `update_file` to handle for `ACTION_ADD_MODIFIED`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47691
diff
changeset
|
816 repo.dirstate.update_file( |
8e2e8d0a9a56
mergestate: use `update_file` to handle for `ACTION_ADD_MODIFIED`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47691
diff
changeset
|
817 f, p1_tracked=True, wc_tracked=True, possibly_dirty=True |
8e2e8d0a9a56
mergestate: use `update_file` to handle for `ACTION_ADD_MODIFIED`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47691
diff
changeset
|
818 ) |
27131
d837da26155e
merge: add a new action type representing files to add/mark as modified
Siddharth Agarwal <sid0@fb.com>
parents:
27130
diff
changeset
|
819 else: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
820 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
821 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
822 # exec change |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
823 for f, args, msg in actions.get(ACTION_EXEC, []): |
47727
0e581d7e89b7
mergestate: use `update_file` to handle for `ACTION_EXEC`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47726
diff
changeset
|
824 repo.dirstate.update_file( |
0e581d7e89b7
mergestate: use `update_file` to handle for `ACTION_EXEC`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47726
diff
changeset
|
825 f, p1_tracked=True, wc_tracked=True, possibly_dirty=True |
0e581d7e89b7
mergestate: use `update_file` to handle for `ACTION_EXEC`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47726
diff
changeset
|
826 ) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
827 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
828 # keep |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
829 for f, args, msg in actions.get(ACTION_KEEP, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
830 pass |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
831 |
45467
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
832 # keep deleted |
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
833 for f, args, msg in actions.get(ACTION_KEEP_ABSENT, []): |
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
834 pass |
bb9888d32601
merge: add `ACTION_KEEP_ABSENT` to represent files we want to keep absent
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45385
diff
changeset
|
835 |
45524
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
836 # keep new |
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
837 for f, args, msg in actions.get(ACTION_KEEP_NEW, []): |
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
838 pass |
6877b0ee5f9d
mergestate: introduce a new ACTION_KEEP_NEW
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45518
diff
changeset
|
839 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
840 # get |
42522
d29db0a0c4eb
update: fix spurious unclean status bug shown by previous commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42456
diff
changeset
|
841 for f, args, msg in actions.get(ACTION_GET, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
842 if branchmerge: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
843 # tracked in p1 can be True also but update_file should not care |
48108
d4e715d2be0b
dirstate: remove a update_file's special case for tracked file with p2 data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47727
diff
changeset
|
844 old_entry = repo.dirstate.get_entry(f) |
d4e715d2be0b
dirstate: remove a update_file's special case for tracked file with p2 data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47727
diff
changeset
|
845 p1_tracked = old_entry.any_tracked and not old_entry.added |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
846 repo.dirstate.update_file( |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
847 f, |
48108
d4e715d2be0b
dirstate: remove a update_file's special case for tracked file with p2 data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47727
diff
changeset
|
848 p1_tracked=p1_tracked, |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
849 wc_tracked=True, |
48144
6f54afb094bd
dirstate: align the dirstate's API to the lower level ones
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48109
diff
changeset
|
850 p2_info=True, |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
851 ) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
852 else: |
42522
d29db0a0c4eb
update: fix spurious unclean status bug shown by previous commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42456
diff
changeset
|
853 parentfiledata = getfiledata[f] if getfiledata else None |
47691
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
854 repo.dirstate.update_file( |
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
855 f, |
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
856 p1_tracked=True, |
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
857 wc_tracked=True, |
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
858 parentfiledata=parentfiledata, |
33beeb32f73a
dirstate: replace `update_parent_file_data` with simpler `update_parent` call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47613
diff
changeset
|
859 ) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
860 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
861 # merge |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
862 for f, args, msg in actions.get(ACTION_MERGE, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
863 f1, f2, fa, move, anc = args |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
864 if branchmerge: |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
865 # We've done a branch merge, mark this file as merged |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
866 # so that we properly record the merger later |
48109
2c2788ce0257
dirstate: remove a update_file's special case for `merged` file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48108
diff
changeset
|
867 p1_tracked = f1 == f |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
868 repo.dirstate.update_file( |
48109
2c2788ce0257
dirstate: remove a update_file's special case for `merged` file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48108
diff
changeset
|
869 f, |
2c2788ce0257
dirstate: remove a update_file's special case for `merged` file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48108
diff
changeset
|
870 p1_tracked=p1_tracked, |
2c2788ce0257
dirstate: remove a update_file's special case for `merged` file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48108
diff
changeset
|
871 wc_tracked=True, |
48144
6f54afb094bd
dirstate: align the dirstate's API to the lower level ones
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48109
diff
changeset
|
872 p2_info=True, |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
873 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
874 if f1 != f2: # copy/rename |
3308
ecc1bf27378c
merge: unify merge and copy actions
Matt Mackall <mpm@selenic.com>
parents:
3307
diff
changeset
|
875 if move: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
876 repo.dirstate.update_file( |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
877 f1, p1_tracked=True, wc_tracked=False |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
878 ) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
879 if f1 != f: |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
880 repo.dirstate.copy(f1, f) |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
881 else: |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
882 repo.dirstate.copy(f2, f) |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
883 else: |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
884 # We've update-merged a locally modified file, so |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
885 # we set the dirstate to emulate a normal checkout |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
886 # of that file some time in the past. Thus our |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
887 # merge will appear as a normal local file |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
888 # modification. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42972
diff
changeset
|
889 if f2 == f: # file not locally copied/moved |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
890 repo.dirstate.update_file( |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
891 f, p1_tracked=True, wc_tracked=True, possibly_dirty=True |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
892 ) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
893 if move: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
894 repo.dirstate.update_file( |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
895 f1, p1_tracked=False, wc_tracked=False |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
896 ) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
897 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
898 # directory rename, move local |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
899 for f, args, msg in actions.get(ACTION_DIR_RENAME_MOVE_LOCAL, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
900 f0, flag = args |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
901 if branchmerge: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
902 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True) |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
903 repo.dirstate.update_file(f0, p1_tracked=True, wc_tracked=False) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
904 repo.dirstate.copy(f0, f) |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
905 else: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
906 repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=True) |
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
907 repo.dirstate.update_file(f0, p1_tracked=False, wc_tracked=False) |
21391
cb15835456cb
merge: change debug logging - test output changes but no real changes
Mads Kiilerich <madski@unity3d.com>
parents:
21390
diff
changeset
|
908 |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
909 # directory rename, get |
37112
43ffd9070da1
merge: use constants for actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37111
diff
changeset
|
910 for f, args, msg in actions.get(ACTION_LOCAL_DIR_RENAME_GET, []): |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
911 f0, flag = args |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
912 if branchmerge: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
913 repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True) |
21551
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
914 repo.dirstate.copy(f0, f) |
bde505f47141
merge: fix stupid indentation left over from previous refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
21545
diff
changeset
|
915 else: |
47613
8b16ccc71001
mergestate: use dirstate.update_file API in recordupdates()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47128
diff
changeset
|
916 repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=True) |