comparison mercurial/merge.py @ 26500:5bd7c4c07f6d

merge.mergestate: factor out code to validate v1/v2 records We're going to need this in another place in upcoming patches.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 30 Sep 2015 21:22:31 -0700
parents 6b4a0c602bec
children e4f27fb65da7
comparison
equal deleted inserted replaced
26499:e72b62b154b0 26500:5bd7c4c07f6d
115 file around. 115 file around.
116 116
117 returns list of record [(TYPE, data), ...]""" 117 returns list of record [(TYPE, data), ...]"""
118 v1records = self._readrecordsv1() 118 v1records = self._readrecordsv1()
119 v2records = self._readrecordsv2() 119 v2records = self._readrecordsv2()
120 if self._v1v2match(v1records, v2records):
121 return v2records
122 else:
123 # v1 file is newer than v2 file, use it
124 # we have to infer the "other" changeset of the merge
125 # we cannot do better than that with v1 of the format
126 mctx = self._repo[None].parents()[-1]
127 v1records.append(('O', mctx.hex()))
128 # add place holder "other" file node information
129 # nobody is using it yet so we do no need to fetch the data
130 # if mctx was wrong `mctx[bits[-2]]` may fails.
131 for idx, r in enumerate(v1records):
132 if r[0] == 'F':
133 bits = r[1].split('\0')
134 bits.insert(-2, '')
135 v1records[idx] = (r[0], '\0'.join(bits))
136 return v1records
137
138 def _v1v2match(self, v1records, v2records):
120 oldv2 = set() # old format version of v2 record 139 oldv2 = set() # old format version of v2 record
121 for rec in v2records: 140 for rec in v2records:
122 if rec[0] == 'L': 141 if rec[0] == 'L':
123 oldv2.add(rec) 142 oldv2.add(rec)
124 elif rec[0] == 'F': 143 elif rec[0] == 'F':
125 # drop the onode data (not contained in v1) 144 # drop the onode data (not contained in v1)
126 oldv2.add(('F', _droponode(rec[1]))) 145 oldv2.add(('F', _droponode(rec[1])))
127 for rec in v1records: 146 for rec in v1records:
128 if rec not in oldv2: 147 if rec not in oldv2:
129 # v1 file is newer than v2 file, use it 148 return False
130 # we have to infer the "other" changeset of the merge
131 # we cannot do better than that with v1 of the format
132 mctx = self._repo[None].parents()[-1]
133 v1records.append(('O', mctx.hex()))
134 # add place holder "other" file node information
135 # nobody is using it yet so we do no need to fetch the data
136 # if mctx was wrong `mctx[bits[-2]]` may fails.
137 for idx, r in enumerate(v1records):
138 if r[0] == 'F':
139 bits = r[1].split('\0')
140 bits.insert(-2, '')
141 v1records[idx] = (r[0], '\0'.join(bits))
142 return v1records
143 else: 149 else:
144 return v2records 150 return True
145 151
146 def _readrecordsv1(self): 152 def _readrecordsv1(self):
147 """read on disk merge state for version 1 file 153 """read on disk merge state for version 1 file
148 154
149 returns list of record [(TYPE, data), ...] 155 returns list of record [(TYPE, data), ...]